If you're having problems getting your AS3 project to run in SWF Studio, one of the most common causes is accessing the stage object in the document class/first frame before the stage is ready. The solution is quick and easy to implement.

If you enable the option to include the Flash debug player in your EXE you may see a runtime error. In AS3 when a runtime is thrown no further code executes in that block of code, unless you catch the error.

Your main SWF is loaded into the EXE through a stub SWF. A SWF's stage property is only set once it has actually been added to the stage. This is true of any SWF loaded into the Flash player.

What you need to do is listen for the Event.ADDED_TO_STAGE event. When that fires you can access the stage property. Accessing it before that will result in a 1009 runtime error.


public function MyDocumentClass()
{
   addEventListener(Event.ADDED_TO_STAGE, init);
}

public function init(e:Event):void
{
   // You can now access the stage property.
   ssDebug.trace(stage.framerate);
}

In a class constructor (Flash or Flex) this will always work, even if you are testing your main SWF by itself from Flash/Flex. Testing your SWF from Flash, with your code in the timeline, you will have to check for the stage property, and if it doesn't exist, listen for the event. For example:


function init(e:Event=null):void
{
   // You can now access the stage property.
   ssDebug.trace(stage.framerate);
}

if (stage)
{
   init();
}
else
{
   addEventListener(Event.ADDED_TO_STAGE, init);
}