In the last post I mentioned the decompiler from Sothink that completely decompiles ActionScript 3. The results of the decompilation can often be a little tricky to read if you don’t know what to look for. Below is a decompiled AIR SWF that simply creates 10 native windows every second. In the FLA all the code is on frame 1 of the timeline. See the resulting code dump below:
[as]package chrome_fla
{
import flash.display.*;
import flash.events.*;
import flash.utils.*;
dynamic public class MainTimeline extends MovieClip
{
public var backdrop:MovieClip;
public var t:Timer;
public var closer:MovieClip;
public function MainTimeline()
{
addFrameScript(0, frame1);
return;
}
public function doMove(param1:Event) : void
{
stage.nativeWindow.startMove();
return;
}
public function makeWin(param1:Event) : void
{
var _loc_2:NativeWindow;
_loc_2 = new NativeWindow(new NativeWindowInitOptions());
_loc_2.width = Math.random() * 200;
_loc_2.height = Math.random() * 200;
_loc_2.x = Math.random() * 1024;
_loc_2.y = Math.random() * 768;
_loc_2.visible = true;
return;
}
public function doClose(param1:Event) : void
{
stage.nativeWindow.close();
return;
}
function frame1()
{
closer.addEventListener(MouseEvent.CLICK, doClose);
backdrop.addEventListener(MouseEvent.MOUSE_DOWN, doMove);
t = new Timer(100);
t.addEventListener(TimerEvent.TIMER, makeWin);
t.start();
return;
}
}
}[/as]
The first thing that you will notice is that the code is inside of a class that extends MovieClip. This is the document class that gets generated behind the scenes. All of your timeline code gets included into this class when you compile. You can see on line 13 the constructor for the document class. Inside of it there is a call to the addFrameScript function. This references what from number it is on and also the name of the class method containing the code. Pretty cool stuff!
Certain things like local variables and parameters lose their original names so you will see names like “_loc_2″ in their place. Pretty easy to figure out though once you get the hang of it.
Viewing Flash ActionScript in this way is a great learning tool for what Flash actually creates when you create timeline scripts. Unfortuantely this tool only runs on Windows but you can use Parallels or VMWare to get it on the Mac.
Lee