as3 quick q

Out of context: Reply #5

  • Started
  • Last post
  • 7 Responses
  • enjine0

    there is a method to do this on every subclass of DisplayObjectContainer (i.e. Sprite, MovieClip, ...). From the language reference:

    Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself. The search includes the entire display list including this DisplayObjectContainer instance. Grandchildren, great-grandchildren, and so on each return true.
    Parameters
    child:DisplayObject — The child object to test.

    Returns
    Boolean — true if the child object is a child of the DisplayObjectContainer or the container itself; otherwise false.

    Example
    The following example sets up a number of Sprite objects and adds some to the child list of others. (A Sprite object is a type of display object container.) The relationship between various objects is shown by calling the contains() method:

    import flash.display.Sprite;

    var sprite1:Sprite = new Sprite();
    var sprite2:Sprite = new Sprite();
    var sprite3:Sprite = new Sprite();
    var sprite4:Sprite = new Sprite();

    sprite1.addChild(sprite2);
    sprite2.addChild(sprite3);

    trace(sprite1.contains(sprite1... // true
    trace(sprite1.contains(sprite2... // true
    trace(sprite1.contains(sprite3... // true
    trace(sprite1.contains(sprite4... // false

View thread