Skip to main content
Known Participant
August 13, 2014
Answered

ENTER_FRAME only executes once and not every frame

  • August 13, 2014
  • 2 replies
  • 1904 views

I have an ENTER_FRAME event which is supossed to run every frame but it just runs when an if statement is true and only once and not every single frame.

  1. public function update(e:Event):void
  2. {
  3.      if(canFire == true)
  4.      {
  5.           trace("The two statements are true");
  6.           var newBullet:Bullet;
  7.           newBullet = new Bullet(gadjet.x, gadjet.y);
  8.           bulletsArray.push(newBullet);
  9.           mcGameStage.addChild(newBullet);
  10.           newBullet.firebullet(); /* as long as this function is executing inside an enter frame's event
  11.           it will make the bullet look moving  */
  12.           // this is the Bullet's class firebullet() function
  13.           /*public function firebullet():void
  14.           {
  15.               x = x + 5; // this makes the bullet look moving when using an ENTER_FRAME event
  16.           }*/
  17.      }
  18. }


Entire class at pastebin:


[ActionScript 3] AvoiderGame4 - Pastebin.com



This topic has been closed for replies.
Correct answer kglad

the question is why my bullet just moves one time and not every frame, the unexpected is that the bullet doesn't look like it is moving. the enter_frame event is acting like a "only the first frame is listenig"


because that boolean is changing to false.

2 replies

Participating Frequently
August 13, 2014

Maybe I'm missing something, but how is "x = x + 5" working?  Shouldn't that equation be referring to something like "this.x" or "newBullet.x"?

Known Participant
August 13, 2014

the bullet's x position will increment 5 pixels every frame, it doesn't matter if you put this.x = x +5; or bullet.x = x + 5; the idea is to move it 5 pixels every frame, this way the bullet will look moving, but the enterframe's function only does it just one frame.

Participating Frequently
August 13, 2014

But you're adding a new bullet to the stage on each frame.  Is it supposed to be a machine gun?  :-)

kglad
Community Expert
Community Expert
August 13, 2014

is there a question?

is anything unexpected happening?

ie, your title is incorrect, but your first sentence may well be correct.