marcelfahle.com

Flex: Repeater Warnings while looping a HTTPService Result

During my current project, a Flex-based Content Management System, a came across an annoying warning, while using the result from an HTTPService call as a DataProvider for a Repeater Component.

What I did, was this:

Actionscript:

  1. <mx:Repeater id=“widgetListRepeater” dataProvider=“{widgetListServiceResult}”>
  2.    <mx:HBox width=“100%” height=“30″ verticalAlign=“middle”>
  3.       <mx:Button label=“{widgetListRepeater.currentItem.title.@value}”
  4.          click=“selectWidgetFromList(event.currentTarget.getRepeaterItem())”
  5.          styleName=“sectionButton” toggle=“false” height=“20″/>
  6.    </mx:HBox>
  7. </mx:Repeater>

Using this code I’ve always received the following warnings or each item in my dataprovider:

warning: unable to bind to property ‘title’ on class ‘XML’ (class is not an IEventDispatcher)
warning: unable to bind to property ‘value’ on class ‘XMLList’ (class is not an IEventDispatcher)

That’s because binding fails when using complex objects, like in this case currentItem of the Repeater Class.
Here the compiler doesn’t know what kind of datatype is looped in the Repeater Class and spits out a warning.

If you tell the compiler what he’s dealing with (casting, in programmer terms), you won’t get those warnings anymore.

Actionscript:

  1. <mx:Button label=“{XML(widgetListRepeater.currentItem).title.@value}”
  2.          click=“selectWidgetFromList(event.currentTarget.getRepeaterItem())”
  3.          styleName=“sectionButton” toggle=“false” height=“20″/>

For more fundamental information on that check the Adobe Flex 2 Help.

Comments:

  1. 1.

    Comment by abhishek:

    i’m showing images through httpService in repeater,

    but how can i get specific title of image after click on each image

  2. 2.

    Comment by Thomas:

    Thank you, I had almost lost hope to find a solution for this.