[flexcoders] Re: Getting Index of item clicked in repeater

2007-10-04 Thread droponrcll
--- In flexcoders@yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote:

 I have not done this recently that I can recall, but here are some
 suggestions.
 
 * If your data Provider is a collection, you can use
 getRepeaterItem() with collection.getItemIndex()
 * Look at the repeaterIndex and instanceIndex properties of
 UIComponent.  Remember the click handler event object provides the
 target and currentTarget properties to reference the repeated UIObject
 * Use a custom component to repeat and set an index property on it
 using repeater.currentIndex

I've already tried suggestion 3, and the index does not seem to bear 
any relation to what was clicked.  For instance, I can click 3 
different things and get back 2, and several other things and get back 
4, but never do I get anything other than 2 or 4.  I have not even been 
able to get the click event to fire on the repeater itself, so it seems 
that option 3 is most promising.  However, the index valued that is 
stored isn't correct.

using

mx:Repeater id=allBlocks dataProvider={contentSource.children()}
ac:ContentBlock contentItem={allBlocks.currentItem} 
rIndex={allBlocks.currentIndex} /
/mx:Repeater

Thanks;

Amy



RE: [flexcoders] Re: Getting Index of item clicked in repeater

2007-10-04 Thread Tracy Spratt
Here is an example using getRepeaterItem() and getItemIndex()
Tracy

?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; 
layout=absolute 
creationComplete=initApp()
mx:Script![CDATA[
  import mx.collections.ArrayCollection;
  import mx.controls.Alert;
  
  [Bindable]private var _acDP:ArrayCollection;

public function initApp():void
{
  var oItem:Object;
  _acDP = new ArrayCollection();
  oItem = {Album:The Lost Chord, Artist:The Moody Blues, 
Price:15.99, x:30, y:30 };
  _acDP.addItem(oItem);
  oItem = {Album:Meddle, Artist:Pink Floyd, Price:17.99, x:170, 
y:60 };
  _acDP.addItem(oItem);
  oItem = {Album:Trespass, Artist:Genesis, Price:18.99, x:220, 
y:100 };
  _acDP.addItem(oItem); 
  oItem = {Album:In the Wake of Poseidon, Artist:King Crimson, 
Price:18.99, x:170, y:140 };
  _acDP.addItem(oItem);
  oItem = {Album:Journey to the Center of the Earth, Artist:rick 
Wakeman, Price:18.99, x:30, y:110 };
  _acDP.addItem(oItem);   
 
}//initApp

private function onClickItem(oEvent:Event):void
{
  var oItem:Object = oEvent.currentTarget.getRepeaterItem();
  var iIndex:int = _acDP.getItemIndex(oItem);
  lblIndex.text = String(iIndex);
}//onClickItem


]]/mx:Script
  mx:Label text=Clicked Item Index: x=0 y=0 
  fontSize=14  fontWeight=bold /
  mx:Label id=lblIndex x=160 y=0 
  fontSize=14 fontWeight=bold color=red /
  mx:Repeater id=rp dataProvider={_acDP} 
mx:LinkButton label={rp.currentItem.Album} click=onClickItem(event)
x={rp.currentItem.x} y={rp.currentItem.y}
 /
  /mx:Repeater
/mx:Application


From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of 
droponrcll
Sent: Thursday, October 04, 2007 11:58 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Getting Index of item clicked in repeater

--- In flexcoders@yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote:

 I have not done this recently that I can recall, but here are some
 suggestions.
 
 * If your data Provider is a collection, you can use
 getRepeaterItem() with collection.getItemIndex()
 * Look at the repeaterIndex and instanceIndex properties of
 UIComponent. Remember the click handler event object provides the
 target and currentTarget properties to reference the repeated UIObject
 * Use a custom component to repeat and set an index property on it
 using repeater.currentIndex

I've already tried suggestion 3, and the index does not seem to bear 
any relation to what was clicked. For instance, I can click 3 
different things and get back 2, and several other things and get back 
4, but never do I get anything other than 2 or 4. I have not even been 
able to get the click event to fire on the repeater itself, so it seems 
that option 3 is most promising. However, the index valued that is 
stored isn't correct.

using

mx:Repeater id=allBlocks dataProvider={contentSource.children()}
ac:ContentBlock contentItem={allBlocks.currentItem} 
rIndex={allBlocks.currentIndex} /
/mx:Repeater

Thanks;

Amy
 



[flexcoders] Re: Getting Index of item clicked in repeater

2007-10-04 Thread droponrcll
--- In flexcoders@yahoogroups.com, Tracy Spratt [EMAIL PROTECTED] wrote:

 Here is an example using getRepeaterItem() and getItemIndex()
 Tracy
 
 ?xml version=1.0 encoding=utf-8?
 mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; 
 layout=absolute 
 creationComplete=initApp()
 mx:Script![CDATA[
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   
   [Bindable]private var _acDP:ArrayCollection;
   
   public function initApp():void
   {
 var oItem:Object;
 _acDP = new ArrayCollection();
 oItem = {Album:The Lost Chord, Artist:The Moody Blues, 
Price:15.99, x:30, y:30 };
 _acDP.addItem(oItem);
 oItem = {Album:Meddle, Artist:Pink Floyd, 
Price:17.99, x:170, y:60 };
 _acDP.addItem(oItem);
 oItem = {Album:Trespass, Artist:Genesis, Price:18.99, 
x:220, y:100 };
 _acDP.addItem(oItem); 
 oItem = {Album:In the Wake of Poseidon, Artist:King 
Crimson, Price:18.99, x:170, y:140 };
 _acDP.addItem(oItem);
 oItem = {Album:Journey to the Center of the Earth, 
Artist:rick Wakeman, Price:18.99, x:30, y:110 };
 _acDP.addItem(oItem);   
  
   }//initApp
   
   private function onClickItem(oEvent:Event):void
   {
 var oItem:Object = oEvent.currentTarget.getRepeaterItem();
 var iIndex:int = _acDP.getItemIndex(oItem);
 lblIndex.text = String(iIndex);
   }//onClickItem
 
   
 ]]/mx:Script
   mx:Label text=Clicked Item Index: x=0 y=0 
   fontSize=14  fontWeight=bold /
   mx:Label id=lblIndex x=160 y=0 
   fontSize=14 fontWeight=bold color=red /
   mx:Repeater id=rp dataProvider={_acDP} 
 mx:LinkButton label={rp.currentItem.Album} click=onClickItem
(event)
 x={rp.currentItem.x} y={rp.currentItem.y}
  /
   /mx:Repeater
 /mx:Application

Thanks.  I'll see if I can get this to translate to my code.