0

I am trying to create a popupmenubutton, with images and label as its nodes. But I am unable to embed the icons. It gives me and error(given below). Thou the label alone are working fine.

<mx:PopUpMenuButton id="menu_file" labelField="@label" itemClick="{menuClickHandler(event);}" visible="false"
        height="20" left="0" top="0" width="15" alpha="0.5" cornerRadius="5" useHandCursor="true"
        toolTip="Delete, Move, Rename or Modify other properties">
        <mx:dataProvider>
            <mx:XMLList>
                <node label="{LABEL_DELETE}" icon="@Embed(source='assets/FileManager/images/cancel2.png')"/>
                <node label="{LABEL_DOWNLOAD}" icon="@Embed(source='assets/FileManager/images/cancel2.png')"/>
                <node label="{LABEL_MOVE}" icon="@Embed(source='assets/FileManager/images/cancel2.png')"/>
                <node label="{LABEL_RENAME}" icon="@Embed(source='assets/FileManager/images/cancel2.png')"/>
                <node label="{LABEL_SET_PRIVACY}" icon="@Embed(source='assets/FileManager/images/cancel2.png')"/>
            </mx:XMLList>
        </mx:dataProvider>

This gives me an error: Initializer for 'Embed': unrecognized compile-time directive.

Plz can someone tell me what I am doing wrong here.

Thanks Zeeshan

Zeeshan Rang
  • 19,375
  • 28
  • 72
  • 100

2 Answers2

1

I normally create a class for each Icon i need

[Embed("img/Print.png")]
public const printIcon : Class;

and than use this class as icon

         <mx:XMLList>
            <menuitem label="File">
                <menuitem label="Print" icon="printIcon"/>
                <menuitem label="Logout" icon="logoutIcon" />
                <menuitem label="Close" icon="closeIcon"/>
            </menuitem>
            <menuitem label="Modify">
                <menuitem label="Preferences" icon="toolIcon" />
            </menuitem>
            <menuitem label="Help">
                <menuitem label="About Us" icon="infoIcon"/>
            </menuitem>
        </mx:XMLList>
0

I think the problem is that the code as written is attempting to embed an image as the value of the icon attribute in your node - the value of an attribute can only be a String.

Without knowing anything else about your application, I'd say you'd have to re-write your dataProvider like this:

<mx:dataProvider>
        <mx:XMLList>
            <node label="{LABEL_DELETE}" icon="assets/FileManager/images/cancel2.png"/>
            <node label="{LABEL_DOWNLOAD}" icon="assets/FileManager/images/cancel2.png"/>
            <node label="{LABEL_MOVE}" icon="assets/FileManager/images/cancel2.png"/>
            <node label="{LABEL_RENAME}" icon="assets/FileManager/images/cancel2.png"/>
            <node label="{LABEL_SET_PRIVACY}" icon="assets/FileManager/images/cancel2.png"/>
        </mx:XMLList>
    </mx:dataProvider>

Obviously, you wouldn't have the ability to embed the icon images this way, but maybe you don't need to? I'm not 100% sure, but I think the dataProvider is applied at runtime, which would mean that there is no way to embed icon images with this approach.

If I'm wrong about that, you could write an item renderer that would look at the value of the icon attribute and embed the image found at that path.

If I'm right, you could write a custom item renderer that embeds all of the icon images and then displays the correct icon based on the value of label, or some other identifying attribute.

Ross Henderson
  • 1,779
  • 16
  • 23