Repeating custom components works great.
When you say, "I need to use extensive binding", what exactly do you mean?
What do you want to happen?
If you dataProvider is an xmlListCollection or an ArrayCollection, you can use
getItemIndex() to return the index of the item. Pass a reference to both the
entire dataprovider and the specific item (using {repeater.currentItem}) into
the component. Then use getItemIndex() to get the index, and decide how to
handle it.
Below are some snippets showing simple use of a custom component in a repeater.
Tracy
Goal: Display a list of items using a complex display for each item, and have
each of those items behave like a menu element and respond to a click anywhere
on the item by running a handler function.
One solution is to use a Repeater with a custom component
In the main app or component, declare the Repeater, and the click handler
function.
<mx:Application ...
<mx:Script><![CDATA[
import MyRepeaterItem;
...
private function onRPItemClick(oEvent:Event):void
{
var xmlItem:XML = XML(oEvent.target);
}//onRPItemClick
]]></mx:Script>
<mx:VBox ...>
<mx:Repeater id="rp" dataProvider="{_xmlData}" ...>
<!-- Note we pass in the entire currentItem, and define a click handler
-->
<MyRepeaterItem xmlItem="{rp.currentItem}"
itemClick="onRPItemClick(event)" .../>
</mx:Repeater
</mx:VBox>
</mx:Application>
And in the component, MyRepeaterItem.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox mouseChildren="false" buttonMode="true" click="onClick(event)" >
<!-- The metadata tag below allows us to define an itemClick handler in mxml,
as in the code above -->
<mx:Metadata>
[Event(name="itemClick", type="flash.events.Event")]
</mx:Metadata>
<mx:Script><![CDATA[
[Bindable]private var _xmlItem:XML;
/** Setter function */
public function set xmlItem(xml:XML):void
{
_xmlItem = xml;
//do any special, non-bound ui stuff you want
}//set xmlItem
/** Getter function */
public function get xmlItem():XML
{
return _xmlItem;
}//get xmlItem
/** Outer VBox Click handler function */
private function onClick():void
{
dispatchEvent(new Event("itemClick",false); //we do not need/want this
event to bubble
}//onClick
]]></mx:Script>
<!-- Now declare the Item UI -->
<mx:Text id="lbDescription" text="[EMAIL PROTECTED]" width="100%"
height="100%" />
</mx:HBox>
________________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Nadeem
Manzoor
Sent: Thursday, December 27, 2007 12:01 PM
To: [email protected]
Subject: [flexcoders] Repeating a Custom Component (VBox)
Hello All
If anyone can help me with this. I am using repeater and repeated item should
be a Custom VBOX. Repeater do not have itemRenderer property. How can i use it?
if i simply place a custom component in Repeater it doesn't work. I need to use
extensive binding
Moreover i need to change the background color of repeated custom component
e.g. White for each odd index and Grey for each Even index. How can is do it
while repeating
--
Regards,
Nadeem Manzoor