mardi 22 novembre 2016

How do I make a progress bar that is listening to a variable in Flash?

This is the first time I worked on a Flash game and I have no idea how to make a progress bar that is dependent to a variable I initialized instead of a percentage.

I am trying to make an interactive space ship launching animation and the logic should be like this:

  1. The user has to press the space bar to increase percentage (the progress bar should increase in accordance to the percentage)
  2. When the percentage reaches 100%, it will play the launching animation I have made (frame 11 in this case)

Now the code doesn't work as I expected and I have found 2 issues:

  1. The user has to click on the window to increase the counter
  2. Whenever I press space bar the movie will skip to frame 11.

So here's 2 question, how do I make the progress bar with the requirements listed above? And how do I fix the code so that the movie doesn't skip to the next frame without meeting the requirements?

import flash.events.KeyboardEvent;

var score1:Number=0;

stage.addEventListener(KeyboardEvent.KEY_DOWN,plus);

function plus(e:KeyboardEvent){
    if (score1 < 100){
    if (e.keyCode == 32){
    score.text=new String(score1);
    score1+=20;
    }
    }   
    gotoAndStop(11);
}

progressBar.addEventListener(ProgressEvent.PROGRESS, plus)

Aucun commentaire:

Enregistrer un commentaire