Copy link to clipboard
Copied
stage.addEventListener(Event.ENTER_FRAME,looping);
function looping (event:Event):void
{
shot.x +=10;
}
fire_btn.addEventListener(MouseEvent.CLICK,fire);
function fire(MouseEvent:Event):void
{
var shot:bullet = new bullet();
this.addChild(shot);
shot.x = player.x;
shot.y = player.y;
}
you're making shot local to fire() and losing your reference.
use:
var shotA:Array=[];
stage.addEventListener(Event.ENTER_FRAME,looping);
function looping (event:Event):void
{
for(var i:int=shotA.length-1;i>=0;i--){
shotA.x +=10;
if(shotA.x>stage.stageWidth){
shotA.splice(i,1);
}
}
}
fire_btn.addEventListener(MouseEvent.CLICK,fire);
function fire(MouseEvent:Event):void
{
var shot:bullet = new bullet();
shotA.push(shot);
this.addChild(shot);
shot.x = player.x;
shot.y = player.y;
}
Copy link to clipboard
Copied
you're making shot local to fire() and losing your reference.
use:
var shotA:Array=[];
stage.addEventListener(Event.ENTER_FRAME,looping);
function looping (event:Event):void
{
for(var i:int=shotA.length-1;i>=0;i--){
shotA.x +=10;
if(shotA.x>stage.stageWidth){
shotA.splice(i,1);
}
}
}
fire_btn.addEventListener(MouseEvent.CLICK,fire);
function fire(MouseEvent:Event):void
{
var shot:bullet = new bullet();
shotA.push(shot);
this.addChild(shot);
shot.x = player.x;
shot.y = player.y;
}
Copy link to clipboard
Copied
Thank you very much!!!
It works perfect!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now