在 PopUpMenuButton 节点中嵌入图标时出错
我正在尝试创建一个弹出菜单按钮,以图像和标签作为其节点。但我无法嵌入图标。它给了我和错误(如下所示)。仅凭标签就可以正常工作。
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常为我需要的每个图标创建一个类
,然后使用该类作为图标
I normally create a class for each Icon i need
and than use this class as icon
我认为问题在于所编写的代码试图将图像作为
icon
属性的值嵌入到节点中 - 属性的值只能是字符串。在不了解有关您的应用程序的任何其他信息的情况下,我想说您必须像这样重写您的 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:
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.