Skip navigation
Currently Being Moderated

Error #2025

Apr 12, 2012 12:20 PM

hi .. how are you guysuld

 

iam making a game  and its all good except the last thing

 

if i wanna finish the game the dragon and health bar and fire should stop attacking and should removing

here this is the code

the problem from the red lines only

 

package

 

{

 

 

 

    import flash.display.MovieClip;

 

    import flash.events.KeyboardEvent;

 

    import flash.ui.Keyboard;

 

    import flash.events.Event;

 

    import flash.events.MouseEvent;

 

public class game extends MovieClip {

 

  

public  var firetalent:uint;

    public var vx:int;

  public var points:uint

 

  public function game (){

 

        run();

       

        removeChild(b1)

        removeChild(b2)

        removeChild(c1)

        removeChild(c2)

        removeChild(d1)

        removeChild(d2)

        removeChild(e1)

        removeChild(e2)

        dragon.gotoAndStop(1)

        NUMBERS.visible = false;

        NUMBERS.stop();

        zelda.stop()

        a1.visible = false

            a2.visible = false

        fire.visible = false

        b1.visible = false

            b2.visible = false

           

            c1.visible = false

            c2.visible = false

           

            d1.visible = false

            d2.visible = false

           

            e1.visible = false

            e2.visible = false

           

           

            a1.addEventListener(MouseEvent.CLICK, onmouseclicka1);

            a2.addEventListener(MouseEvent.CLICK, onmouseclicka2);

           

            b1.addEventListener(MouseEvent.CLICK, onmouseclickb1);

            b2.addEventListener(MouseEvent.CLICK, onmouseclickb2);

           

            c1.addEventListener(MouseEvent.CLICK, onmouseclickc1);

                c2.addEventListener(MouseEvent.CLICK, onmouseclickc2);

             

                d1.addEventListener(MouseEvent.CLICK, onmouseclickd1);

                d2.addEventListener(MouseEvent.CLICK, onmouseclickd2);

               

                e1.addEventListener(MouseEvent.CLICK, onmouseclicke1);

                e2.addEventListener(MouseEvent.CLICK, onmouseclicke2);

               

           

           

 

        hero.gotoAndStop(3);

 

      

 

    }

 

  

 

    public function run(){

 

      

 

        addEventListener(Event.ENTER_FRAME, onEnterFrame);

 

        stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);

 

        stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

       

spell1.addEventListener(MouseEvent.CLICK,onspell)

    firstaid.addEventListener(MouseEvent.CLICK,firstaid1)  

 

    }

 

  

 

  

 

        function onEnterFrame(event:Event):void

 

        {

           

            if(dragonhealthbar.width == 0 ){

            stage.removeChild(fire)

            stage.removeChild(dragonhealthbar)

            stage.removeChild(dragon)

           

       

        }

           

            if(monster.hitTestObject(wall))

              {

                  dragonhealthbar.width -=3

                  dragon.gotoAndStop(2);

                 

              }

            if(!monster.hitTestObject(wall))

              {

                 dragon.gotoAndStop(1)

               

              }

           

           

            if(firetalent >= 1){

           

           

            monster.visible = true;

            monster.x -= 10;

            monster.y += 10;

           

            if(monster.y >=400){

        monster.x = 247

        monster.y =0;

        firetalent--

        monster.visible = false;

       

            }

            }

           

        if(points >= 2){

        spell1.alpha = 1;

        spell1.enabled = true;

        }

        else

        {

            spell1.alpha = .3;

            spell1.enabled = false;

        }

       

       

        if(points >= 3){

        firstaid.alpha = 1;

        firstaid.enabled = true;

        }

        else

        {

            firstaid.alpha = .3;

            firstaid.enabled = false;

        }

           

            score.text = String(points);

   

   

    if (score.text < "0" ){

score.text = "0";}

 

if(healthbar.width >80){

zelda.gotoAndStop(1)

}

if(healthbar.width >60 &&healthbar.width <80 ){

zelda.gotoAndStop(2)

}

if(healthbar.width >40 &&healthbar.width <60 ){

zelda.gotoAndStop(3)

}

if(healthbar.width >20 &&healthbar.width <40 ){

zelda.gotoAndStop(4)

 

}

if(healthbar.width >0 &&healthbar.width <20 ){

zelda.gotoAndStop(5)

 

}

 

if(dragon.hitTestObject(hero)){

     stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);

   

    NUMBERS.visible = true;

    a1.visible = true;

            a2.visible = true;

        fire.visible = true

 

fire.x += 20

fire.y +=18

fire.width +=3

fire.height +=3

 

if(fire.y >= 400){

    fire.width = 31;

    fire.height = 29

 

    fire.x = 94

    fire.y =239}

   

   

   

    if(hero.hitTestObject(fire)){

 

           hero.gotoAndStop(5);

           healthbar.width -= .5;

         

           }

           if(!hero.hitTestObject(fire)){

 

           hero.gotoAndStop(3);

         

           }

         }

}

   

 

           public function onmouseclicka1 (event:MouseEvent):void{

             points++

             removeChild(a1)

               removeChild(a2)

               addChild(b1)

                addChild(b2)

               b1.visible = true

                b2.visible = true

                NUMBERS.gotoAndStop(2)

              

              

           }

 

      

           public function onmouseclicka2 (event:MouseEvent):void{

               points +=2;

                addChild(b1)

                addChild(b2)

                removeChild(a1)

                removeChild(a2)

                 b1.visible = true

                b2.visible = true

                NUMBERS.gotoAndStop(2)

              

           }

 

 

 

           public function onmouseclickb1 (event:MouseEvent):void{

               points ++;

               addChild(c1)

                addChild(c2)

               removeChild(b1)

                removeChild(b2)

                 c1.visible = true

                c2.visible = true

                NUMBERS.gotoAndStop(3)

           }

          

           public function onmouseclickb2 (event:MouseEvent):void{

               

                removeChild(b1)

                removeChild(b2)

                addChild(c1)

                addChild(c2)

                c1.visible = true

                c2.visible = true

                NUMBERS.gotoAndStop(3)

                points +=2;

           }

          

          

           public function onmouseclickc1 (event:MouseEvent):void{

               points +=1;

               addChild(d1)

                addChild(d2)

               removeChild(c1)

              

                removeChild(c2)

                 d1.visible = true

                d2.visible = true

                NUMBERS.gotoAndStop(4)

           }

          

           public function onmouseclickc2 (event:MouseEvent):void{

              points +=2;

              addChild(d1)

                addChild(d2)

              removeChild(c1)

                removeChild(c2)

                 d1.visible = true

                d2.visible = true

                NUMBERS.gotoAndStop(4)

           }

          

           public function onmouseclickd1 (event:MouseEvent):void{

                points +=1

               addChild(e1)

                addChild(e2)

               removeChild(d1)

                removeChild(d2)

                 e1.visible = true

                e2.visible = true

                NUMBERS.gotoAndStop(5)

           }

          

           public function onmouseclickd2 (event:MouseEvent):void{

               points +=2;

                addChild(e1)

                addChild(e2)

                removeChild(d1)

                removeChild(d2)

                 e1.visible = true

                e2.visible = true

                NUMBERS.gotoAndStop(5)

               

           }

           public function onmouseclicke1 (event:MouseEvent):void{

               points +=1;

               removeChild(e1)

                removeChild(e2)

                removeChild(NUMBERS)      

                }

          

           public function onmouseclicke2 (event:MouseEvent):void{

               points +=2;

                               removeChild(NUMBERS)      

 

               removeChild(e1)

                removeChild(e2)

           }

 

          

          

          

  

 

