1
votes

I have as a main application setted "main.mxml" which contains the follow declaration :

[Bindable]
[Embed(source="../images/common/user.png")] 
public var userIcon : Class;

I have another module, on which i wish to access it as a button icon. I have tried with the follow definition, but it doesnt work:

<s:Group width="100%" height="29">
    <s:layout>
        <s:VerticalLayout horizontalAlign="center"/>
    </s:layout>
    <s:Button id="buttonLoad" width="80%" label="Loading" icon="{ main.userIcon }"/>
</s:Group>
  • How to access the declaration inside main.mxml from the other modules ?
1

1 Answers

2
votes

The name of MXML class isn't an identifier of its instance (because of it can have a lot of instances). You should think about MXML files as not files but classes. They are absolutely the same as ordinary ActionScript classes. The same rules as in other OOP languages. So if you have main.mxml main is a class name for that class and its package is determined by that MXML file path relative to the source folder (as in ActionScript classes). That's why you should name your MXML classes from the capital letter (Main.mxml but not main.mxml).

If your main.mxml is top level application you can refer it as FlexGlobals.topLevelApplication. But it is not the right way to do things.

The best way is to inject this property to your target class. You can do it using Dependency Injecting Framework/Container like Spring ActionScript or RobotLegs or Parsley. Or you can do it manually by delegating from top application to the class containing piece of code which handles modules. When module is loaded pass this value there.