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?

4

2 回答 2

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.

于 2009-07-07T01:28:17.677 回答
1

首先,您似乎没有在构建中包含资源包。你可能需要类似的东西

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

在 MXML 或只是

[ResourceBundle("RegistrationForm")]

在你班上名列前茅

完成此操作后,请确保您拥有捆绑包...尝试仅添加一个字符串资源,看看是否可以得到它。如果您有捆绑包但它仍然无法使用,请为您的图标使用不同的路径。它们可能与资源无关(如果不玩它,我永远记不起什么是相对于什么的)。

于 2009-04-20T07:31:51.753 回答