10 Replies Latest reply: Aug 12, 2012 12:18 PM by kglad RSS

    logical error

    thunderxlight11111 Community Member

      hi , how are you all ?

      i made game in 1 stage and it works  without errors but i have problem and here are some pictures then i will insert the code

       

       

      first there is 1 hero, and enemy .and 1 portal 

      when you touch the enemy it  will hit you and you gonna lose hp until death 

      like here

       

      [url=http://www.gulfup.com/show/X9e9628ecxzc4cw][img]http://im18.gulfup.com/2012-08-11/1344659217691.png[/img][/url]

       

       

      but there is a portal that you can use it for kill the enemy (the pat )

      here

      [url=http://www.gulfup.com/show/Xs6ria103sf4gw][img]http://im18.gulfup.com/2012-08-11/1344659218552.png[/img][/url]

       

      but the problem is : the enemy still hitting you ?? i dont know why ? i remove it and all its events

      but it,s still in the stage ??

       

      here is the code  of the MAIN class and its placein document file

      [url=http://www.gulfup.com/show/X9e9od31np68sgg][img]http://im17.gulfup.com/2012-08-11/1344660833131.png[/img][/url]

       

       

       

      package  {

      import flash.display.MovieClip;
      import flash.events.Event;


      public class MAIN extends MovieClip {
       
       
       
        public function MAIN() {
      addEventListener(Event.ADDED_TO_STAGE,onAddedToStage)  
      }


      public function onAddedToStage(event:Event):void
        {
      addEventListener(Event.ENTER_FRAME,onEnterFrame )
        addEventListener(Event.REMOVED_FROM_STAGE,onRemovedFromStage)
       
      }


      private function onRemovedFromStage(event:Event):void
        {
         removeEventListener(Event.ENTER_FRAME, onEnterFrame);
         removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
         removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
         trace("player removed");
        }
        public function onEnterFrame (event:Event)
        {
        
          if (hero.hitTestObject(bat1))
          {
           healthbar1.width -=1
          
          }
          if (healthbar1.width >=  80 && healthbar1.width <=  100 ){
           zelda1.gotoAndPlay(1)
          }
          if (healthbar1.width >=  60 && healthbar1.width <=  80){
           zelda1.gotoAndPlay(2)
          }
          if (healthbar1.width >=  40 && healthbar1.width <=  60){
           zelda1.gotoAndPlay(3)
          }
          if (healthbar1.width >=  20 && healthbar1.width <=  40){
           zelda1.gotoAndPlay(4)
          }
          if (healthbar1.width >=  0 && healthbar1.width <=  20){
           zelda1.gotoAndPlay(5)
          }
          if (hero.hitTestObject(portal2)){
           var map2:MAP2 = new MAP2
           addChild(map2)
           if(map1.stage){
           removeChild(map1)
           }
           }
           if (hero.hitTestObject(portal3)){
            var map4:BACKGROUND = new BACKGROUND
            if(bat1.stage){
           removeChild(bat1)
           bat1.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
           }
           }
        }


      }


      }

       

      and here is the bat class

       

      [url=http://www.gulfup.com/show/X34r84djied4w0s][img]http://im17.gulfup.com/2012-08-11/1344660833422.png[/img][/url]

       

       

       

      package  {

       

      import flash.display.MovieClip;

      import flash.events.Event;

       

      public class BAT1 extends MovieClip {

       

       

        public function BAT1() {

         addEventListener(Event.ADDED_TO_STAGE,onAddedToStage)

        }

        public function onAddedToStage(event:Event):void

        {

      addEventListener(Event.ENTER_FRAME,onEnterFrame )

        addEventListener(Event.REMOVED_FROM_STAGE,onRemovedFromStage)

       

      }

      private function onRemovedFromStage(event:Event):void

        {

         removeEventListener(Event.ENTER_FRAME, onEnterFrame);

         removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

         removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);

         trace("bat removed");

        }

        public function onEnterFrame (event:Event)

        {

        

        }

       

      }

       

      }

       

       

      thats all , also iam sure about that(the pat has removed because i saw this in trace message)

      bat1 removed

       

      here

      [url=http://www.gulfup.com/show/X9e9w762dv5cs4k][img]http://im18.gulfup.com/2012-08-11/1344661317721.png[/img][/url]

       

      thank you

       

      (yeah right the images dont work auto i dont know why , but you can just click it then it will work )

      thanks again)