December 31, 2007

Error creating AIR file: 103: ERROR, application.name

Last night I started playing with the public beta 3 drops for Flex 3 and AIR. Using the project creation wizard I created a new Flex based AIR application. After looking at the new application descriptor format which has changed a lot since beta 2 I started to customize it so that I could use it as a template for sample applications I was updating to beta 3. When running the Export Release Build... wizard it got through most of the .air creation process but then erred out at the end with the following message:

Error creating AIR file: 103: ERROR, application.name

A 0 byte .air file existed and a randomly named .tmp file was created.

Turns out the default application descriptor created by the project wizard has a small bug in it. It inserts a commented out <name> element below <filename> at the top of the file. Right before the closing <application> element it inserts an uncommented <name> element. When I uncommented the <name> at the top of the file I was accidentally defining <name> twice and hence causing an error. I would have liked the error message to be more descriptive, but now that I know what it was trying to say (error with <name> in the application descriptor) I should be able to deduce other issues.

Tags: air error flex

February 26, 2007

RegExp Constructor Issue

The Flex documentation is a a little misleading in regards to the RegExp Constructor. Livedocs has this to say:

public function RegExp(re:String, flags:String)

Lets you construct a regular expression from two strings. One string defines the pattern of the regular expression, and the other defines the flags used in the regular expression.

Notice the lack of a default value for the flags argument? One would think that would mean you should get a compilation error if you don't supply both arguments to the constructor. However, both of these compile without error:

var regExpA:RegExp = new RegExp("^http://www.google.com/(.*)$");
var regExpB:RegExp = new RegExp("^http://www.google.com/(.*)$", "");

I would expect the first one to cause this error:

1136: Incorrect number of arguments. Expected 2.

It would be nice if the documentation was just wrong and you didn't need to supply the second argument to the constructor. The problem is the two regular expressions behave differently! The missing flags argument causes the regular expression to do funky stuff, which is not the same as passing in the empty string. For example look at the output of this little example:

trace(regExpA.test("http://www.google.com/"));
trace(regExpA.test("http://www.google.com/webhp?hl=en"));
trace(regExpB.test("http://www.google.com/"));
trace(regExpB.test("http://www.google.com/webhp?hl=en"));
// Output
// true
// false
// true
// true

That false shouldn't be there! The funky stuff that is going on behind the scenes is that without the second argument to the constructor it is looking at the regular expression string itself to set the flags. In this case g appears after a //, which is the way you specify the global flag in a RegExp literal. To confirm this, look at the string version of each RegExp:

trace(regExpA);
trace(regExpB);
// Output
// /^http://www.google.com/(.*)$/gm
// /^http://www.google.com/(.*)$/

Cool, we also picked up the multiline flag since m also appears! The problem only occurs if you have more than one / followed by one of the regular expression flags. The two slahses don't need to be next to each other just having two anywhere in the string followed by other text can cause the problem. In general you are probably better using RegExp literals, but if you do use the RegExp constructor be sure to supply both arguments, even if the second one is just the empty string.

Tags: error flex regexp

January 25, 2007

Could not resolve * to a component implementation.

Often when refactoring code I'll extract ActionScript code out of an MXML file into an ActionScript based superclass to get a cleaner separation between logic and the view. In doing so I sometimes forget to update MXML variable declrations, leading to the confusing error:

Could not resolve <mx:states> to a component implementation.

In this case my MXML class extends another custom class and looks like:

<?xml version="1.0" encoding="utf-8"?>
<example:CustomCanvas xmlns:example="com.example.*" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:states>
<mx:State name="default"/>
<mx:State name="custom"/>
</mx:states>
</example:CustomCanvas>

The issue is that the "mx" namespace doesn't match the root component's namespace so the MXML compiler gets confused about it being a property versus a child component. The simple fix is to just change the namespace on the property to match the root component's namespace like this:

<?xml version="1.0" encoding="utf-8"?>
<example:CustomCanvas xmlns:example="com.example.*" xmlns:mx="http://www.adobe.com/2006/mxml">
<example:states>
<mx:State name="default"/>
<mx:State name="custom"/>
</example:states>
</example:CustomCanvas>

Tags: as3 error flex2