Reputation: 97
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
Upvotes: 0
Views: 367
Reputation: 882
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:
Application
IControlManager(_controller)
HBox
YourComponent
When you dispatch an bubbling event in YourComponent, your _controller will be possible to invoke corresponding listeners.
Upvotes: 0
Reputation: 14221
From your code I can see you're listening events of _controller
but the object which dispatches event isn't _controller
but this
.
Upvotes: 1