我有一个关于事件分派和分派在Flex中的问题。Flex自定义事件分派和视听堆栈收听
我的目标是传递一个组件(Comp1)中捕获的电子邮件地址并传递给另一个组件(Comp2)。这两个组件是viewstack的导航器内容。自定义事件从Comp1正确地发送了电子邮件,但无法到达Comp2。应用程序(主)看起来像:
<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>
的器Comp1看起来像
<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>
的组合物2看起来像
<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"/>
自定义事件LoginEventComplete样子
包事件 { 进口对象类型: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;
}
}}
有人可以帮助吗?非常感谢!
最佳大卫W¯¯
非常感谢 – 2011-05-28 03:58:13
@David Wu不客气。如果这是解决您的问题的答案,一定要将其标记为这样。点击答案旁边的“复选标记”。 – JeffryHouser 2011-05-28 11:23:04
是的,问题解决了。将这样标记。 – 2011-05-28 15:22:55