----- Original Message -----
From: "Muzak" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Sunday, July 08, 2007 6:22 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.
You comment about 'this' was completely wrong.. ;-)
Well for lesser beings (from the flash help):
this property
this
References an object or movie clip instance. When a script executes, this
references the movie clip instance that contains the script. When a method
is called, this contains a reference to the object that contains the called
method.
Inside an on() event handler attached to a button, this refers to the
Timeline that contains the button. Inside an onClipEvent() event handler
attached to a movie clip, this refers to the Timeline of the movie clip
itself.
Because this is evaluated in the context of the script that contains it, you
can't use this in a script to refer to a variable defined in a class file.
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.
Well, nobody ever mentioned that - Delegate was proposed as apparently the
only way forward.
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.
Well that's why *anything* 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.
I don't see what this has to do with delegate. I can use Delegate and still
have 100 lines of code between it and the function.
Using Delegate is just one of those "best practices" and should be used at
all times, even if it "kinda works" without.
Well, "best practice" wasn't mentioned until now. I think "kinda works" is
actually "does work".
The OP was reporting a problem and many people seemed to suggest that
Delegate was going to help solve the problem, something that was entirely
erroneous.
Best practice, fine. Only practice, no.
regards,
Muzak
Paul
_______________________________________________
[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