A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] ERROR: DisplayObject must be a child of the caller

  1. #1
    Member
    Join Date
    Jul 2001
    Posts
    72

    resolved [RESOLVED] ERROR: DisplayObject must be a child of the caller

    Please help me...


    I created this simple hitTest on the first frame of my main timeline.


    var flash_1g:Flash_1g = new Flash_1g();

    stage.addEventListener(Event.ENTER_FRAME, hitTest)
    fuction hitTest(yourEvent:Event):void{

    if (note1.hitTestObject(key_1g)) {
    addChild(new Flash_1g);
    }
    };


    So I have a movieClip (note1) colliding with another movieClip (key_1g) and when collision happens it, a third movieClip from my library (class: Flash_1g) is placed on stage with the addChild cmd. Works fine.

    Later I want to remove this movieClip (Flash_1g) again.

    But when I try to use

    removeChild(flash_1g);

    which is the variable name for Flash_1g defined at the beginning.

    I get this error:

    "The supplied DisplayObject must be a child of the caller."



    How should I go about this?
    Last edited by Zeicon; 05-06-2012 at 04:44 PM.

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    make sure you are calling removeChild on the actual parent of flash_1g.
    For example if you add a child to a display object called myParent with:
    myParent.addChild(myChild);
    you can only remove it from that object:
    myParent.removeChild(myChild);

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You never added flash_1g. Instead, you created a new instance of Flash_1g and added that.

  4. #4
    Member
    Join Date
    Jul 2001
    Posts
    72
    yea, that's what happened.


    Thanks guys. This is resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center