Flex error 1120 (Access of undefined property XXX) when using constants in MXML

apache-flexmxml

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

Best Answer

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.

Related Topic