menubar with susbsitems events - apache-flex

can any one help me regarding the events related to menubar sub items,
here is some code iam working with
<menuitem label="Home"/>
<menuitem label="AboutUs"/>
<menuitem label="CoursesOffered">
<menuitem label="UG">
<menuitem label="CSE"/>
<menuitem label="EEE"/>
<menuitem label="ECE"/>
<menuitem label="IT"/>
<menuitem label="MECH"/>
<menuitem label="CIVIL"/>
</menuitem>
<menuitem label="PG">
<menuitem label="CSE"/>
<menuitem label="ECE"/>
<menuitem label="MCA"/>
</menuitem>
</menuitem>
<menuitem label="Departments">
<menuitem label="CSE" >
<menuitem label="HOD" />
<menuitem label="Staff" />
<menuitem label="DeparmentGallary"/>
</menuitem>
<menuitem label="ECE">
<menuitem label="HOD"/>
<menuitem label="Staff" />
<menuitem label="DeparmentGallary"/>
</menuitem>
<menuitem label="EEE">
<menuitem label="HOD"/>
<menuitem label="Staff" />
<menuitem label="DeparmentGallary" />
</menuitem>
<menuitem label="IT">
<menuitem label="HOD"/>
<menuitem label="Staff"/>
<menuitem label="DeparmentGallary"/>
</menuitem>
<menuitem label="MECH">
<menuitem label="HOD"/>
<menuitem label="Staff"/>
<menuitem label="DeparmentGallary"/>
</menuitem>
<menuitem label="CIVIL">
<menuitem label="HOD"/>
<menuitem label="Staff"/>
<menuitem label="DeparmentGallary"/>
</menuitem>
<menuitem label="SH"/>
</menuitem>
<menuitem label="ExaminationSection"/>
<menuitem label="TrainingAndPlacement"/>
<menuitem label="Alumni"/>
<menuitem label="ContactUs"/>
i want to handle events wen particular subitem is clicked
for example ,if submnu item hod of cse is clicked it should go to the particular mxml page ,and if hod of ece is clicked it shold goto other page
how do i differentiate each page of particular deparment
how do select that particulasr item of that particular submenu itm
if any one knows plz help meeeeeeee...................?????

