Skip to main content
Participant
February 17, 2013
Answered

Can i convert TimerEvent to MultitouchInputMode ?

  • February 17, 2013
  • 1 reply
  • 998 views

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

This topic has been closed for replies.
Correct answer kglad

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();

}

1 reply

kglad
Community Expert
Community Expert
February 17, 2013

instead of starting a laser using the timer, you want to start a laser using a touch event?

Participant
February 17, 2013

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()

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
February 17, 2013

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();

}