And IMPORTANT: do not initialize/set it when you declare it.  You can
only initialize instance variables to simple values.  Set its value
inside the function.

 

public var _myLoader:URLLoader;  //declare this outside of a function.
The leading underscore is just a convention

public var _myXML:XML;  //this too

...

private function initUrlLoader():void {

  var XML_URL:String ="http://whatever <http://whatever/> ";
  var myXMLURL:URLRequest = new URLRequest(XML_URL);
  _myLoader = new URLLoader(myXMLURL);
  _myLoader.addEventListener("complete", xmlLoaded); 

...

}

 

function xmlLoaded(event:Event):void
{
  _myXML = XML(_myLoader.data);
  trace("Data loaded.");
}

 

Tracy

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Tracy Spratt
Sent: Wednesday, May 21, 2008 8:42 PM
To: [email protected]
Subject: RE: [flexcoders] Re: How do I use URLLoader?

 

Declare the variable in the "instance" scope, that is, not inside a
function.  That will make it available anywhere within the class
instance.  In non-OO terms, you might call it a "global" variable, but
it is not really global, only global to the class instance, hence the
term "instance" variable.

 

Tracy

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of wild.katana
Sent: Wednesday, May 21, 2008 4:53 PM
To: [email protected]
Subject: [flexcoders] Re: How do I use URLLoader?

 

Do you mean something like this:
public var myLoader:URLLoader = new URLLoader(myXMLURL);
I tried it but it didn't work... What do you mean by instance variable?

--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> myLoader needs to be an instance variable instead of a local one.
> 
> 
> 
> Maybe the sencond will go away when the xmlLoaded function can
compile.
> 
> 
> 
> Consider HTTPService instead, it is a bit simpler to use.
> 
> 
> 
> Tracy
> 
> 

 

Reply via email to