Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: How to use Mediator with Flex's Repeater ?  (Read 8186 times)
francois
Newbie
*
Posts: 4


View Profile Email
« 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!
« Last Edit: December 31, 2008, 04:31:05 by francois » Logged
francois
Newbie
*
Posts: 4


View Profile Email
« Reply #1 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
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 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>
Logged
Pages: [1]
Print