Skip to main content

as3 quick q 77 Responses

Last post: 7 months, 1 week ago | Thread started: Mar 6, 08, 7:09 a.m.

RespondNew TopicDisable Images

  • scpgt

    How can I check to see if a particular instance name exists in my movie?

    Something like:

    if(box1.stage) {
    trace("exists");
    }

    but this particular example produces a compiler error if box1 doesn't exist.. Is there a better way to go about it?

    Mar 6, 08, 7:09 a.m. – Permalink
  • ephix

    if (this.parent.instancename) ?

    not really sure. just an idea.

    • you can just use the target button thingo, usually helpsephix
    + add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earMar 6, 08, 7:11 a.m. – Permalink
  • scpgt

    if only twere that easy..

    basically, there's several dozen dynamically generated movieclips and at a given point i need to check if a particular one exists on the stage..

    you'd think it'd be straightforward but apparently not..

    + add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earMar 6, 08, 7:14 a.m. – Permalink
  • forbes

    try
    if(box1 =! null) {
    trace("exists")'
    }

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earMar 6, 08, 7:19 a.m. – Permalink
  • scpgt

    ahhh... nice try.. but same error:

    1120: Access of undefined property box1.

    • only seems to affect AS3 as well..
      feckin thing
      scpgt
    + add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earMar 6, 08, 7:22 a.m. – Permalink
  • enjine

    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

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earMar 6, 08, 7:25 a.m. – Permalink
  • forbes

    var box1:BOX1 = new BOX1;
    addChild(box1);

    if (box1 =! null) {
    trace("exists");
    }

    ok ive defined the box1 and added it to the stage.. try that

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earMar 6, 08, 7:57 a.m. – Permalink
  • scpgt

    Ta for the tips... by process of looking at those and then experimenting a bit, best option turned out to be

    if (Boolean(getChildByName('box1… {
    trace("exists");
    } else {
    trace("doesn't!");
    }

    in case anyone's bothered :)

    Ta again!

    next note >add note

    You must be logged in to add a note. Login now or register for an account.

    Cancel
    Dog-earMar 6, 08, 8:18 a.m. – Permalink

Login or Register to respond to this

Skip to main content