Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ENTER_FRAME only executes once and not every frame

Community Beginner ,
Aug 13, 2014 Aug 13, 2014

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



TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 13, 2014 Aug 13, 2014

because that boolean is changing to false.

Translate
Community Expert ,
Aug 13, 2014 Aug 13, 2014

is there a question?

is anything unexpected happening?

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 13, 2014 Aug 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"?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 13, 2014 Aug 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 13, 2014 Aug 13, 2014

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 13, 2014 Aug 13, 2014

kinda like, i need to shut a bullet every time I press the space bar, i.e when the if stament is true

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2014 Aug 13, 2014

again,

is there a question?

is anything unexpected happening?

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 13, 2014 Aug 13, 2014

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"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2014 Aug 13, 2014

because that boolean is changing to false.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 13, 2014 Aug 13, 2014

so if I put a while instead of an if and keep my space bar pressed it will be moving?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2014 Aug 13, 2014

no.  you can't use for-loops, while-loops or do-loops to animate objects.  those loops execute from beginning to end before anything is updated on-stage.

you should check why your boolean is changing, if that's unexpected.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 13, 2014 Aug 13, 2014

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 13, 2014 Aug 13, 2014

you're welcome.

p.s when using the adobe forums, please mark helpful/correct responses, if there are any.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 28, 2014 Aug 28, 2014

I think you jumped the gun asking him to mark an answer as correct, since no one has as yet given him a correct answer. This is one reason I never ask people to do this, even if I am sure I have provided them with the correct answer.

It seems to me that the OP is expecting for the fireBullet() function to continue to fire on ENTER_FRAME. Even if the Boolean changes, this will not happen. The reason behind that is that fireBullet() is only being called on the particular bullet that was just created, not on all bullets that have ever been created. So the function needs to either loop through all of the bullets in the Array or fireBullet() needs to be written in such a way that it's self-sustaining (does its own ENTER_FRAME checking, which opens you up to the possibility of a memory leak due to the nature of that particular event).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 22, 2014 Sep 22, 2014
LATEST

I dont actually know how to mark it as helpfull because I dont see that option anywhere

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 13, 2014 Aug 13, 2014

I can understand that a new bullet needs to be drawn each time you press the space bar, but it looks like you are drawing a new bullet on every frame.  Are you setting "canFire" to 'false' anywhere in your code? Because, if you are, then I agree with KGLAD that your issue lies there.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 27, 2014 Aug 27, 2014

Yes I set it to false

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2014 Aug 27, 2014

Well, somehow that's probably your issue.  It is being set to false at the wrong time and the function stops performing.  I would temporarily comment out the place where it is set to false, and see if the problem goes away.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 27, 2014 Aug 27, 2014

Okey thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines