Wednesday, April 23, 2008

Initialization code in Adobe Flash ActionScript 3.0

At long last, it's really, really, working right... and the code looks like this:

var initialized; // has to be declared, even if it's undefined

if (initialized == undefined) {
stop(); // stop the slide show on the first frame
Next_btn.addEventListener(MouseEvent.MOUSE_UP,function(evt:MouseEvent):void { nextFrame(); });
Back_btn.addEventListener(MouseEvent.MOUSE_UP,function(evt:MouseEvent):void { prevFrame(); });

initialized=true; // could make it anything, as long as it's not undefined

So, now I can just put all of the initialization code in the middle of the braces, and it all runs only once!

No comments: