shizny
|
|
« on: March 05, 2008, 02:34:51 » |
|
I have a set of buttons that when clicked create a new Menu. In that menu I want to be able to trap mouseclicks and create an event that will talk with the appropriate mediator. Can anybody tell me if I am doing this in the recommended PureMVC way. Here is my code for the menu component.
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="1000" height="200"> <mx:Metadata> [Event('importGame')] [Event('modifyGame')] [Event('generateReports')] [Event('exportData')] </mx:Metadata> <mx:Script> <![CDATA[ import mx.controls.Menu; import com.wolffebrothers.gametimetech.*;
public static const importGame:String = "importGame"; public static const modifyGame:String = "modifyGame"; public static const generateGame:String = "generateReports"; public static const exportGame:String = "exportData"; // Create and display the Menu control. private function createAndShow():void { //call notification ? JJM var myMenu:Menu = Menu.createMenu(null, myMenuData, false); myMenu.labelField="@label"; myMenu.show(10, 50); myMenu.addEventListener(MouseEvent.CLICK, mainMenuClicked); } public function mainMenuClicked(event:Event):void { trace("Main menu clicked"); dispatchEvent( new Event( importGame ) ); } ]]> </mx:Script> <!-- send to Proxy JJM --> <!-- Define the menu data. --> <mx:XML format="e4x" id="myMenuData"> <root> <menuitem label="Import New Game Data"/> <menuitem label="Modify Existing Game"/> <menuitem label="Generate Reports"/> <menuitem label="Export Data"/> </root> </mx:XML> <!-- call notification JJM --> <!-- Define a Button control to open the menu --> <mx:HBox> <mx:Button id="Stats" label="Stats" click="createAndShow();"/> <mx:Button id="PlayBook" label="Play Book" click="createAndShow();" enabled="false"/> <mx:Button id="VideoAnalysis" label="Video Analysis" click="createAndShow();" enabled="false"/> <mx:Button id="Recruiting" label="Recruiting" click="createAndShow();" enabled="false"/> </mx:HBox> </mx:Canvas>
|