Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,644 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,099 people online right now. Registration is fast and FREE... Join Now!




Menu Component event handler

 
Reply to this topicStart new topic

Menu Component event handler, How can you get the index of the selected object?

CBPTrainer
post 11 Sep, 2008 - 02:05 PM
Post #1


New D.I.C Head

*
Joined: 11 Sep, 2008
Posts: 1

I have made a menu that is populated by an XML file. It displays a list of maps when the user clicks a button. What I want is to be able to set a variable (i) to the number of the index of the menu selection and use that number to open a filename in an array named filename_ar.

I've been fooling around with Menu.IndexOf all day and I can't seem to get it to return a number.

If it could I could use:
getURL(filename_ar[i]);

If I could get a number of the node in the XML file, that would probably work as well.

Anne Richardson

CODE


import mx.controls.Menu;

var FLmenu:Menu = Menu.createMenu(myParent_mc, my_xml);

//!*var menuNames_ar:Array = new Array("South Florida", "Florida Keys", "Miami", "Northeastern Florida", "Southwestern Florida", "Central Florida", "Florida South", "Florida North");*!//

var fileNames_ar:Array = new Array("FL_CG_SOUTH_OFO.pdf", "FL_MAP_KEYS_NLECC.pdf", "FL_MAP_NE_NLECC.pdf", "FL_MAP_NW_NLECC.pdf", "FL_MAP_SW_NLECC.pdf", "FL_MAP_CENTRAL_NLECC.pdf", "FL_MAP_SOUTH_NLECC.pdf", "FL_CG_NORTH_OFO.pdf");

my_FL_btn.onRelease = function(){
var my_xml:XML = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success:Boolean){
if (success) {
FLmenu.dataProvider = my_xml.firstChild;
    }
}
my_xml.load("FLmenu.xml");

FLmenu.dataProvider = [{data:0, label:"South Florida"},
         {data:1, label:"Florida Keys"},
         {data:2, label:"Miami"},
         {data:3, label:"Northeastern Florida"},
         {data:4, label:"Menuname
Northwestern Florida"},
         {data:5, label:"Southwestern Florida"},
         {data:6, label:"Central Florida"},
         {data:7, label:"Florida South"},
         {data:8, label:"Florida North"}];

FLmenu.show(500, 300);
}

var menuListener:Object = new Object();
menuListener.change = function(evt_obj:Object) {
var selectedItem = evt_obj.menuItem.attributes.label;
trace(selectedItem);

}
FLmenu.addEventListener("change", menuListener);



FLmenu.XML:

<menu>
<menuitem label="Maps">
<menuitem label="Central Florida" />
<menuitem label="Florida Keys" />
<menuitem label="Florida Keys" />
<menuitem label="Northeast Florida" />
<menuitem label="Northwest Florida" />
<menuitem label="South Florida" />
<menuitem label="Southwest Florida" />
</menuitem>
<menuitem label="Channel Guides">
<menuitem label="North Florida" />
<menuitem label="South Florida" />
</menuitem>
</menu>
User is offlineProfile CardPM

Go to the top of the page

DilutedImage
post 24 Sep, 2008 - 07:08 PM
Post #2


D.I.C Addict

Group Icon
Joined: 20 Nov, 2006
Posts: 642



Thanked 6 times

Dream Kudos: 25
My Contributions


I don't have time to really dig into this, but you might want to look into these properties:

FLmenu.selectedIndex
FLmenu.selectedItem
evt_obj.index
evt_obj.item

User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 04:40AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month