środa, 14 lipca 2010

Pass reference to "this" to child object generated by Repeater.

Let's assume that we've got a component named Item. This component has a public property named controller.

The idea is that we want to pass reference to this (usually a parent object of Repeater) to Repeater children.

You could use basic logic and try to do something like this:
<mx:Repeater dataProvider="{dP}">
    <layouts:Item controller="{this}" />
</mx:Repeater>
But unfortunately Flex is not a place where you should use logical solutions. In shown example scope of this is fubar. Thus the necessary workaround which is displayed below. Please note that XXX should be the name of the Class which is represented by this pointer.
[Bindable] private var _this:XXX; 
private function init():void
{
_this = this; 
}
<mx:Repeater dataProvider="{dP}">
    <layouts:Item controller="{_this}" />
</mx:Repeater>

Brak komentarzy:

Prześlij komentarz