# AS2 - tutorial trouble

**URL:** <https://forum.kirupa.com/t/as2-tutorial-trouble/285467>\
**Category:** flash\
**Created:** [April 1, 2009, 7:23am UTC](https://forum.kirupa.com/t/as2-tutorial-trouble/285467 "2009-04-01T07:23:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhf80](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@jhf80](https://forum.kirupa.com/u/jhf80)\
**Post date:** [April 1, 2009, 7:23am UTC](https://forum.kirupa.com/t/as2-tutorial-trouble/285467/1 "2009-04-01T07:23:43Z")

</div>

Hi iwe been following a tutorial on how to make a vertical shooter in AS2 on:[http://www.mrsunstudios.com/2009/01/tutorial-make-a-vertical-shooter-in-as2-part-2/](http://www.mrsunstudios.com/2009/01/tutorial-make-a-vertical-shooter-in-as2-part-2/)  
Annoying thing is, I cant get the final step on part two to work (where you make the bullets fire in intervals) I´ve tried looking at the source file but its in AS3 :stare::ponder:

this is the script so far:

[COLOR=Green]var mainSpeed:Number = 5;//how fast the main guy can move

onEnterFrame = function(){ //this function will run every frame (needed for moving the character  
if(Key.isDown(37) || Key.isDown(65)){ //if the “A” key or Left Arrow Key is Down  
mcMain.\_x -= mainSpeed;//then the move the guy left  
}  
if (Key.isDown(38) || Key.isDown(87)){//if the “W” key or Up Arrow Key is Down  
mcMain.\_y -= mainSpeed; //then move the guy up  
}  
if(Key.isDown(39) || Key.isDown(68)){//if the “D” key or Right Arrow Key is Down  
mcMain.\_x += mainSpeed; //then move the guy to the right  
}  
if(Key.isDown(40) || Key.isDown(83)){//if the “S” key or Down Arrow Key is Down  
mcMain.\_y += mainSpeed; //then move the guy down  
}

```
//keeping the main character within bounds
if(mcMain._x &lt;= 0){
    mcMain._x += mainSpeed;
}
if(mcMain._y &lt;= 0){
    mcMain._y += mainSpeed;
}
if(mcMain._x &gt;= Stage.width - mcMain._width){
    mcMain._x -= mainSpeed;
}
if(mcMain._y &gt;= Stage.height - mcMain._height){
    mcMain._y -= mainSpeed;
}

```

[COLOR=Red]

//this is where im confused, i need to add this:[/COLOR]  
if(Key.isDown(32)[/COLOR][COLOR=Red] && shootAllow[/COLOR]){//if the space bar is pressed  
[COLOR=Green][COLOR=Red]//and this somewere!:[/COLOR][/COLOR][COLOR=Red] shootAllow = false;[/COLOR]

[COLOR=Green]  
//BULLET TIMING VARIABLES  
var cTime:Number = 0;//the amount of frames that has elapsed since last bullet shot  
var cLimit:Number = 12;//amount of frames needed to shoot another bullet  
var shootAllow:Boolean = false;//whether or not main can shoot  
var bulletID:Number = Math.random(); //create a variable that we’ll use at the bullet’s id  
//then attach a bullet to the stage  
\_root.attachMovie(‘mcBullet’, ‘Bullet’+bulletID,\_root.getNextHighestDepth());  
//setting the coordinates of the bullet to be the same as the main character  
\_root[‘Bullet’+bulletID].\_x = mcMain.\_x + mcMain.\_width/2 - \_root[‘Bullet’+bulletID].\_width/2;  
\_root[‘Bullet’+bulletID].\_y = mcMain.\_y;  
\_root[‘Bullet’+bulletID].onEnterFrame = function(){  
//giving the bullet some actions  
this.\_y -= 10; //moving the bullet  
if(this.\_y \< -1 \* this.\_height){//if the bullet goes off stage  
//then destroy it  
this.removeMovieClip();  
}

```
}
cTime ++;//increment the time
if(cTime == cLimit){//if enough time has elapsed
shootAllow = true;//allow shooting again
cTime = 0;//reset the time
}

```

}  
}[/COLOR]
