PDA

View Full Version : How can a component detect it's own index change?



xbrotherx
January 6th, 2009, 05:29 PM
If I have a component (A) based on a Canvas container, and it's index changes due to another component (B) being added to the same parent container as component "A", how can I have component "A" listen for it's own change in index?

I have tried listening for the IndexChangedEvent.CHANGE but to no avail.

senocular
January 6th, 2009, 05:58 PM
There is no event directly related to that specific action. However, if you know this change in index will be the result of a new object being added to the same parent, you can add an Event.ADDED listener to the parent and check for a change in index there. Note, however, that in the added event the index of your desired display object will have already changed to its new index. You might want to save the previous index to a variable or maybe go under the assumption that if the newly added clip is at an index below the desired, it would have affected and changed the desired clip's index.

xbrotherx
January 7th, 2009, 09:58 AM
Thanks Senocular, for the clarification that there isn't an event directly tied to index changes. I was racking my brain trying figure out how I could use that IndexChangedEvent.CHANGE event. I wound up having the parent container listen for the ChildExistenceChangedEvent.CHILD_ADD event because the Event.ADDED would list all child components within the child component being added and that was too much clutter for me to sort through.

Thanks again for you help!!