PDA

View Full Version : menuEvent problems, Flex newbie...


loki421
02-13-2009, 11:51 PM
Hi all!

This is my first post here, so hi everyone!! :)

I'm a total newbie with Flex 3, i've only been using it for a couple of days and i think i'm in love! It really has inspired me. I used to work with CF but that's got nothing on Flex!!

Anyway, back to the point, i am trying to build a 'pop' out menu that appears when a user clicks a button (based on the code from the Adobe Flex component explorer), but i'm confused as to what syntax i should be using for the click event.

So far i've go a menu in xml, but can't link that menu to any of the states i have.

I'm getting the error 'Acces of possibly undifined property currentState through a reference static type Function'

Now i'd have thought that this should be a function not a variable? But as i said i've only been using Flex for a few days and don't really have a clue what i'm doing! :p

But anyway, here's the code i have so far

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:states>
<mx:State name="home" id="home">
<mx:AddChild position="lastChild">
<mx:Button x="216" y="119" label="Home"/>
</mx:AddChild>
</mx:State>
<mx:State name="about" id="about">
<mx:AddChild position="lastChild">
<mx:Panel x="165" y="73" width="250" height="200" layout="absolute" borderColor="#161616" title="About Us" color="#FCFCFC" backgroundColor="#717171" backgroundAlpha="1.0" alpha="1.0" cornerRadius="5" themeColor="#0B0B0B">
</mx:Panel>
</mx:AddChild>
</mx:State>
<mx:State name="contact" id="contact">
<mx:AddChild position="lastChild">
<mx:Label x="212" y="75" text="Contact Us" fontSize="15" fontWeight="bold" fontStyle="normal" color="#717171"/>
</mx:AddChild>
</mx:State>
</mx:states>

<mx:Script>
<![CDATA[

import mx.controls.Menu;
import mx.events.MenuEvent;
import flash.geom.Point;


private var point1:Point = new Point();
private var myMenu:Menu;



private function showMenu():void {
myMenu= Menu.createMenu(myCanvas, myMenuData, false);
myMenu.labelField="@label"
myMenu.addEventListener("itemClick", menuHandler);


point1.x=mybutton.x;
point1.y=mybutton.y;
point1=mybutton.localToGlobal(point1);

myMenu.show(point1.x + 25, point1.y + 25);
}

private function menuHandler(event:MenuEvent):void
{
menuHandler.currentState = 'myMenuData.id' ;
}

]]>
</mx:Script>

<mx:XML id="myMenuData">
<root>
<menuitem label="Home" id="home" itemClick="currentState='home'" />
<menuitem label="About Us" id="about" />
<menuitem label="Contact Us" id="contact" />
</root>
</mx:XML>



<mx:Canvas id="myCanvas">

<mx:Button id="mybutton" label="Click Here To Open Menu" click="showMenu();"
color="#0517C5"
themeColor="#00FFDE"
fontSize="10"
fillAlphas="[1.0, 1.0]"
fillColors="[#FFFFFF, #FFFFFF]"/>

</mx:Canvas>
<mx:Label x="217" y="4" text="Base state"/>


</mx:Application>


The error apears here on line 55

private function menuHandler(event:MenuEvent):void
{
menuHandler.currentState = 'myMenuData.id' ;
}


Does anyone know why this is happening? If so could you suggest a solution to this, it's really bugging me :)

Many thanks in advance all! :D