2 Replies Latest reply on May 31, 2007 10:49 AM by Graeme Harker

    Can I refernce a Repeater with "this"?

    Graeme Harker Level 1
      Why does this work ....

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      backgroundColor="white" backgroundImage="">

      <mx:ArrayCollection id="dataSource" >
      <mx:String>Mary</mx:String>
      <mx:String>Alice</mx:String>
      <mx:String>Fred</mx:String>
      </mx:ArrayCollection>

      <mx:Repeater id="myRepeater" dataProvider="{this.dataSource}">
      <mx:Button label="{String(myRepeater.currentItem)}" />
      </mx:Repeater>

      </mx:Application>

      but this doesn't (the only change is that I added "this." in the reference to the repeater)

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      backgroundColor="white" backgroundImage="">

      <mx:ArrayCollection id="dataSource" >
      <mx:String>Mary</mx:String>
      <mx:String>Alice</mx:String>
      <mx:String>Fred</mx:String>
      </mx:ArrayCollection>

      <mx:Repeater id="myRepeater" dataProvider="{this.dataSource}">
      <mx:Button label="{String(this.myRepeater.currentItem)}" />
      </mx:Repeater>

      </mx:Application>
        • 1. Re: Can I refernce a Repeater with &quot;this&quot;?
          upshotvideo Level 1
          Because the Repeater is not a child of the Button.
          • 2. Re: Can I refernce a Repeater with &quot;this&quot;?
            Graeme Harker Level 1
            That's not the reason as the keyword "this" has no relationship whatsoever to the display list hierarchy.

            In Flex, the keyword "this" in an MXML file refers to the component instance that the MXML "object factory" file describes. So in this case "this" refers to an instance of a component defined by the MXML file and derived from the Application component). All the components declared in an MXML file, irrespective of the level of nesting, are all instantiated and defined as properties of the parent component. It's one flat namespace. So in my example "this.myRepeater" should always refer to the Repeater instance. The only exception to that rule that I know is item renderers and the <mx:Component> "component".

            I suspect that the body of a Repeater (like the body of an in-line item renderer) is a separate scope. The documentation doesn't say that tho'.