Also, you will find using Repeater much easier if you create a custom 
component, and repeat that.  Pass in a ref to the entire currentItem.  Then, in 
that component, you can code normally.  Also, you can dispatch an event, and 
the handler can access the entire dataProvider Item through the event.target 
proprety.

Below are some snippets:
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: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Ali 
Erken
Sent: Thursday, December 20, 2007 6:21 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Repeater and click

this is your code

click="openSite(newRepeater.currentItem.url)"

use this

click="openSite(event.currentTarget.getRepeaterItem ().url)"
On Dec 20, 2007 11:57 AM, Giro <[EMAIL PROTECTED]> wrote:
Hi,
 
I have this code
 
<mx:Repeater id="newRepeater" dataProvider="{newsRequest.lastResult.news.noti}" 
count="2">
       <mx:Label y="{20+(newRepeater.currentIndex*35)}" 
text="{newRepeater.currentItem.data}" color="0xcccccc"/>
            <mx:Label y="{32+(newRepeater.currentIndex*35)}" 
text="{newRepeater.currentItem.titol}" color="0xffffff" width="200" 
useHandCursor="true" click="openSite(newRepeater.currentItem.url)" 
buttonMode="true" mouseChildren="false"/>
            <mx:Label text="{newRepeater.currentItem.url}" />
</mx:Repeater>
 
All work okay, but when i press Label, error say:
 
Error: Repeater is not executing.
            at mx.core::Repeater/get currentItem()
            at vidi_new/___Label3_click()
 
 
How i can pass repeater data to a function?
 
 
Thk.
 
Giro.

 

Reply via email to