我有点担心。我开始尝试使用已经以 FXG 格式制作的自定义图标制作 MenuBar 控件。
我的项目文件夹内的“assets.graphics.icons”中有 3 个 FXG 文件:
- src/assets/graphics/icons/MenuIcon.fxg
- src/assets/graphics/icons/ItemAIcon.fxg
- src/assets/graphics/icons/ItemBIcon.fxg
在阅读了以下两个链接和一堆网页之后。
- http://blog.flexexamples.com/2010/01/29/displaying-icons-in-an-mx-menu bar-control-in-flex/
- http://livedocs.adobe.com/flex/3/html/help.html?content=menucontrols_3 .html
我最终得到了这段代码:
<?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>
我了解到您可以使用任何图像文件添加带有以下代码的标签
<mx:Script>
<![CDATA[
[Embed("assets/graphics/images/MenuIcon.png")]
public const MenuIconConst:Class;
]]>
</mx:Script>
将常量名称添加到 MenuBar 控件的图标属性,如下所示:
所以我试图做到这一点,但没有运气:
<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>
我发现了一个不同的网页,你必须创建一个库来嵌入 Fxg 文件,然后将它们用作类名或类似的东西,但我不太了解。
现实情况是,我一直试图以多种不同的方式将任何 fxg 组件放入 MenuBar 的图标属性中,但没有成功。我真的希望有人已经做了这样的事情。我将不胜感激任何帮助。