Flex: Call function from included component

感情迁移 提交于 2019-12-05 21:58:03

Add this to menu:

  <mx:Metadata>
         [Event(name="buttonClicked", type="flash.events.Event")]
    </mx:Metadata>

 <mx:Button x="10" y="10" width="80" label="Show" id="btnOne" click="this.showLabel=true;dispatchEvent(new Event("buttonClicked"));"/>

Change main to:

  <ns1:menu id="buttons" buttonClicked="changeText("Your Text");">

I couldn't tell where current text is coming from but if it is from menu you may have to build your own custom flex event or create a common variable for the two parts to access. The first is usually preferred.

P.S. The event metadata thing could also be achieved by adding the event listener when the creation of the application completes. You would add to main:

buttons.addEventListener("buttonClicked",changeText("Your Text"));

there is a simpler way, just use parentDocument.

Change this:

<mx:Button x="181" y="10" width="80" label="Run Function" id="btnThree" click="{changeText('changeText')}"/>

to:

<mx:Button x="181" y="10" width="80" label="Run Function" id="btnThree" click="{parentDocument*.changeText('changeText')}"/>**
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!