如何在flex中调度自定义事件
如何
在我的主 mxml 文件中的 Flex 中分派自定义事件 我已将此代码放入 controlmanagerevent 中分派此函数
private var ageVerifyMessage:AgeVerify = new AgeVerify();
public function onAgeVerifyFailed(event:ControlManagerEvent) : void
{
ageVerifyMessage.visible = true;
return;
}// end function
我已使用此代码
private function getUserDetailsHandler(event:ResultEvent) : void
{
userDetails = ResponseParser.parseUserDetails(event.result as Object);
if (!userDetails || !userDetails.age)
{
if (_flashVars.birth_date && _flashVars.birth_date != "" && _flashVars.birth_date.toString().split("/").length == 3)
{
reportConnectedUser();
}
else
{
dispatchEvent(new ControlManagerEvent(ControlManagerEvent.onAgeVerifyFailed));
}
}
else
{
reportConnectedUser(userDetails.age);
}
return;
}// end function
private var _controller:IControlManager;
public function initApp() : void
{
_controller.addEventListener(ControlManagerEvent.onServerStatusChange, onServerStatusChange);
_controller.addEventListener(ControlManagerEvent.onSelfCamFailed, onSelfCamFailed);
_controller.addEventListener(ControlManagerEvent.onNoCamerasFound, onNoCamerasFound);
_controller.addEventListener(ControlManagerEvent.onAgeVerifyFailed, onAgeVerifyFailed);
_controller.initController();
return;
}// end function
<local:AgeVerify horizontalCenter="0" id="ageVerifyMessage1" verticalCenter="0" visible="false"/>
我想问我缺少什么 为什么我的自定义事件不起作用
how to dispatch custom event in flex
in my main mxml file i have put this code to dispatch this function
private var ageVerifyMessage:AgeVerify = new AgeVerify();
public function onAgeVerifyFailed(event:ControlManagerEvent) : void
{
ageVerifyMessage.visible = true;
return;
}// end function
in controlmanagerevent i have used this code
private function getUserDetailsHandler(event:ResultEvent) : void
{
userDetails = ResponseParser.parseUserDetails(event.result as Object);
if (!userDetails || !userDetails.age)
{
if (_flashVars.birth_date && _flashVars.birth_date != "" && _flashVars.birth_date.toString().split("/").length == 3)
{
reportConnectedUser();
}
else
{
dispatchEvent(new ControlManagerEvent(ControlManagerEvent.onAgeVerifyFailed));
}
}
else
{
reportConnectedUser(userDetails.age);
}
return;
}// end function
private var _controller:IControlManager;
public function initApp() : void
{
_controller.addEventListener(ControlManagerEvent.onServerStatusChange, onServerStatusChange);
_controller.addEventListener(ControlManagerEvent.onSelfCamFailed, onSelfCamFailed);
_controller.addEventListener(ControlManagerEvent.onNoCamerasFound, onNoCamerasFound);
_controller.addEventListener(ControlManagerEvent.onAgeVerifyFailed, onAgeVerifyFailed);
_controller.initController();
return;
}// end function
<local:AgeVerify horizontalCenter="0" id="ageVerifyMessage1" verticalCenter="0" visible="false"/>
i want to ask what i am missing why my customevents not working
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的代码中我可以看到您正在侦听
_controller
的事件,但调度事件的对象不是_controller
而是this
。From your code I can see you're listening events of
_controller
but the object which dispatches event isn't_controller
butthis
.似乎
_controller.dispatchEvent(YourEvent)
应该可以工作。或者,我假设您没有使用像 Parsley 或 Swiz 这样的任何事件框架,您的 _controller 应该是组件树中的根:
当您在 YourComponent 中分派冒泡事件时,您的 _controller 将可以调用相应的侦听器。
Seems
_controller.dispatchEvent(YourEvent)
should work.Or, I assume you're not using any event framework like Parsley or Swiz, your _controller should be kind of root in the component tree:
When you dispatch an bubbling event in YourComponent, your _controller will be possible to invoke corresponding listeners.