actionscript 3 - Add MXML event listener on component's child -
i'm not sure if possble, add event listener on sub component mxml. this:
my component
<s:group> <s:button id="mybtn" label="click me" /> </s:group>
main application
<local:mycomponent> <local:mybtn click="dosomething()" /> </local:mycomponent>
i know can in code, want know if it's possible in mxml. if it's possible, correct syntax?
it possible, requires lot of setup.
first add event metadata mycomponent:
<s:group> <fx:metadata> [event(name="click", type="flash.events.mouseevent")] </fx:metadata> <s:button id="mybtn" label="click me" /> </s:group>
in theory should make sure component dispatches click event; since click bubble default not need else event.
now, main component show event in mxml code hinting, , compiler not complain:
<local:mycomponent click="dosomething()> </local:mycomponent>
generally, not recommend trying drill down component in order place listeners on events dispatched component's children. break of encapsulation. parent component should not know implementation details of children.
Comments
Post a Comment