tags:

views:

1320

answers:

2

Hey folks

Again pulling my hair out due to some Flex/AS3 weirdness. The following code does not compile due to error 1120 - Access of undefined property AbstractWizardModel

<mx:HBox id="cntr_buttons" width="100%" horizontalAlign="right">
   <mx:Button label="{model.getButtonLabel(AbstractWizardModel.GO_BACK)}" />
</mx:HBox>

The constant is defined (in AbstractWizardModel) as:

[Bindable]
public class AbstractWizardModel extends EventDispatcher
{
   public static const GO_BACK : String = "goBack";
   ...
}

Replacing 'AbstractWizardModel.GO_BACK' with '"goBack"' does the trick, but what was the problem?

Thanks!

PS: Of course I am importing the AbstractWizardModel in the MXML code

A: 

The error is about the class AbstractWizardModel, not about the constant GO_BACK. You need to have an import statement for the class inside the mxml file:

<mx:Script>
<![CDATA[
import the.package.AbstractWizardModel;
]]>
</mx:Script>

before you can use the class. EDIT: replace "the.package." with whatever package the class is in.

Markus Johnsson
Thanks for your answer, but actually I had that import right from the start. Will edit my question to be more precise.
Tom
This is indeed weird AS3 behaviour.. The error message indicates that the class is unknown, which usually means that it is not imported or a needed swc is missing. Do you get any other warnings or errors?
Markus Johnsson
A: 

Oh man this is so weird..

I found kind of a solution, thanks to all comments, which helped me to get on the right track, but still think this is a bug in Flex.

First of all I have to add that (in my code) the MXML and AbstractWizardModel class are in the same package.

The 'getButtonLabel()' function that I am calling is declared as

[Bindable(event="getButtonLabelChanged")]
public function getButtonLabel (buttonId:String) : String
{
    ..
}

If I remove that [Bindable..] annotation, the code compiles.

If I leave it there, I have to add an import for class AbstractWizardModel, although it is in the same package. Anyway, that fixes the problem, too.

However :) FB4 removes that import everytime it organizes imports, so that user comment was helpful too.

Happy to hear your thoughts!

Tom