Copy link to clipboard
Copied
hi to all I'm trying to create a siple app for android (spaceinvaders) and I created a TimerEvent for the laser
this is the code
___________
//Create a timer that executes a function every 1/2 second
var laserTimer:Timer = new Timer(500);
laserTimer.addEventListener(TimerEvent.TIMER, timerListener);
function timerListener(e:TimerEvent):void
{
//In the Library linkage for a movieclip should be Laser
var tempLaser:MovieClip = new Laser();
//place the laser at the tip of the pla5er's ship
tempLaser.x = player.x +(player.width/2);
tempLaser.y = player.y;
tempLaser.speed = 10;
Lasers.push(tempLaser);
addChild(tempLaser);
var sound:Sound = new shoot();
sound.play();
}
//Lasers array is required;
function moveLaser():void
{
//Move Laser
var tempLaser:MovieClip;
for (var i=Lasers.length-1; i>=0; i--)
{
tempLaser = Lasers;
tempLaser.y -= tempLaser.speed;
if (tempLaser.y < 0)
{
//Remove laser 1 from Lasers array;
removeLaser(i);
}
}
//Remove any tempExplosion from the explosions array that has already played;
var tempExplosion:MovieClip;
for (i=explosions.length-1; i>=0; i--)
{
tempExplosion = explosions;
if (tempExplosion.currentFrame >= tempExplosion.totalFrames)
{
removeExplosion(i);
}
}
}
____
now I'm asking to convert this code whit a Multitouch event this is the code
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
movieClip_1.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler);
function fl_TapHandler(event:TouchEvent):void
{
//code
}
_____
What should I do if it 'possible?
many tnks to all
then delete all the timer code and use:
...
//Create a timer that executes a function every 1/2 second
stage.addEventListener(TouchEvent.TOUCH_TAP, timerListener);
function timerListener(event:TouchEvent):void
{
//In the Library linkage for a movieclip should be Laser
var tempLaser:MovieClip = new Laser();
//place the laser at the tip of the pla5er's ship
tempLaser.x = player.x +(player.width/2);
tempLaser.y = player.y;
tempLaser.speed = 10;
Copy link to clipboard
Copied
instead of starting a laser using the timer, you want to start a laser using a touch event?
Copy link to clipboard
Copied
yess
now i've insert at the top of as3 file this " import flash.events.TouchEvent;
and have modified the code :
//Create a timer that executes a function every 1/2 second
stage.addEventListener(TouchEvent.TOUCH_TAP, timerListener);
var laserTimer:Timer = new Timer(500);
laserTimer.addEventListener(TimerEvent.TIMER, timerListener);
function timerListener(event:TouchEvent):void
{
//In the Library linkage for a movieclip should be Laser
var tempLaser:MovieClip = new Laser();
//place the laser at the tip of the pla5er's ship
tempLaser.x = player.x +(player.width/2);
tempLaser.y = player.y;
tempLaser.speed = 10;
Lasers.push(tempLaser);
addChild(tempLaser);
var sound:Sound = new shoot();
sound.play();
}
this is the error
TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::TimerEvent@a471449 to flash.events.TouchEvent.
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
Copy link to clipboard
Copied
then delete all the timer code and use:
//Create a timer that executes a function every 1/2 second
stage.addEventListener(TouchEvent.TOUCH_TAP, timerListener);
function timerListener(event:TouchEvent):void
{
//In the Library linkage for a movieclip should be Laser
var tempLaser:MovieClip = new Laser();
//place the laser at the tip of the pla5er's ship
tempLaser.x = player.x +(player.width/2);
tempLaser.y = player.y;
tempLaser.speed = 10;
Lasers.push(tempLaser);
addChild(tempLaser);
var sound:Sound = new shoot();
sound.play();
}
Copy link to clipboard
Copied
thanks for the reply, but i've solved , this is the code
----
var laserTimer:Timer = new Timer(500);
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
stage.addEventListener(TouchEvent.TOUCH_TAP, timerListener);
function timerListener(e:TouchEvent):void
{
//In the Library linkage for a movieclip should be Laser
var tempLaser:MovieClip = new Laser();
//place the laser at the tip of the pla5er's ship
tempLaser.x = player.x +(player.width/2);
tempLaser.y = player.y;
tempLaser.cacheAsBitmap = true;
tempLaser.speed = 10;
Lasers.push(tempLaser);
addChildAt(tempLaser,2);//posizionare laser sotto bargame
var sound:Sound = new Shoot();
sound.play();
}
Copy link to clipboard
Copied
remove the laserTimer declaration.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now