[英]In Flex, How can I use an Fxg file as a MenuBar Icon attribute?
I have a little concern.我有点担心。 I started trying to make a MenuBar control with custom icons already made in FXG format.我开始尝试使用已经以 FXG 格式制作的自定义图标制作 MenuBar 控件。
I have 3 FXG files in "assets.graphics.icons" inside my project folder:我的项目文件夹内的“assets.graphics.icons”中有 3 个 FXG 文件:
After reading the following two links and a bunch of web pages.在阅读了以下两个链接和一堆 web 页面之后。
I ended up with this code:我最终得到了这段代码:
<?xml version="1.0" encoding="utf-8"?>
<!-- src/myMenuBarApplication.mxml -->
<mx:Application name="myMenuBarApplication"
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:components="assets.graphics.icons.*">
<mx:MenuBar id="myMenuBar" iconField="@icon" labelField="@label" showRoot="true">
<fx:XMLList>
<menuitem label="Menu" icon="">
<menuitem label="Item A" icon="">
<menuitem label="SubItem A1"/>
<menuitem label="SubItem A2"/>
</menuitem>
<menuitem label="Item B" icon="">
<menuitem label="SubItem B1"/>
<menuitem label="SubItem B2"/>
</menuitem>
</menuitem>
</fx:XMLList>
</mx:MenuBar>
</mx:Application>
I learned that you can do it with any image file adding an tag with the following code我了解到您可以使用任何图像文件添加带有以下代码的标签
<mx:Script>
<![CDATA[
[Embed("assets/graphics/images/MenuIcon.png")]
public const MenuIconConst:Class;
]]>
</mx:Script>
An adding the constant name to the icon attribute of the MenuBar control like this:将常量名称添加到 MenuBar 控件的图标属性,如下所示:
So I tried to do this with no luck:所以我试图做到这一点,但没有运气:
<mx:Script>
<![CDATA[
import assets.graphics.icons.*;
[Bindable]
public var MenuIconVar:Class = new MenuIcon() as Class;
// MenuIcon is one of my FXG files inside assets.graphics.icons
]]>
</mx:Script>
I found an a different web page that you have to make a library to embed Fxg files and then use them as Class names or something like this but i did not understand that very well.我发现了一个不同的 web 页面,您必须创建一个库来嵌入 Fxg 文件,然后将它们用作 Class 名称或类似名称,但我不太了解。
The reality is that I have been trying to put anyone of fxg components inside the icon attributes of the MenuBar in many different ways with no luck.现实情况是,我一直试图以多种不同的方式将任何 fxg 组件放入 MenuBar 的图标属性中,但没有成功。 I really hope someone has already made something like this.我真的希望有人已经做了这样的事情。 I would appreciate any help.我将不胜感激任何帮助。
It is actually easier then you think, if you just treat it like any ol' MXML class.它实际上比你想象的要容易,如果你只是像对待任何 ol' MXML class 一样对待它。
So, "assets/graphics/images/MenuIcon.fxg" would become assets.graphics.images.MenuIcon.因此,“assets/graphics/images/MenuIcon.fxg”将变为 assets.graphics.images.MenuIcon。 Since a string is not a class, you will need to use a binding expression to assign the class to your icon attribute.由于字符串不是 class,因此您需要使用绑定表达式将 class 分配给您的图标属性。
<menuitem label="Item A" icon="{assets.graphics.images.MenuIcon}">
<menuitem label="SubItem A1"/>
<menuitem label="SubItem A2"/>
</menuitem>
You may also need to import the class first... I can't recall off the top of my head.您可能还需要先导入 class ......我想不起来了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.