Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Data Integration / August 2006



Tip: Looking for answers? Try searching our database.

XML loads properly in .SWF but not in .AS

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
maija_g - 23 Aug 2006 15:56 GMT
I have the following script which works jim-dandy when implimented as a frame
script in my .swf, but I don't want it there, I want it in a class I've created
called FigureItem. I've stripped the script down to just the part that loads
the XML. When the script is inside the .swf (without the class constructor,
obviously) 'trace(contentXML)' correctly returns the formatted XML. Inside the
.as 'trace(contentXML)' returns 'undefined'. SOMETHING is loading becase
'trace("yay")'  returns 'yay'.  (loadXML gets called by the FiguireItem movie
clip inside the .swf).

class FigureItem extends MovieClip {
    var rollBox:MovieClip;
    var contentXML:XML;
    //
    public function FigureItem() {
        contentXML = new XML();
       
    }
    public function loadXML(myURL:String):Void {
       
       
        contentXML.onLoad = function(success:Boolean):Void  {
            if (success) {
                trace ("yay");
                trace(contentXML);
            } else {
                trace ("yay");
            }
        };
        contentXML.load(myURL);
    }
}
Raymond Basque - 23 Aug 2006 16:26 GMT
contentXML is out of scope from the XML object;
Here are a few ways to deal with scope:

public function loadXML(myURL:String):Void {

var xmlOwner = this;
contentXML._OWNERREF = this;
 contentXML.onLoad = function(success:Boolean):Void  {
 if (success) {
   trace ("yay");
    trace(this); // <===
   trace(xmlOwner.contentXML); // <=====
   trace(this._OWNERREF.contentXML);  // <=========
 } else {  trace ("yay");  }
 };

 contentXML.load(myURL);
 }
maija_g - 23 Aug 2006 16:55 GMT
Thanks, but that doesn't seem to work. I copied and pasted and immediately got
a pile of errors. I commented out all the stuff you added in until there were
no errors and then started uncommenting until I got an error. Below is the
first one.

class FigureItem extends MovieClip {
    var contentXML:XML;
    //
    public function FigureItem() {
        contentXML = new XML();
        contentXML.onLoad = function(success:Boolean):Void {
            if (success) {
                trace ("yay");
                //trace(this); // <===
                //trace(xmlOwner.contentXML); // <=====
                //trace(this._OWNERREF.contentXML); // <=========
                } else {
                trace ("booooo");
                }
            };
       
        contentXML.load(myURL);
    }
}

/**Error** blah/blah/blah/FigureItem.as: Line 11: There is no property with
the name '_OWNERREF'.
             contentXML._OWNERREF = this;
*/
maija_g - 23 Aug 2006 17:00 GMT
Never mind, the 'trace (this)' and 'trace (xmlOwner.contentXML)' both worked so I'll use one of those. Thanks!!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.