Thursday, November 30, 2006

flash 8 frustrations

This just saved my life.

It's amazing how much 15 lines of code just solved hours of me banging my head against the wall.

For those of you who know anything about flash, the above is a workaround for scope problems when importing XML or LoadVars from within an actionscript class.

<3 whoever wrote that.

Labels: ,


comments
Michael said:
Oops, I'm going to tell you a secret now! There's already a built-in class to do that, it's called Delegate. simply:

import mx.utils.Delegate;

var myxml:XML = new XML();
myxml.ignoreWhite = true;
myxml.load("something.xml");
myxml.onLoad = Delegate.create(this, onXMLLoad);
function onXMLLoad():Void {
trace(this); // traces _level0
trace(myxml); // traces xml structure
}


i was yelled at on thu, november 30 @ 11:20 pm
1
Michael said:
oh also, bigspaceship wrote a new class that lets you add your own arguments onto the call, so like delegate.create(this, onxmlload, myparam, "otherparam") it's on labs.bigspaceship.com/blog
i was yelled at on thu, november 30 @ 11:22 pm
2
Michael said:
OH and sry to spamalot but it's useful in other things as well. say you have a movieclip and you HAVE to use the onRelease handler for that mc, as in mc.onRelease = function() (aka you lose the scope to the class) then what i do is define variables in that mc for functions i might need to call from the class like this:



mc.setSomeVar = Delegate.create(this, setSomeVar);
mc.doSomething = Delegate.create(this, doSomething);
mc.onRelease = function():Void {
this.setSomeVar(true);
this.doSomething(false);
}

private function doSomething(foooolean):Void {
trace(this); // this = your class instance, aka all your members are accesible
}


k, tips for you rule my world
i was yelled at on thu, november 30 @ 11:26 pm
3
dave said:
Michael, you're officially my best friend, ever! Can't wait until January...
i was yelled at on thu, november 30 @ 11:36 pm
4
dave said:
and if you're looking for the URL Michael was talking about in post #2, here it is:

[url]
i was yelled at on fri, december 1 @ 12:46 am
5
James said:
Man I am so far down on the code totem pole.
i was yelled at on fri, december 1 @ 3:05 pm
6

Add A Comment:

name
email
url

remember me