I have a component "child" which has a cancel button. Now this component is placed in a state called "newChildComp"
I also have another component called "parent". In the parent component, i have a button that dispatches an event . Here is the event code:
protected function addNew开发者_JAVA技巧Child(event:Event):void
{
if(currentState!='newChildComp')
currentState='newChildCom[';
child["cancelButtonId"].addEventListener("click",cancelButtonHandler);
}
so, basically,i am checking to see if the cancel button component in the Child component, while i am still in the parent Compoent, was clicked, if it was clicked, call the cancelButtonHandler. The problem is by the time the addNewChild handles the event, that cancel button was still null. My question is how do i solve this without using the itemCreationPolicy on the cancel button?
Thanks
you could just add the click property in mxml...
<s:Button click="cancelButtonHandler(event)" />
or if you don't want to do that, add event listener to creationComplete or contentCreationComplete on the container and add the event listener there.
<s:WhateverComponent includeIn="newChildComp" contentCreationComplete="{cancelButton.addEventListener etc.}"/>
does that make sense?
精彩评论