Hi Ward,

On Fri, Nov 28, 2008 at 8:27 AM, Ward Loockx <[EMAIL PROTECTED]> wrote:

> [...] So when data changed in the search the arraycollection dispatches an
> event so that my carousel knows that it needs to update.

You need, when you get your new data provider, to subscribe to its (the
collection's) CollectionEvent.COLLECTION_CHANGE event.  That way you can run
your update logic not only when you get it but also when it updates in any
other way.

...

This is, as an example, a setter on one big carousel component that i've been
working on which not only takes collections but other types of providers as
well.

public function set dataProvider(value:Object):void
{

    if (_dataProvider == value)
        return;

    if (_dataProvider)
    {
        _dataProvider.removeEventListener(
            CollectionEvent.COLLECTION_CHANGE,
            dataProvider_collectionChangeHandler,
            false
        );
    }

    _dataProvider
        = (value is Array)      ? new ArrayCollection(value as Array)
        : (value is XMLList)    ? new XMLListCollection(value as XMLList)
        : (value is IList)      ? IList(value)
        : new ArrayCollection()
        ;

    _dataProvider.addEventListener(
        CollectionEvent.COLLECTION_CHANGE,
        dataProvider_collectionChangeHandler,
        false,
        0,
        true
    );

    dataProviderChanged = true;

    invalidateProperties();
    invalidateDisplayList();

    dispatchEvent(new Event("dataProviderChanged"));

}


.... the handler for that change can then just be,

private function dataProvider_collectionChangeHandler(
                                                event:CollectionEvent):void
{
    dataProviderChanged = true;
    invalidateProperties();
}


... etc.

you can browse the complete code from here, if you want to,
http://code.google.com/p/rojored/source/browse/trunk/src/com/rojored/view/controls/carouselClasses/BaseCarousel.as

and you can see it running here, at the bottom, if you click "bookmarks" you
can check and uncheck "twitter", "last.fm", etc. and you can see the carousel
update.

http://rojored.com

another usage example of that same component.
http://rojored.googlecode.com/svn/trunk/docs/examples/carousel/c01/bin/Main.swf

both are "view source" enabled.

HTH,
G.


-- 
gabriel montagné láscaris comneno
http://rojored.com
t/506.8367.6794

Reply via email to