A couple of weeks ago I made a post about using Repeaters in ViewStacks and I mentioned in the post I’d put together a class called DataStack that worked in the same way as a ViewStack but was driven by a dataProvider.

I then realized that using a Repeater inside a ViewStack would achieve the same result, but one thing I didn’t mention is that the DataStack re-uses its children like itemRenderers.

This means that if you only add one child to a DataStack, but supply a dataProvider with 1000 items, it will only create the one child and re-use it, unlike the Repeater and ViewStack combination which would create 1000 instances of the same child.

In addition recently I added a little more code so that you can add more than a single child to the DataStack and it will cycle through through them as you change the selectedIndex. So if you supply 2 different children and a dataProvider of 1000 items, it will reuse each child 500 times, the child at index 0 for all the data at the even indices, and the child at index 1 for all the data at the odd indices.

Due to the fact that DataStack isn’t a ViewStack (i.e. it extends Container not ViewStack), it won’t work with the Efflex viewStackEffects, and therefore I created a dataStack effect for Efflex and an example that extends it.

DataStack Example (right click for source).

The source for DataStack can be downloaded from our Google Code repository.

6 Responses to “DataStack”

  1. ThaStyle says:

    Once again thanks bro, and i noticed this part when i used flexspy, huge memory leaks with datarepeaters , i used it to display some blog stuff more then 5 was suckin the cpu..
    maybey a stupid question i had this with the datarepeater example too, when i have this one inside of another container with a effect it will trigger that one too, to solve this i manually added and removed the parent container effects. is there a better way ??

  2. Tink says:

    NOt sure I entirely understand the problem mate. Can you put a simple example together and put it online somewhere with view source enabled?

  3. ThaStyle says:

    Thanks for ur responce will put one as fast as i can, i think i already know where the problem is, this behaviour happens when i use the addChild method, what i am trying to is have a arraycollection with pages those pages have a template_id, on effect start remove all added stuff , on effect end build container , and add the classes ..
    when i call a function that removes or adds children inside that visible and effect done container it will replay the effect of its owner, i tried about all i could think off, inherit false, maybey is what i want not possible, and i do have to intialiase . all the containers before using any effect…
    i know a viewstack is a simple component, and that it just hides the other children, but i wanna use all ur nifty efflex stuff :) , i think the odd or even option is great this way i already have much more control can use one dummy for loading and one for actual stuff.. thanks again

  4. Hi Tink,
    I just read your post on DataStack and really liked it.

    We’re trying to add more links in our docs so that Flex developers are made aware of the great community content out there. I’m wondering whether you would consider adding a comment with a link to your post to the following page:

    * Your page:
    * Our page:

    Integration of customer-generated content is a key component in the success of the Flash platform documentation, so we really appreciate your contribution. FYI, here’s a blog post with a little more information about community help contributions: This post specifically mentions Adobe AIR but we’re doing this across the entire Adobe Flash Platform.

    Best regards
    Randy Nielsen
    Flex Documentation Manager
    Adobe Systems Incorporated

  5. Tink says:

    Well I’m flattered Randy.

    Consider it done (I feel a bit like a naughty spammer).

Leave a Reply