public function onKeyDown(event:KeyboardEvent):void{

 

if (event.keyCode == Keyboard.LEFT){

 

 

 

hero.gotoAndStop(1);

 

hero.x -=3

 

 

 

 

}

 

if (event.keyCode == Keyboard.RIGHT){

 

 

hero.gotoAndStop(2);

 

hero.x +=3

 

}

 

}

 

public function onKeyUp (event:KeyboardEvent):void{

 

  

if(event.keyCode == Keyboard.LEFT){

    hero.gotoAndStop(3)

}

else if (event.keyCode == Keyboard.RIGHT){

    hero.gotoAndStop(4)

}

 

 

}

 

public function onspell (event:MouseEvent):void {

    if(points >=2){

    firetalent +=1

    points -=2

    }

   

}

public function firstaid1 (event:MouseEvent):void {

    if(points >=3){

   

    healthbar.width +=90

    if(healthbar.width >=90){

    healthbar.width =90

    }

    points -= 3;

    }

}

 

 

}

}

 

here the full eror

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

    at flash.display::DisplayObjectContainer/removeChild()

    at game/onEnterFrame()

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

 

and i guess (not sure) that because the event moves 30 times in sec and when it try to find the if it cant find or child or anything like that

 

thank you

 
Replies
  • Currently Being Moderated
    Apr 12, 2012 12:41 PM   in reply to thunderxlight11111

    The error and what you describe sounds like you might be trying to remove something that has already been removed based on what you describe.  If you have already removed the objects, but have not removed the ENTER_FRAME listener that causes it to happen, that could be the source of the problem.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 12, 2012 1:30 PM   in reply to thunderxlight11111

    Try what I said and see if it helps...

     

            function onEnterFrame(event:Event):void

     

            {

                

               if(dragonhealthbar.width == 0 ){

                stage.removeChild(fire)

                stage.removeChild(dragonhealthbar)

                stage.removeChild(dragon)  

                removeEventListener(Event.ENTER_FRAME, onEnterFrame);     

           

                }

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 12, 2012 5:41 PM   in reply to thunderxlight11111

    You should put traces in to see where you might be having these problems.  I just noticed at the start of yiouyr class you have these lines...

     

            removeChild(b1) 

            removeChild(b2)

            removeChild(c1)

            removeChild(c2)

            removeChild(d1)

            removeChild(d2)

            removeChild(e1)

            removeChild(e2)

     

    How certain are you that by the time this code is executed those objects exist?  You should try putting a trace before them and after each one to see if that is where the error is coming from.

     

    If you have any more remoiveChild calls, you should test there similarly

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points