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
    Posts
    3

    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\Main.as:55]"

    Here is my code for Main.as

    Actionscript Code:
    package
    {
        import flash.display.DisplayObjectContainer
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.ui.ContextMenu;
        import flash.display.Bitmap;
        import flash.display.SimpleButton;
        import flash.ui.Mouse;
        Mouse.hide();
       

        [Frame(factoryClass="Preloader")]
        public class Main extends Sprite
        {
            private var _game:Game;
            private var _menu:Bitmap = new Assets.menu;
            private var _swatter:Bitmap = new Assets.swat();
            private var _play:Bitmap = new Assets.play;
           
           
           

            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
               
                addChild(_menu);
                addChild(_play);
                _play.x = 300;
                _play.y = 0;
               

                function followSwatter(e:Event):void
                {
                    addChild(_swatter);
                    _swatter.x=mouseX;
                    _swatter.y=mouseY;
                }

                function onClicked(evt:MouseEvent):void
                {
                    if (_swatter.hitTestObject(_play))
                        {
                            removeChild(_play);
                            removeChild(_menu);
                            removeChild(_swatter);
                            _game = new Game();
                            addChild(_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
    Posts
    3
    forget it, I figured out the solution to this.

    I forgot to remove the eventlisteners.

    :P

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