Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can i convert TimerEvent to MultitouchInputMode ?

New Here ,
Feb 17, 2013 Feb 17, 2013

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

TOPICS
ActionScript
949
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 17, 2013 Feb 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;

         

...
Translate
Community Expert ,
Feb 17, 2013 Feb 17, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 17, 2013 Feb 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()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 17, 2013 Feb 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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 18, 2013 Feb 18, 2013

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 18, 2013 Feb 18, 2013
LATEST

remove the laserTimer declaration.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines