Different behaviour between Flex mx:XMLList and fx:XMLList - apache-flex

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.

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 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>

Programmatically change Flex MenuBar item toggled property

I have this MenuBar control in Flex 3. How can I programmatically change the toggled property to false?
<mx:MenuBar labelField="#label" itemClick="itemClickHandler(event);" left="0" right="0" top="0" id="menuBar">
<mx:XMLList>
<menuitem label="File" data="top">
<menuitem label="New" data="file-new"/>
</menuitem>
<menuitem label="View" >
<menuitem label="Grid" type="check" toggled="true" data="view-grid"/>
</menuitem>
</mx:XMLList>
</mx:MenuBar>
Easy enough, just need to bind the toggle property to a property within the class like so:
<fx:Script>
<![CDATA[
[Bindable] private var _toggled:Boolean = true;
]]>
</fx:Script>
<mx:MenuBar labelField="#label" itemClick="itemClickHandler(event);" left="0" right="0" top="0" id="menuBar">
<mx:XMLList>
<menuitem label="File" data="top">
<menuitem label="New" data="file-new"/>
</menuitem>
<menuitem label="View" >
<menuitem label="Grid" type="check" toggled="{this._toggled}" data="view-grid"/>
</menuitem>
</mx:XMLList>
</mx:MenuBar>
Now when you change the _toggled property, it will reflect in the menubar.

menubar with susbsitems events

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
}

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