1

少し心配です。すでにFXG形式で作成されたカスタムアイコンを使用してMenuBarコントロールを作成しようとしました。

プロジェクトフォルダ内の「assets.graphics.icons」に3つのFXGファイルがあります。

  1. src / Assets / graphics / icons / MenuIcon.fxg
  2. src / Assets / graphics / icons / ItemAIcon.fxg
  3. src / Assets / graphics / icons / ItemBIcon.fxg

次の2つのリンクと一連のWebページを読んだ後。

  1. http://blog.flexexamples.com/2010/01/29/displaying-icons-in-an-mx-menu bar-control-in-flex /
  2. 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ファイルを埋め込むためのライブラリを作成し、それらをクラス名などとして使用する必要がある別のWebページを見つけましたが、それはよくわかりませんでした。

現実には、私はfxgコンポーネントのいずれかをMenuBarのアイコン属性内にさまざまな方法で配置しようとしていましたが、運がありませんでした。誰かがすでにこのようなものを作っていることを本当に願っています。助けていただければ幸いです。

4

1 に答える 1

0

昔の MXML クラスと同じように扱えば、実際には思ったより簡単です。

したがって、「assets/graphics/images/MenuIcon.fxg」は assets.graphics.images.MenuIcon になります。文字列はクラスではないため、バインディング式を使用してクラスをアイコン属性に割り当てる必要があります。

<menuitem label="Item A" icon="{assets.graphics.images.MenuIcon}">
     <menuitem label="SubItem A1"/>
     <menuitem label="SubItem A2"/>
</menuitem>

最初にクラスをインポートする必要があるかもしれません...頭のてっぺんから思い出せません。

于 2011-05-03T20:39:33.277 に答える