I got a question about event dispatching and dispatching in flex.
My goal is to pass an email address captured in one component (Comp1) and be passed to another (Comp2). These two components are navigator content of a viewstack. The custom event dispatched the email correctly from Comp1 but somehow could not reach Comp2. The application (Main) looks like :
<fx:Script>
<![CDATA[
import events.LoginEventComplete;
protected function loginHandler(event:LoginEventComplete):void
{
myViewStack.selectedChild = idViewMain;
}
]]>
</fx:Script>
<s:Panel width="100%" height="100%">
<mx:ViewStack id="myViewStack" selectedIndex="0" width="100%" height="100%">
<views:Comp1 id="idViewLogin" login="loginHandler(event)"/>
<views:Comp2 id="idViewMain"/>
</mx:ViewStack>
</s:Panel>
The Comp1 looks like
<fx:Metadata>
[Event(name="login", type="events.LoginEventComplete")]
</fx:Metadata>
<fx:Script>
<![CDATA[
import events.LoginEventComplete;
protected function bnLogIn_clickHandler(event:MouseEvent):void{
var e:LoginEventComplete = new LoginEventComplete("login");
e.workemail = tiWorkEmail.text;
dispatchEvent(e);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:layout>
<s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/>
</s:layout>
<s:Panel width="400" height="500">
<s:Label text="Email" x="130" y="150"/>
<s:TextInput id="tiWorkEmail" top="140" left="180" right="60"/>
<s:Button
id="bnLogIn"
label="Log In"
top="220" left="180"
click="bnLogIn_clickHandler(event)"/>
</s:Panel>
The Comp2 looks like
<fx:Script>
<![CDATA[
import events.LoginEventComplete;
import valueObjects.Employee;
protected function init():void
{
this.addEventListener(LoginEventComplete.LOGIN, mainHandler);
}
private function mainHandler(event:LoginEventComplete):void{
tiWorkEmail.text = event.workemail;
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:layout>
<s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/>
</s:layout>
<s:Label id="idWorkEmail" text="Email"/>
<s:TextInput id="tiWorkEmail"/>
The custom event LoginEventComplete look like
package events { import flash.events.Event; public class LoginEventComplete extends Event { public var workemail:String;
public static const LOGIN:String = "login";
public function LoginEventComplete(type:String)
{
super(type, true, false);
this.workemail = workemail;
}
override public function clone():Event
{
var newEvent:LoginEventComplete = new LoginEventComplete(type);
newEvent.workemail = workemail;
return newEvent;
}
} }
Can someone help please? Many thanks!
Best David W