PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
child wont remove!!
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: child wont remove!!

  1. #1
    Junior Member
    Join Date
    May 2012

    child wont remove!!

    Ok, so I'm working on my very first as3 project, which is "Swat that Mosquito!"

    Basically, you hit "Play", and then a mosquito pops up in a random spot, you swat it with the fly swatter, and then another one reappears in a random spot.

    It works.

    But I am getting an error message which pops up when I swat a mosquito that appears in the top right corner.

    The top right corner is where my Play button is.

    Basically, the stage is 450x450. The start screen has the title, and takes up the entire stage except the top right corner (150x150), and the Play button goes in that spot, which is a .png file that simply says "Play!"

    I'm using hitTestObject instead of making that 150x150 .png file a button.

    Here is my error :

    "ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display:isplayObjectContainer/removeChild()
    at Function/Main/private:init/onClicked()[C:\Users\Me\Push\src\]"

    Here is my code for

    Actionscript Code:
        import flash.display.DisplayObjectContainer
        import flash.display.Sprite;
        import flash.ui.ContextMenu;
        import flash.display.Bitmap;
        import flash.display.SimpleButton;
        import flash.ui.Mouse;

        public class Main extends Sprite
            private var _game:Game;
            private var _menu:Bitmap = new;
            private var _swatter:Bitmap = new Assets.swat();
            private var _play:Bitmap = new;

            public function Main():void
                if (stage) init();
                else addEventListener(Event.ADDED_TO_STAGE, init);

            private function init(e:Event = null):void
                removeEventListener(Event.ADDED_TO_STAGE, init);
                stage.addEventListener(MouseEvent.MOUSE_MOVE, followSwatter);
                stage.addEventListener(MouseEvent.CLICK, onClicked);
                // entry point
                _play.x = 300;
                _play.y = 0;

                function followSwatter(e:Event):void

                function onClicked(evt:MouseEvent):void
                    if (_swatter.hitTestObject(_play))
                            _game = new Game();

    The question I have is why am I getting this error message during my game, when I've removeChild(_play); ?? When I swat a mosquito that appears where the Play graphic was, then I'm getting this.

    I'm getting no other error messages.

    I've exhausted myself on the net trying to find the answer, but have not been able to.
    I've been learning as3 for a week now, and have gotten this far, but keep hitting roadblocks that I eventually overcome. Hoping to get past this one soon.

    Thanks in advance for your help!

  2. #2
    Junior Member
    Join Date
    May 2012
    forget it, I figured out the solution to this.

    I forgot to remove the eventlisteners.


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