Skip navigation
Currently Being Moderated

Knowing when a child has been added

Nov 14, 2007 10:52 AM

Hi there,

I'm adding a child via mxml e.g AddChild. I'm wondering how I go about knowing when the child has been added. I want to call a function when it has. I saw the 'added' method but I'm not quite sure how it works. Do I need to create a listener?

Thanks.

Novian
 
Replies
  • Currently Being Moderated
    Nov 15, 2007 12:10 PM   in reply to Novian
    addChild is immediate. You can call functions anytime.

    In fact, you can call functions on the child before you call addChild. The instance is created when you do new.

    Tracy
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 15, 2007 2:38 PM   in reply to Novian
    There are the following events you could listen to:

    added
    Dispatched when a display object is added to the display list.

    addedToStage
    Dispatched when a display object is added to the on stage display list, either directly or through the addition of a sub tree in which the display object is contained.
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 16, 2007 2:32 PM   in reply to Novian
    var numberOfChildren:uint = componentName.numChildren;
    or
    componentName.getChildIndex(child'sName); //If this returns -1, the child is not there.
    or
    if(componentName.getChildByName(child'sName) != null)...
    or
    if(componentName.getChildren().toString().indexOf(child'sName) != -1)...

    If you want to know for sure if the child is really in there! After checking, if true, then call a function, else, return.
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 17, 2007 6:54 AM   in reply to Novian
    Hi,

    If you want to know when a content child has been added, listen for;

    ChildExistenceChangedEvent.CHILD_ADDED

    or

    ChildExistenceChangedEvent.CHILD_REMOVED

    The event.releatedObject will contain the instance that fired the event. The currentTarget is the parent that just added the new child.

    The added event gets dispatched by the player and gets called for 'every' display list addition to the component, chrome and content children.

    Peace,
    Mike
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)