PureMVC Architects Lounge

PureMVC Manifold => Standard Version => Topic started by: francois on December 31, 2008, 04:24:15



Title: How to use Mediator with Flex's Repeater ?
Post by: francois on December 31, 2008, 04:24:15
Hello,
I'm developing some kind of image gallery in Flex 3 + PureMVC and in one of my UI component, I use a repeater, I guess it is a kind of unusual case... Usually it is simply:

Mediator:
:
someId.addEventListener()...

View component:
:
[Bindable] public var images:ArrayCollection;

...

<mx:HBox id="thumbnailContainer" width="50%" horizontalCenter="true" horizontalAlign="center" styleName="thumbContainer" backgroundAlpha="0.2" backgroundColor="#433838">
    <mx:Repeater id="thumbRepeater" dataProvider="{images}">
    <mx:Image source="{String(thumbRepeater.currentItem.thumb)}"
maintainAspectRatio="true"
height="50" width="100%"
click="onChangeCurrentImage(event)"
styleName="selectedThumb" />
    </mx:Repeater>
</mx:HBox>

...

private function onChangeCurrentImage(event:MouseEvent):void //, item:Object):void
{
selectedTarget = event.currentTarget;
selectedItem = selectedTarget.getRepeaterItem();
dispatchEvent(new Event(EVENT_CHANGE_CURRENT_IMAGE));
}

And in the mediator:
:
ui.addEventListener( ItemImagesPanel.EVENT_CHANGE_CURRENT_IMAGE, onChangeCurrentImage);


It is the first time I use a repeater in an UI with PUREMVC Mediator and I'm not sure if I did it right !
I need to get the item data in order to change the image... I hope my post was understabe enough ;-)

Any advices, remarks ?

I guess I could make a custom event and add a "data" property on it...

Thanks!


Title: Re: How to use Mediator with Flex's Repeater ?
Post by: francois on January 04, 2009, 11:56:30
I found a solution, I use the "Bubbling phase" of the MouseEvent and I add the listener to the container that hold the several button added by the repeater...
I had also to set mouseChildren to false on each <mx:Image>... If I didn't add "mouseChildren" sometime the target of the event would be an mx:Loader...

Cheers


Title: Re: How to use Mediator with Flex's Repeater ?
Post by: puremvc on January 05, 2009, 02:33:11
Thanks for following up with your findings. Unfortunately I lost my response to this one, I thought I posted from my phone.

I was going to enquire whether you actually needed the mediators on the repeated objects or if you couldn't simply let their messages bubble and catch them in the mediator for the component that holds the repeater.

Cheers,
-=Cliff>