The easiest way is to add an id attribute to any menu item that is a leaf and store those id values in static constant fields in the corresponding class.
public static const None:Number = 0;
public static const CSE_HOD:Number = 12;
public static const CSE_STAFF:Number = 13;
//and so on
in the dataProvider
<menuitem label="CSE" id="0">
<menuitem label="HOD" id="12"/>
<menuitem label="Staff" id="13"/>
</menuitem>
<menuitem label="ECE" id="0">
and the itemClick event handler of the MenuBar
switch(Number(menuEvent.item.#id))
{
case CSE_HOD:
//deal with cse hod here
break;
case CSE_STAFF:
//deal with cse staff here
break;
//and so on
default:break; //switch defaults for non leaf menu items like CSE etc
}

Related

How to Add CSS3 Elements to DW CS6 Code Hints

Ok, I spent quite a bit of time trying to research plugins and/or extensions that would allow Dreamweaver to hint the few commands of CSS3 that were not showing up.
I am posting the solution below.
I FIGURED OUT A METHOD SO I WILL ANSWER MY OWN QUESTION but I thought it would be helpful to others that need to do the same. I personally am going to show how to add all the "flex" stuff on a windows computer.
STEP 1 - Locate the file
Use File Explorer to navigate to; /Program Files/Adobe/Adobe Dreamweaver CS6/configuration/CodeHints/ it may be in a /Program Files (x86)/ folder.
STEP 2 - Allow Access to CodeHints.xml
Right click on CodeHints.xml and click security tab. Go to your current user (usually Users (You\Users)) in the list and make sure it has "modify" enabled. If not, click Edit, select the current user in the popup and tick the Modify, then click OK at the bottom and OK again on the security tab.
STEP 3 - Add flex as a display: option in CodeHints.xml
Use an editor that can edit XML, such as Sublime, Dreamweaver or any text editor and search for display: - make sure you add the colon to the search.
There will be two results, you want the first one that starts <menu pattern="display:".
Add a new menu item of <menuitem label="flex" value="flex" icon="shared/mm/images/hintMisc.gif" /> anywhere between the opening and closing
STEP 4 - Add flex-* tags.
After the Closing </menu> of that display: block add:
<menu pattern="flex-wrap:" additionaldismisschars=";:" allowwhitespaceprefix="true" displayrestriction="css" allowmultiplevalues="true">
<menuitem label="nowrap" value="nowrap" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="wrap" value="wrap" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="wrap-reverse" value="wrap-reverse" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="initial" value="initial" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="inherit" value="inherit" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="!important" value="!important" icon="shared/mm/images/hintFlag.gif" />
</menu>
<menu pattern="flex-shrink:" additionaldismisschars=";:" allowwhitespaceprefix="true" displayrestriction="css" allowmultiplevalues="true">
<menuitem label="initial" value="initial" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="inherit" value="inherit" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="!important" value="!important" icon="shared/mm/images/hintFlag.gif" />
</menu>
<menu pattern="flex-basis:" additionaldismisschars=";:" allowwhitespaceprefix="true" displayrestriction="css" allowmultiplevalues="true">
<menuitem label="auto" value="auto" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="initial" value="initial" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="inherit" value="inherit" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="!important" value="!important" icon="shared/mm/images/hintFlag.gif" />
</menu>
<menu pattern="flex-grow:" additionaldismisschars=";:" allowwhitespaceprefix="true" displayrestriction="css" allowmultiplevalues="true">
<menuitem label="initial" value="initial" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="inherit" value="inherit" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="!important" value="!important" icon="shared/mm/images/hintFlag.gif" />
</menu>
<menu pattern="flex-direction:" additionaldismisschars=";:" allowwhitespaceprefix="true" displayrestriction="css" allowmultiplevalues="true">
<menuitem label="row" value="row" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="row-reverse" value="row-reverse" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="column" value="column" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="column-reverse" value="column-reverse" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="initial" value="initial" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="inherit" value="inherit" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="!important" value="!important" icon="shared/mm/images/hintFlag.gif" />
</menu>
<menu pattern="flex-flow:" additionaldismisschars=";:" allowwhitespaceprefix="true" displayrestriction="css" allowmultiplevalues="true">
<menuitem label="row" value="row" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="row-reverse" value="row-reverse" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="column" value="column" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="column-reverse" value="column-reverse" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="nowrap" value="nowrap" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="wrap" value="wrap" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="wrap-reverse" value="wrap-reverse" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="initial" value="initial" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="inherit" value="inherit" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="!important" value="!important" icon="shared/mm/images/hintFlag.gif" />
</menu>
STEP 5 - Add those labels to the hint list.
Search display: again and go the second one that is something like this <menuitem label="display" value="display:" icon="shared/mm/images/hintMisc.gif" />
Add below that entry:
<menuitem label="flex-wrap" value="flex-wrap:" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="flex-basis" value="flex-basis:" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="flex-direction" value="flex-direction:" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="flex-flow" value="flex-flow:" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="flex-grow" value="flex-grow:" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="flex-shrink" value="flex-shrink:" icon="shared/mm/images/hintMisc.gif" />
again making sure that the icon path matches the others.
STEP 6 - Save and Restart Dreamweaver.
STEP 7 - Be happy your code hinting works!
Hope that helps someone out there.
I'm adding a few more useful lines to the XML. Someone else might need it.
As in STEP 4 add:
<menu pattern="justify-content:" additionaldismisschars=";:" allowwhitespaceprefix="true" displayrestriction="css" allowmultiplevalues="true">
<menuitem label="flex-start" value="flex-start" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="flex-end" value="flex-end" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="center" value="center" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="space-between" value="space-between" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="space-around" value="space-around" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="!important" value="!important" icon="shared/mm/images/hintFlag.gif" />
</menu>
<menu pattern="align-items:" additionaldismisschars=";:" allowwhitespaceprefix="true" displayrestriction="css" allowmultiplevalues="true">
<menuitem label="flex-start" value="flex-start" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="flex-end" value="flex-end" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="center" value="center" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="baseline" value="baseline" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="stretch" value="stretch" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="!important" value="!important" icon="shared/mm/images/hintFlag.gif" />
</menu>
<menu pattern="align-content:" additionaldismisschars=";:" allowwhitespaceprefix="true" displayrestriction="css" allowmultiplevalues="true">
<menuitem label="flex-start" value="flex-start" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="flex-end" value="flex-end" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="center" value="center" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="space-between" value="space-between" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="space-around" value="space-around" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="stretch" value="stretch" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="!important" value="!important" icon="shared/mm/images/hintFlag.gif" />
</menu>
As in STEP 5 add:
<menuitem label="justify-content" value="justify-content:" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="align-items" value="align-items:" icon="shared/mm/images/hintMisc.gif" />
<menuitem label="align-content" value="align-content:" icon="shared/mm/images/hintMisc.gif" />

How to listen to a custom event dispatched by a renderer in Flex?

I'm having the following problem: I've implemented a custom headRenderer for my DataGridColumn. The idea is to have a dropdown menu when clicked on the column header. The problem is I don't know how to add a listener or pass a variable to the renderer since the renderer class is instantiated by the ClassFactory.
The renderer class:
<?xml version="1.0"?>
<!-- itemRenderers\dataGrid\myComponents\RendererDGHeader.mxml -->
<mx:HBox xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:fx="http://ns.adobe.com/mxml/2009"
width = "100%"
>
<fx:Script>
// ...
// Event handler for the Menu control's change event.
private function menuHandler(evt:MenuEvent):void {
//Alert.show("Label: " + evt.item.#label, "Clicked menu item");
if (evt.item.#eventName == "typeLat"){
typeIcon.load("assets/type_location.jpg");
evt.item.toggled=true;
//variable.setColumnType(myLabel.text, "type"); // how can I pass "variable" to this renderer?
} else if (evt.item.#eventName == "typeLng"){
typeIcon.load("assets/type_location.jpg");
evt.item.toggled=true;
} else if (evt.item.#eventName == "typeTime"){
typeIcon.load("assets/type_time.png");
evt.item.toggled=true;
}
else if (evt.item.#eventName == "similarity"){
dispatchEvent(new SimilarityEvent("selectSimilarity", null, null)); // how to listen to this event?
}
}
</fx:Script>
<fx:Declarations>
<fx:XML id="myMenuData">
<root>
<menuitem label="Select type..." eventName="copy">
<menuitem label="Other..." eventName="typeOther"/>
<menuitem type="separator"/>
<menuitem label="Order" type="check" eventName="typeOther"/>
<menuitem label="Range" type="check" eventName="typeOther"/>
<menuitem label="Date/Time" type="check" eventName="typeTime"/>
<menuitem label="Latitude" type="check" eventName="typeLat"/>
<menuitem label="Longitude" type="check" eventName="typeLng"/>
</menuitem>
<menuitem label="Define similarity..." eventName="similarity"/>
<menuitem type="separator"/>
<menuitem label="Filter objects..." eventName="similarity"/>
<menuitem label="Order" eventName="similarity">
<menuitem label="Ascending" eventName="typeOther"/>
<menuitem label="Descending" eventName="typeOther"/>
</menuitem>
<menuitem type="separator"/>
<menuitem label="Remove" eventName="paste"/>
</root>
</fx:XML>
</fx:Declarations>
<mx:Label id="myLabel" click="showMenu();"/>
<mx:Image height="20" id = "typeIcon"/>
</mx:HBox>
Here is how I instantiate the renderer:
var newColumn:DataGridColumn = new DataGridColumn();
newColumn.dataField = attr;
newColumn.headerText = attr;
newColumn.sortable = false;
newColumn.editable = false;
newColumn.draggable = false;
newColumn.headerRenderer = new ClassFactory(newviews.RendererDataHeader);
cols.push(newColumn);
any help will be highly appreciated
Add event listener to control (DataGrid) and make event bubble, it will be caught.

how to develop 2 level horizontal menu in flex3?

How can I develop a 2 level horizontal menu in flex 3? I want a sub menu to appear when you mouse over the 1st level.
The Menu control has this functionality built in. Here's Adobe's online documentation with some examples for you to check out.
Example:
<?xml version="1.0"?>
<!-- menus/SimpleMenuControl.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script>
<![CDATA[
// Import the Menu control.
import mx.controls.Menu;
// Create and display the Menu control.
private function createAndShow():void {
var myMenu:Menu = Menu.createMenu(null, myMenuData, false);
myMenu.labelField="#label";
myMenu.show(10, 10);
}
]]>
</mx:Script>
<!-- Define the menu data. -->
<mx:XML format="e4x" id="myMenuData">
<root>
<menuitem label="MenuItem A" >
<menuitem label="SubMenuItem A-1" enabled="false"/>
<menuitem label="SubMenuItem A-2"/>
</menuitem>
<menuitem label="MenuItem B" type="check" toggled="true"/>
<menuitem label="MenuItem C" type="check" toggled="false"/>
<menuitem type="separator"/>
<menuitem label="MenuItem D" >
<menuitem label="SubMenuItem D-1" type="radio"
groupName="one"/>
<menuitem label="SubMenuItem D-2" type="radio"
groupName="one" toggled="true"/>
<menuitem label="SubMenuItem D-3" type="radio"
groupName="one"/>
</menuitem>
</root>
</mx:XML>
<mx:VBox>
<!-- Define a Button control to open the menu -->
<mx:Button id="myButton"
label="Open Menu"
click="createAndShow();"/>
</mx:VBox>
</mx:Application>

Different behaviour between Flex mx:XMLList and fx:XMLList

Having this code in a flex3 project worked (note the enabled property on the sixth item):
<mx:XMLList id="items">
<menuitem label="file">
<menuitem label="file.new" data="New"/>
<menuitem label="file.saveAs" data="SaveAs"/>
<menuitem label="file.open" data="Open"/>
<menuitem label="file.close" data="Close"/>
</menuitem>
<menuitem label="business">
<menuitem label="business.add" data="AddBusiness"/>
<menuitem label="business.delete" enabled="{someproperty.selected}" data="DeleteBusiness"/>
</menuitem>
<menuitem label="help">
<menuitem label="help.about" data="About" />
</menuitem>
</mx:XMLList>
However fx:XMLList can't handle binding in that way. This code gives a compilation error:
<fx:XMLList id="items">
<menuitem label="file">
<menuitem label="file.new" data="New"/>
<menuitem label="file.saveAs" data="SaveAs"/>
<menuitem label="file.open" data="Open"/>
<menuitem label="file.close" data="Close"/>
</menuitem>
<menuitem label="business">
<menuitem label="business.add" data="AddBusiness"/>
<menuitem label="business.delete" enabled="{someproperty.selected}" data="DeleteBusiness"/>
</menuitem>
<menuitem label="help">
<menuitem label="help.about" data="About" />
</menuitem>
</fx:XMLList>
1120: Access of undefined property items.
I suppose you are compiling your project in strict mode and that you are using the items XMLList directly as dataProvider for some component (at least it was the only way I've found to reproduce the problem), like this:
<s:List>
<s:dataProvider>
<s:XMLListCollection>
<fx:XMLList id="items">
<menuitem label="file">
<menuitem label="file.new" data="New"/>
<menuitem label="file.saveAs" data="SaveAs"/>
<menuitem label="file.open" data="Open"/>
<menuitem label="file.close" data="Close"/>
</menuitem>
<menuitem label="business">
<menuitem label="business.add" data="AddBusiness"/>
<menuitem label="business.delete" enabled="{someproperty.selected}" data="DeleteBusiness"/>
</menuitem>
<menuitem label="help">
<menuitem label="help.about" data="About"/>
</menuitem>
</fx:XMLList>
</s:XMLListCollection>
</s:dataProvider>
</s:List>
This reproduces the same error (#1120) you mentioned. In order to fix this, you have to declare the XMLList prior to its container (in the example it's a List), in the <fx:Declarations> block. This way you are assuring that the items reference will exist before the container is created, which is what strict mode verifies during compilation.
<fx:Declarations>
<fx:XMLList id="items">
<menuitem label="file">
<menuitem label="file.new" data="New"/>
<menuitem label="file.saveAs" data="SaveAs"/>
<menuitem label="file.open" data="Open"/>
<menuitem label="file.close" data="Close"/>
</menuitem>
<menuitem label="business">
<menuitem label="business.add" data="AddBusiness"/>
<menuitem label="business.delete" enabled="{someproperty.selected}" data="DeleteBusiness"/>
</menuitem>
<menuitem label="help">
<menuitem label="help.about" data="About"/>
</menuitem>
</fx:XMLList>
</fx:Declarations>
<s:List>
<s:dataProvider>
<s:XMLListCollection source="{ items }"/>
</s:dataProvider>
</s:List>
Update: This will also generate the #1120 error if you don't have the compiler's strict mode option enabled. Just declare the XMLList in the <fx:Declarations> block and it should work fine.

How to open a menu automatically with a shortcut?

I have a MenuBar which contains general menu items like File, View, Tools ,Help.
I have sub items in each of those menuitems.
The problem is that i want to open the 'File' menu automatically when i press Alt+f key.
I could capture the keyevents on the view.
But how to open the File Menu of the MenuBar (what is the function that needs to be called from MenuBar Class to popup those sub menuitems) ?
I have searched for some information on google .. but cudnt find.
or else if u have any better solution or example ..plz do post it.
<root>
<menuitem label="File">
<menuitem label="New" enabled="false"/>
<menuitem label="Open.." enabled="false"/>
<menuitem label="Save" enabled="false"/>
<menuitem label="Restore" enabled="false"/>
<menuitem label="Print" enabled="true"/>
<menuitem type="seperator" enabled="false"/>
<menuitem label="Exit" enabled="true"/>
</menuitem>
<menuitem label="View" accesskey="v">
<menuitem label="Zoom In" enabled="true" maxValue="200"/>
<menuitem label="Zoom Out" enabled="true" maxValue="25"/>
</menuitem>
<menuitem label="Tools" enabled="false">
<menuitem label="item1" enabled="false"/>
<menuitem label="item2" enabled="false"/>
</menuitem>
</root>
Thanks in advance :)
Sriss
To open a menu at its position :
var fileMenu:Menu = mnuBar.getMenuAt(0);
pnt : Point = new Point(mnuBar.x,mnuBar.y + mnuBar.height);
pnt = localToGlobal(pnt);
fileMenu.show(pnt.x,pnt.y);
I solved it :)
var fileMenu:Menu = myMenuBar.getMenuAt(0);
fileMenu.show();
It works, but now the problem is .. the submenu is popping out at (0,0) location of the application not at the file Menu item ..!!!
It's a fake Menu!
A better way to do it is:
e.preventDefault(); // will play against pressed ESC, too
menuBar.setFocus();
menuBar.dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN, false, false, 0, Keyboard.RIGHT));

Resources