Flex-menu-control

提供:Dev Guides
移動先:案内検索

フレックス-メニューコントロール

前書き

Menuコントロールは、単独で選択可能な選択肢またはメニュー項目のポップアップメニューを作成します。 ポップアップメニューには、必要な数のサブメニューを含めることができます。

クラス宣言

以下は mx.controls.Menu クラスの宣言です-

public class Menu
   extends List
      implements IFocusManagerContainer

パブリックプロパティ

Sr.No Property & Description
1

dataDescriptor : IMenuDataDescriptor

データプロバイダー内のデータにアクセスして操作するオブジェクト。

2

hasRoot : Boolean

[read-only] A flag that indicates that the current data provider has a root node; for example, a single top node in a hierarchical structure.

3

parentMenu : Menu

メニューの階層チェーン内の親メニュー。現在のメニューは親のサブメニューです。

4

showRoot : Boolean

データプロバイダーのルートノードを表示するかどうかを指定するブールフラグ。

パブリックメソッド

Sr.No Method & Description
1

Menu()

コンストラクタ。

2

createMenu(parent:DisplayObjectContainer, mdp:Object, showRoot:Boolean = true):Menu

[static] Creates and returns an instance of the Menu class.

3

hide():void

Menuコントロールが表示されている場合、Menuコントロールとそのサブメニューを非表示にします。

4

popUpMenu(menu:Menu, parent:DisplayObjectContainer, mdp:Object):void

[static] Sets the dataProvider of an existing Menu control and places the Menu control in the specified parent container.

5

show(xShow:Object = null, yShow:Object = null):void

メニューコントロールを表示します。

保護されたメソッド

Sr.No Method & Description
1

makeListData(data:Object, uid:String, rowNum:int):BaseListData

[override] Creates a new MenuListData instance and populates the fields based on the input data provider item.

2

measure():void

[override] Calculates the preferred width and height of the Menu based on the widths and heights of its menu items.

3

setMenuItemToggled(item:Object, toggle:Boolean):void

メニュー項目を切り替えます。

イベント

Sr.No Event & Description
1

change

ユーザーの操作の結果として選択が変更されたときに送出されます。

2

itemClick

メニューアイテムが選択されたときに送出されます。

3

itemRollOut

ユーザーがメニューアイテムからマウスをロールアウトしたときに送出されます。

4

itemRollOver

ユーザーがメニューアイテムの上にマウスを置いたときに送出されます。

5

menuHide

メニューまたはサブメニューが閉じられたときに送出されます。

6

menuShow

メニューまたはサブメニューが開いたときに送出されます。

継承されるメソッド

このクラスは、次のクラスからメソッドを継承します-

  • mx.controls.List
  • mx.controls.listClasses.ListBase
  • mx.core.ScrollControlBase
  • mx.core.UIComponent
  • mx.core.FlexSprite
  • flash.display.Sprite
  • flash.display.DisplayObjectContainer
  • flash.display.InteractiveObject
  • flash.display.DisplayObject
  • flash.events.EventDispatcher
  • 対象

Flexメニューコントロールの例

次の手順に従って、テストアプリケーションを作成して、Flexアプリケーションのメニューコントロールの使用を確認します。

Step Description
1 Create a project with a name HelloWorld under a package com.finddevguides.client as explained in the Flex - Create Application chapter.
2 Modify HelloWorld.mxml as explained below. Keep rest of the files unchanged.
3 Compile and run the application to make sure business logic is working as per the requirements.

以下は、変更されたmxmlファイル src/com.finddevguides/HelloWorld.mxml の内容です。

<?xml version = "1.0" encoding = "utf-8"?>
<s:Application xmlns:fx = "http://ns.adobe.com/mxml/2009"
   xmlns:s = "library://ns.adobe.com/flex/spark"
   xmlns:mx = "library://ns.adobe.com/flex/mx"
   width = "100%" height = "100%" minWidth = "500" minHeight = "500">

   <fx:Style source = "/com/finddevguides/client/Style.css"/>
   <fx:Script>
      <![CDATA[
         import mx.controls.Menu;
         import mx.events.MenuEvent;

         protected var menu:Menu;
         protected function showMenu(event:MouseEvent):void {
            menu = Menu.createMenu(null, menuData, false);
            menu.labelField = "@label";
            menu.show(mainContainer.x+menuPanel.x+ 2,
            mainContainer.y +menuPanel.y+32);
            menu.addEventListener(MenuEvent.CHANGE,onMenuChange);
         }

         protected function hideMenu(event:MouseEvent):void {
            menu.hide();
         }

         protected function onMenuChange(event:MenuEvent):void {
            lblSelected.text =  event.label;
         }
      ]]>
   </fx:Script>

   <fx:Declarations>
      <fx:XML format = "e4x" id = "menuData">
         <root>
            <menuitem label = "Menu Item A" >
               <menuitem label = "SubMenu Item A 1" enabled = "false"/>
               <menuitem label = "SubMenu Item A 2"/>
            </menuitem>

            <menuitem label = "Menu Item B" type = "check" toggled = "true"/>
            <menuitem label = "Menu Item C" type = "check" toggled = "false"/>
            <menuitem type = "separator"/>

            <menuitem label = "Menu Item D" >
               <menuitem label = "SubMenu Item D 1" type = "radio"
                  groupName = "one"/>
               <menuitem label = "SubMenu Item D 2" type = "radio"
                  groupName = "one" toggled = "true"/>
               <menuitem label = "SubMenu Item D 3" type = "radio"
                  groupName = "one"/>
            </menuitem>
         </root>
      </fx:XML>
   </fx:Declarations>

   <s:BorderContainer width = "630" height = "480" id = "mainContainer"
      styleName = "container">
      <s:VGroup width = "100%" height = "100%" gap = "50"
         horizontalAlign = "center" verticalAlign = "middle">
         <s:Label id = "lblHeader" text = "Complex Controls Demonstration"
            fontSize = "40" color = "0x777777" styleName = "heading"/>

         <s:Panel id = "menuPanel" title = "Using Menu" width = "500"
            height = "300">
            <s:layout>
               <s:VerticalLayout  gap = "10" verticalAlign = "middle"
                  horizontalAlign = "center"/>
            </s:layout>

            <s:HGroup>
               <s:Button label = "Show Menu" click = "showMenu(event)"/>
               <s:Button label = "Hide Menu" click = "hideMenu(event)"/>
            </s:HGroup>

            <s:HGroup>
               <s:Label text = "Menu Item selected:"/>
               <s:Label id = "lblSelected" fontWeight = "bold"/>
            </s:HGroup>
         </s:Panel>
      </s:VGroup>
   </s:BorderContainer>
</s:Application>

すべての変更が完了したら、link:/flex/flex_create_application [Flex-アプリケーションの作成]の章で行ったように、アプリケーションを通常モードでコンパイルして実行します。 アプリケーションに問題がなければ、次の結果が生成されます。[link:/flex/samples/ComplexControlsApplicationl#currentlyLoaded = Menu [Try it online]]

フレックスメニューコントロール