views:

288

answers:

3

I have a HorizontalList in Flex that contains some data and an ItemRenderer representing a Page. After the last item (Page) in the list, I want to have a button - a Plus to create a new page.

What data can I look at to get the proper x,y position of the last ItemRenderer? I'm getting the position of

this.listContent.listItems[this.listContent.listItems.length-1];

which gives me the proper ItemRenderer instanceBut, but its x and y have been used for the index position of the ItemRenderer in the list. I want something in pixels relative to the list itself so I can position a button in UpdateDisplayList().

I'm interested in doing this via the UIComponent overrides instead of through the ItemRenderer itself because it doesn't seem like this is something that should live in the dataProvider... it would need to be some weird "lastItem" object that the ItemRenderer looked for and just seems odd. Plus, this is a fairly useful function for lists in general.

So, any ideas on this or other approaches?

A: 

It's hard to grab the actual itemRenderer for the last object because itemRenderer's are reused, so it's difficult to determine which one is always going to be the last. Checking for a "lastItem" variable in the data is probably the easiest way to implement this.

You could however, use the outerDocument property with an inline itemRenderer. This gives you access to the list.

<mx:List>
    <mx:itemRenderer>
        <mx:Component>
            <ns1:MyRenderer addLastButton="{outerDocument.myList.dataProvider.index == 10}"/>
        </mx:Component>
    </mx:itemRenderer>
...
</mx:List>
CookieOfFortune
Even if the itemRenderers are reused, the list would still know if a particular itemrenderer was showing the last item in the list. Still, the biggest problem from my point of view is that I can't get the local X,Y of ANY itemrenderers. If that was available, I feel like it would be mostly solved.
Ben Throop
I don't understand what you need the local X and Y for. You could in theory take take the dimensions of the list, divide by the items displayed, and interpolate the location of the last item.
CookieOfFortune
I suppose if I could get the dimensions of either the cells or the itemRenderer that would work. Good point!
Ben Throop
A: 

There's probably a right way of doing it using an itemEditor but I would try something like this:

  1. Add an extra null object to the list every time the data refreshed.
  2. Have an itemRenderer that overrides the set data as shown here which checks if the object is null and if it is, set a bindable boolean isAddable to true.
  3. This boolean controls visibility and includeInLayout propertys of a textInput, label, and button.
  4. Have the button dispatch an event when click which adds the new item to the list with some validation.
Brandon
A: 

I think you can try to add one more item to dataProvider (with data e.g. "button") and create custom itemRenderer for the list which will change its appearance to Button (can be implemented with states) if data == "button"

Peet