Skip navigation
thunderxlight11111
Currently Being Moderated

logical error

Aug 10, 2012 10:11 PM

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)

 
Replies
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 10, 2012 11:00 PM   in reply to thunderxlight11111

    you don't have a trace("bat1 removed") in your code.

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 11, 2012 9:01 AM   in reply to thunderxlight11111

    removing an object from the display list does not stop your bat from existing and does not cause a bat hit test to be false.

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 12, 2012 9:58 AM   in reply to thunderxlight11111

    again, removing an object from the stage does not invalidate a hittest.  your bat object still exists and it still has x,y properties etc.

     

    you should probably clear your bat objects from memory and revamp your code so you're not testing objects that don't exist.  but a quick fix would be to use:

     

    if(hero.hitTestObject(bat1)&&bat1.stage)

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 12, 2012 10:11 AM   in reply to thunderxlight11111

    bat1.stage is null if bat1 is not in the display list so your if-statement resolves to false which is what you want.

     

    p.s.  please mark helpful/correct responses.

     
    |
    Mark as:
  • kglad
    72,260 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 12, 2012 12:18 PM   in reply to thunderxlight11111

    you're welcome.

     
    |
    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