> OK, my comment about 'this' isn't completely right, but I am certainly right
> about the use of Delegate for the XML loader.
You comment about 'this' was completely wrong.. ;-)
You're right if you say that *you don't have to* use Delegate to be able to
access variables outside an onLoad hander, but the fact
remains that the scope has changed, and that's the important part.
When you do this:
var foo = "bar";
test.onLoad = function(success) {
trace(foo);
}
you're relying on Flash to look up the variable (which it will) and that's why
it works.
Things also get more complicated/missleading when you do something like this:
var foo = "bar";
function loadHandler() {
trace(foo);
}
test = new XML()
// etc..
test.onLoad = loadHandler;
Seeing it like that (nice and together) one could note that the loadHandler
function runs in a different scope than the one it
resides in (the timeline).
But what if the loadHandler function and the onLoad assignment are separated by
100 lines of code?
Then things aren't that obvious anymore and leads to missleading code.
Using Delegate is just one of those "best practices" and should be used at all
times, even if it "kinda works" without.
regards,
Muzak
----- Original Message -----
From: "Paul Andrews" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Sunday, July 08, 2007 6:32 PM
Subject: Re: [Flashcoders] XML loading and parsing problem
> OK, my comment about 'this' isn't completely right, but I am certainly right
> about the use of Delegate for the XML loader.
>
> If you don't use the Delegate class and try and access the attributes of a
> class within an onLoad function, you won't have access
> to the class atrributes, so you must use a delegate.
> If you don't use the Delegate class on the main timeline and try and access
> the variables declared on the timeline you will be
> able to access them, so you don't have to use a delegate.
>
> Stick the following code onto the timeline and see how you get on..
>
> Paul
>
> stop();
> var thisVariable:String="This is me";
> trace(this.thisVariable);
> var test:XML = new XML();
> test.ignoreWhite = true;
> test.onLoad = function(success) {
> if (success) {
> trace("loaded");
> trace(thisVariable);
> trace(this.thisVariable);
> }
> };
> test.load("test.xml");
>
> /*
>
> test.xml:
>
> <test>
> <something />
> </test>
>
> */
>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com