Thursday, 11 March 2010

Killing Flash CS3 / AIR Processes and avoiding the "debugger launch failed" message

To kill an AIR application launched for testing from Flash CS3 open the task manager and kill the process idl.exe.

When working within the Flash CS3 development environment, lightweight or utility windows spawned from an AIR application are not killed when the primary AIR application window is exited. In fact, they are not even killed when Flash CS3 is closed.

Further, as long as these lightweight/utility windows are open you will not be able to to test your application. There simply will be no result from pressing ctrl+enter. Launching the debugger will only offer the message, "debugger launch failed!" If any part of the AIR application is still running you simply will not be able to test your application. Hence, you must go to the task manager and kill idl.exe!

Embedding Font in CS3 Components (Avoiding Disappearing Button Labels)

When a CS3 Component (i.e. a Button) appears under a mask the text disappears.
To fix this we simply embed the font in the Component. Unfortunately, this isn't like embedding font in a normal programatically generated TextField instance.

How To Embed Font in CS3 Components
(I will use the Button component for this example.)

1.First, we must embed the font in the swf. There are 2 ways to do this:

◦If you wish, you may simply create a TextField off stage and embed the font in that TextField.

◦Or if you have taste, you will open the library and select “new Font” from the library panel menu. Now, create a font symbol in the library. I chose Arial and set the linkage identifier for the font symbol to “ArialFont” exporting it for ActionScript.
2.With the font embedded in the swf, we now need to embed it in our component.
There is only one way to do this. Assuming that our button is named button_btn your ActionScript will look like this:


// you may replace new ArialFont().fontName with the string “Arial” if you prefer. (If you did not create a Font Symbol you must use the string “Arial”)

var tf:TextFormat = new TextFormat(new ArialFont().fontName);
button_btn.setStyle("embedFonts", true);
button_btn.setStyle("textFormat", tf);
button_btn.label = "fox";

3.That's it. The Font is now embedded in the CS3 Component.

A Note about things that don't work: components do not have a “fontFamily” style. The only way to control the style of text in components is to create an instance of TextFormat and set the Button's “textFormat” style to that instance of TextFormat. Also, you cannot set a style directly on the TextField object in the button component. (The CS3 Button Component's TextField can be retrieved through it's textField property.) Setting the style directly on the textField causes a runtime error. Also, setting the textField's defaultTextFormat object does not have an effect, as it is overwritten by the components default styles. Finally setting the textField.embedFonts property to true does not have any effect.

ReferenceError: Error #1056: Caused by Declaring Stage Instances Private

If you declare a stage instance private you get the message: "ReferenceError #1056 Cannot create property my_mc on StageIntanceDeclarationsClass"

This error occurs when you uncheck the "Declare Stage Instances Automatically" checkbox in the "ActionScript 3.0 Settings" dialogbox and proceed to declare stage instances as private variables in the class associated with the containing MovieClip.

A Note on Inheritances and Declaring Stage Instances:
You cannot choose to simply always declare stage instances automatically without forging the use of inheritance in classes linked to MovieClip Symbols. If you have a class APrime which is derived from class A and APrime is linked to a MovieClip Symbol, all stage instances used in the base class A must be manually declared in class A. "Declare Stage Instances Automatically" only declares instances in the class linked to the MovieClip Symbol and does NOT make those references available to any base classes.

Example:
Assume that the class StageIntanceDeclarations is set as the class associated with a MovieClip which c0ntains the MovieClip my_mc. Then the following code will cause ReferenceError #1056 at runtime.

package{
import flash.display.MovieClip;
public class StageIntanceDeclarations extends MovieClip
{
//Private Causes ReferenceError #1056
private var my_mc:MovieClip;
function StageIntanceDeclarations()
{
}
}
}

The output is as follows:
ReferenceError: Error #1056: Cannot create property my_mc on StageIntanceDeclarations.
at flash.display::Sprite/flash.display:Sprite::constructChildren()
at flash.display::Sprite$iinit()
at flash.display::MovieClip$iinit()
at TestStageIntanceDeclarationsBase$iinit()
at flash.display::Sprite/flash.display:Sprite::constructChildren()
at flash.display::Sprite$iinit()
at flash.display::MovieClip$iinit()

To avoid this error simply declare my_mc as public:
public var my_mc:MovieClip;