Thursday, December 18, 2008

watch that variable scope with AS3!

if you're used to actionscript2 in flash and making banners, you're used to:

on (release){
getURL(clickTag,"_blank");
}

But AS3 ushers in a new dawn where the language is more object orientated and comes away from those handy little tricks. First thing you have to do is bring in the click tag variable from root, something like:

clickTAG = root.loaderInfo.parameters.clickTag;

Then you need to catch the action:

public function HandleClick(param1:MouseEvent) : void
{
trace("click");
ExternalInterface.call("window.open", clickTAG, "arplayer", "height=372,width=820");
return;
}

now the above is actually an example of how to open a window of a custom size.

Now I was dealing with a case recently where the clickTAG = was brought in on the root frame - so in otherwords it was within a function called frame1(). Now this means that clickTAG is only defined for this function and not for the event handler function. Instead the event handler has to be changed to:

public function HandleClick(param1:MouseEvent) : void
{
trace("click");
clickTAG = root.loaderInfo.parameters.clickTag;
ExternalInterface.call("window.open", clickTAG, "arplayer", "height=372,width=820");
return;
}// end function

Now I'm not a flash designer/programmer - but I am a coder and so this was blatantly obvious to me using sothink decompiler, but not so much for the creative agency.

No comments: