davelog Wherein, I write.

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.


5 Comments

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
}

:D

Posted by Michael on 30 November 2006 @ 11pm

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

Posted by Michael on 30 November 2006 @ 11pm

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(foo:Boolean):Void {
trace(this); // this = your class instance, aka all your members are accesible
}

k, tips for you rule my world

Posted by Michael on 30 November 2006 @ 11pm

Michael, you’re officially my best friend, ever! Can’t wait until January…

Posted by dave on 30 November 2006 @ 11pm

and if you’re looking for the URL Michael was talking about in post #2, here it is:

[url]

Posted by dave on 1 December 2006 @ 12am