I am not smarter than you, oh no! Delegate's smarter than us, and AS3
is King!! (problem solved in the future)
I am simply declaring a variable in the class which refers to the class
itself. This frees me from the scope trap (using this with 'onLoad') :
public function handleXML () {
trace(owner);
}
public function parseXML (url:String) {
xmlDoc = new XML();
xmlDoc.onLoad =handleXML;
xmlDoc.load(url);
}
public function init(url:String) {
var owner = this;
this.parseXML(url);
}
by doing this, I guarantee myself that this variable will be available
to every object of the class. Its scope is the class.
Now, when you assign handleXML to xmlDoc.onLoad, you mainly transfer
the method's owner (from the class to the xmlDoc object). By using
'owner', I can target back my class without any problem...
I may be off tracks ;)
Cedric
Why? haha, sorry, but to me it looks like you just added var owner =
this just to avoid putting trace(this) for no reason other than
avoiding to use "this".
What's the specific reason you did that? I'm guessing you're smarter
than me :)
- Andreas
Cedric Muller wrote:
this is logical: you assign handleXML function to 'xmlDoc.onLoad'
handler which means that 'handleXML' belongs to xmlDoc from now on
...
In such cases, I do the following:
class ParseXML{
private var xmlDoc:XML;
private function handleXML(){
trace(owner);
}
function ParseXML(url:String){
var owner = this;
xmlDoc = new XML();
xmlDoc.ignoreWhite = true;
xmlDoc.onLoad = handleXML;
xmlDoc.load(url);
}
}
2. What the hell is going on with "this" here
class ParseXML{
private var xmlDoc:XML;
private function handleXML(){
trace(this);
}
function ParseXML(url:String){
xmlDoc = new XML();
xmlDoc.ignoreWhite = true;
xmlDoc.onLoad = handleXML;
xmlDoc.load(url);
}
}
"trace this" in this case traces out the xml doc. Is this because
onLoad = handleXML declares the scope of handleXML as being the
xmlDoc?
Sometimes the onLoad = functionReference; syntax weirds me out. I
tend to go for the onLoad = function(){ more specific functionality
here } method
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders