I'm trying to add the listener to the REPEATED components not the 
REPEATER component. In this case I'm repeating a checkbox, that's 
what I need the listener for, each of them.

Thanks



--- In [email protected], "Gordon Smith" <[EMAIL PROTECTED]> 
wrote:
>
> > I don't think you can add a listener to Repeater. 
>  
> Yes you can; a Repeater dispatches 'repeatStart', 'repeat', and
> 'repeatEnd' events. But that's different from listening to events
> disaptched by the repeated components.
>  
> - Gordon
> 
> ________________________________
> 
> From: [email protected] 
[mailto:[EMAIL PROTECTED] On
> Behalf Of Tracy Spratt
> Sent: Tuesday, September 04, 2007 1:53 PM
> To: [email protected]
> Subject: RE: [flexcoders] How do I addEventListener to a repeated
> component.
> 
> 
> 
> I don't think you can add a listener to Repeater. That does not 
really
> make sense anyway, as repeater has no UI of its own, it only adds
> children to a container. The listeners need to be on the repeated
> components (checkBoxes). You can do this in mxml fairly easily, 
but you
> have to use getRepeaterItem() to get a reference to the item.
> currentItem will not work in an event handler declaration.
> 
> When working with Repeater, I suggest using a custom component. It
> simplifies many things. 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: [email protected] <mailto:flexcoders%
40yahoogroups.com>
> [mailto:[email protected] <mailto:flexcoders%
40yahoogroups.com>
> ] On Behalf Of Mark
> Sent: Tuesday, September 04, 2007 1:20 PM
> To: [email protected] <mailto:flexcoders%
40yahoogroups.com> 
> Subject: [flexcoders] How do I addEventListener to a repeated 
component.
> 
> My code is below.  I'm trying to put an eventListener on the 
CheckBoxes
> (repSL) that are being created with the Repeater.  I get this 
error:
> TypeError: Error #1006: addEventListener is not a function
> this works fine with everything but for the repeated checkboxes.  
Is
> there a differnt way to assign this?
> Thanks
>  
> <?xml version="1.0"?>
> <!-- repeater\myComponents\CustButton.mxml -->
> <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml
> <http://www.adobe.com/2006/mxml> " initialize="createListener()"
> paddingLeft="5" paddingTop="5" paddingRight="5" paddingBottom="5">
>   <mx:Script>
>     <![CDATA[
>   import mx.events.ListEvent;
>   import mx.core.Application;
>   import mx.events.ListEvent;
>   import flash.events.Event;
>   
>       [Bindable]
>       public var dpSL:Array=["All","AABS","CBS","TAS","TAX"];
>       [Bindable]
>       public var dpDI:Array=["Desktop Impact","Network 
Impact","Local
> Help Desk Impact","Other"];
>       [Bindable]
>       public var dpDO:Array=["All","Global IT","Americas","Central
> Europe","Continental Western Europe","NEMIA","Far
> East","Oceania","Japan"];
>       //
>       [Bindable]
>       public var dpApp:Array=[{label:"Select One",data:"All"},
>              {label:"App Infrastructure",data:"Application
> Infrastructure"},
>              {label:"Client Conn",data:"Client Connectivity"},
>              {label:"Doc Mgmt",data:"Document Management"},
>              {label:"Finance",data:"Finance"},
>              {label:"People",data:"People"},
>              {label:"Q&RM",data:"Q&RM"},
>              {label:"SL App Services",data:"Service Line 
Application
> Services"}
>              ];
>       [Bindable]
>       public var dpInfra:Array=[{label:"Select One",data:"All"},
>              {label:"Content Mgmt",data:"Content Management"},
>              {label:"Data Networking",data:"Data Networking"},
>              {label:"Desktop",data:"Desktop"},
>              {label:"Identity & Access Mgmt",data:"Identity and 
Access
> Management"},
>              {label:"Info Security",data:"Information Security"},
>              {label:"Msg and Collab",data:"Messaging and
> Collaboration"},
>              {label:"Mobility and Comm",data:"Mobility and
> Communications"}];
>       //
>       //
>   private function createListener():void {
>        repSL.addEventListener(MouseEvent.CLICK, myClickHandler, 
false,
> 0);
>        infraRB.addEventListener(MouseEvent.CLICK, 
myClickHandler,false,
> 0);
>        appCB.addEventListener(ListEvent.CHANGE,setFilter,false,0);
>        infraCB.addEventListener
(ListEvent.CHANGE,setFilter,false,0);
>   }
>   private function myClickHandler(e:MouseEvent):void {
>    trace(e.target.label);
>    var myTarget:String = e.target.label;
>    if (myTarget == "Application") {
>     appCB.enabled = true;
>     infraCB.enabled = false;
>     infraCB.selectedIndex = 0;
>    } else {
>     infraCB.enabled = true;
>     appCB.enabled = false;
>     appCB.selectedIndex = 0;
>    }
>   }
> ...
> <mx:Tile direction="horizontal" borderStyle="none" width="100%"
> horizontalGap="5" verticalGap="5"
>   paddingTop="5" paddingBottom="5">
>   <mx:Repeater id="rSL" dataProvider="{myACSL}">
>     <mx:CheckBox id="repSL" label="{rSL.currentItem}" 
selected="true"
>  
> change="Application.application.getRegions
(event);Application.applicatio
> n.refresh();" />
>   </mx:Repeater>
> </mx:Tile>
>


Reply via email to