开发者

Add event listener to Flex components inside a repeater

I want to add an event listener to each component inside a repeater, but don't know how. Here's some code I have tried:

<mx:Repeater id="rp" dataProvider="{dataProvide开发者_StackOverflow中文版r}" width="100%">
   <mx:Button id="attach" creationComplete="addListeners(attach[rp.currentIndex])"/>
</mx:Repeater>

This doesn't work. creationComplete is not called until the repeater has finished instead of (as I expected) when the creation of the button is complete. I'm not sure how to accomplish this.

BTW - I also tried placing the creationComplete on the parent component to the repeater, but it would only be called the first time the component was rendered (the data inside the repeater sometimes changes) so that didn't work.


If you're using an Event defined in metadata, it can be as simple as adding click="myClickHandler(event)". You can also do something like this:

<yourNS:YourComponent id="foo>
    <creationComplete>
        <fx:Script>
            (foo[yourRepeater.currentIndex] as EventDispatcher).addEventListener('the event', yourEventHandler);
        </fx:Script>
    </creationComplete>
</yourNS:YourComponent >
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