开发者

how could i possibly solve a null-component issue in flex?

开发者 https://www.devze.com 2023-03-15 03:15 出处:网络
I have a component \"child\" which has a cancel button. Now this component is placed in a state called \"newChildComp\"

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消