在 PopUpMenuButton 节点中嵌入图标时出错

发布于 2024-10-13 03:17:49 字数 1164 浏览 2 评论 0原文

我正在尝试创建一个弹出菜单按钮,以图像和标签作为其节点。但我无法嵌入图标。它给了我和错误(如下所示)。仅凭标签就可以正常工作。

<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>

这给了我一个错误:“嵌入”的初始化程序:无法识别的编译时指令。

请有人告诉我我在这里做错了什么。

谢谢 泽山

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄离 2024-10-20 03:17:49

我通常为我需要的每个图标创建一个类

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

,然后使用该类作为图标

         <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>

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>
猥琐帝 2024-10-20 03:17:49

我认为问题在于所编写的代码试图将图像作为 icon 属性的值嵌入到节点中 - 属性的值只能是字符串。

在不了解有关您的应用程序的任何其他信息的情况下,我想说您必须像这样重写您的 dataProvider:

<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>

显然,您无法以这种方式嵌入图标图像,但也许您不需要?我不是 100% 确定,但我认为 dataProvider 是在运行时应用的,这意味着无法使用这种方法嵌入图标图像。

如果我的想法是错误的,您可以编写一个项目渲染器来查看 icon 属性的值并嵌入在该路径中找到的图像。

如果我是对的,您可以编写一个自定义项目渲染器,嵌入所有图标图像,然后根据 label 的值或其他一些标识属性显示正确的图标。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文