Search code examples
actionscript-3apache-flexflex4flash-builderflex4.5

How to use a skin from the main application in Flex?


I have an application with a SWF loader.
From the loaded SWF file, I'm accessing public variables from the main application with this:

[Bindable] public var global:Object = FlexGlobals.topLevelApplication;

Alert.show(global.myvar); 

This all works perfect.


I have a MXML skin file (for buttons) in a directory called 'skins' in the main application.
Is it possible to use this skin in the child applications?


I've already tried this, unfortunately not working:

[Bindable] public var global:Object = FlexGlobals.topLevelApplication;

<s:Button label="My Text" skinClass="{global.skins.menuButtons}" />

And this, but then it can't compile anymore:

[Bindable] public var global:Object = FlexGlobals.topLevelApplication;

<s:Button label="Button 1" skinClass="global.skins.menuButtons" />
<s:Button label="Button 2" skinClass="FlexGlobals.topLevelApplication.skins.menuButtons" />

Is it possible what I want in another way or do I have to copy the skin to the all the projects where I want to use the skin?

Thanks.


Solution

  • I've already fixed the problem.

    In my main SWF file, I'm defining a public variable as class:

    public var menuButtons:Class = skins.menuButtons;
    

    And in the children SWF files, I'm referring to this variable with FlexGlobals.topLevelApplication:

    [Bindable] public var global:Object = FlexGlobals.topLevelApplication;
    
    <s:Button label="My Text" skinClass="{global.menuButtons}" />
    

    Apparently it is not possible to refer directly to the skin with global.skins.menuButtons.