Hi all.
I have a Flex application that has states defined in the main MXML file. I have a navigation custom component I created that dispatches events. I also created a custom Event object. I just want to simply move from one state to the next using a click function. Problem is.. now that I have moved the Navigation into its own MXML custom componet, I cant seem to get clicks to work to change states. The links work when I try change the code to display an alert. So the buttons work, just can't scope the States correctly. Here is the code.. if I havent confused you so far.
Main MXML Application code:
Code:
<mx:states>
<mx:State name="Home"/>
<mx:State name="About"/>
</mx:states>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import events.OptionSelectEvent;
//Bindable]
//public var selectedOptions:ArrayCollection = new ArrayCollection();
private function optionHandler(event:OptionSelectEvent):void
{
Alert.show("Navigation Shows", "Trace Alert");
//var index:int = selectedOptions.getItemIndex(event.option);
}
]]>
</mx:Script>
<comp:BXNavigation id="bxNav"
x="3" y="64"
optionSelected="optionHandler(event)"/>
Navigation Component Code:
Code:
<mx:Script>
<![CDATA[
import events.OptionSelectEvent;
private function clickHandler(event:Event):void
{
var selection:String = event.target.label;
var optionSelectEvent:OptionSelectEvent = new OptionSelectEvent("optionSelected", selection);
dispatchEvent(optionSelectEvent);
}
]]>
</mx:Script>
<mx:Metadata>
[Event(name="optionSelected", type="events.OptionSelectEvent")]
</mx:Metadata>
<mx:LinkButton label="HOME"
x="47" y="18"
color="#FFFFFF"
click="clickHandler(event)"/>
<mx:LinkButton label="ABOUT US"
x="204" y="18"
color="#FFFFFF"
click="clickHandler(event)"/>
Custom Event Code:
Code:
package events
{
import flash.events.Event;
public class OptionSelectEvent extends Event
{
public var option:String;
public function OptionSelectEvent(type:String, option:String)
{
super(type);
this.option = option;
}
override public function clone():Event
{
return new OptionSelectEvent(type, option);
}
}
}
I thank you for all your help with this issue. This will help me better understand the use of States and how to communicate to them from custom components.