2

I'm having trouble with getting icons from resource bundle in Flex. Here's the scenario:

Directory structure looks like this:

 -ResourceManagerTest
   -resources
     -icons
       -icon1.png
       -icon2.png
       -icons.properties
 -src
   -MyButton.as
   -ResourceManagerTest.mxml

In icons.properties I have:

CIRCLE_FILLED=Embed("icon1.png")
CIRCLE_CONTOUR=Embed("icon2.png")

I'd like to create ToggleButtonBar with buttons whose icons are pulled out from resource bundle.

Here's the source of programmatically created button:

package
{
    import mx.resources.ResourceManager;

    public class MyButton extends Object
    {
    public var icon:Class;
    public function MyButton()
    {
        super();
        icon = ResourceManager.getInstance().getClass("icons", "CIRCLE_FILLED");
    }

}

}

And here is ResourceManagerTest where I define the ToggleButtonBar:

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
layout="absolute"
creationComplete="onCreationComplete()">

<mx:Script>
    <![CDATA[
        [Bindable]
        public var dataProvider:Array;

        public function onCreationComplete():void {

            dataProvider = new Array();
            dataProvider.push(new MyButton());
            dataProvider.push(new MyButton());
            tgb.dataProvider = dataProvider;
        }

    ]]>
</mx:Script>


<mx:ToggleButtonBar id="tgb"/>

Buttons do appear, however without any icons. What am I doing wrong?

2 Answers2

1

The best resource I've found for information about how to setup ResourceBundle in Flex 3 is "Using Resources" in Adobe's livedocs.

[ResourceBundle("icons")]

In addition to including the resource bundle, you need to make sure you include the resource path at compile time. Read Adobe's docs for more information.

calvinf
  • 3,754
  • 3
  • 28
  • 41
1

Firstly it looks like you are not including the resource bundle in your build. You're probably going to need something like

<mx:Metadata>
        [ResourceBundle("RegistrationForm")]
</mx:Metadata> 

in the MXML or just

[ResourceBundle("RegistrationForm")]

at the top of your class

Once you've done that make sure you have the bundle... try adding just a string resource and see if you can get that. If you have the bundle and it still doesn't work have a play with different paths for you icons. They may not be relative to the resource (with out playing with it i can never remember what is relative to what).

James Hay
  • 12,580
  • 8
  • 44
  • 67