Skip to main content
Participating Frequently
December 11, 2012
Answered

Flash Multi Touch help

  • December 11, 2012
  • 1 reply
  • 1507 views

I am creating a Multi Touch game for a project of mine. I have created the desktop versionusing actionscript 3 and mouse clicks, but I need to convert it into multi touch. Below you will see the code for one of the levels.

Aims: The main game is a sniper based, you will have a completly blacked out screen with a cross hair only showing you a certain amount of the screen.

Solved problem: I have been able to convert my enemies to multi touch pretty easily with the touch begin events etc so they are not a problem

UnSolved problem: The code at the bottom in red is my issue, the creation of a pure black screen is fine I have that but to enable multi touch instead of a mouse is a little tricker. I can kill the enemy as I said above but I can't seem to get the correct command in to drag the "scope" around the screen.

IF anybody knows the code to put in it would be greatly appreciated or knows a tutorial that could help me out.

Thanks in advance,

Jason

stop();

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

 

var crosshairD:MovieClip; //this code replaces cursor with scope

var soundD:Sound = new Sound (new URLRequest("gunshot.mp3"));//this code calls in the mp3 file

    mc_4.addEventListener(TouchEvent.TOUCH_BEGIN, dock_shot);

//stage.addChild(mc_4);

shootMe2();

function dock_shot(event:TouchEvent):void {

gotoAndStop(1, "level2_comp");

crosshairD.visible = false;

//Mouse.hide();

stage.removeChild(mc_4);

} //this code makes the movie clip clickable

guard1.addEventListener(TouchEvent.TOUCH_BEGIN, guard1_fcn);

//stage.addChild(mc_5);

function guard1_fcn(event:TouchEvent):void {

gotoAndStop(1, "level2_fail");

crosshairD.visible = false;

//Mouse.hide();

stage.removeChild(guard1);

} //this code makes the movie clip clickable

guard2.addEventListener(TouchEvent.TOUCH_BEGIN, guard2_fcn);

//stage.addChild(mc_5);

function guard2_fcn(event:TouchEvent):void {

gotoAndStop(1, "level2_fail");

crosshairD.visible = false;

//Mouse.hide();

stage.removeChild(guard2);

} //this code makes the movie clip clickable

guard3.addEventListener(TouchEvent.TOUCH_BEGIN, guard3_fcn);

//stage.addChild(mc_5);

function guard3_fcn(event:TouchEvent):void {

gotoAndStop(1, "level2_fail");

crosshairD.visible = false;

//Mouse.hide();

stage.removeChild(guard3);

} //this code makes the movie clip clickable

guard4.addEventListener(TouchEvent.TOUCH_BEGIN, guard4_fcn);

//stage.addChild(mc_5);

function guard4_fcn(event:TouchEvent):void {

gotoAndStop(1, "level2_fail");

crosshairD.visible = false;

//Mouse.hide();

stage.removeChild(guard4);

} //this code makes the movie clip clickable

function shootMe2 ():void

{

    crosshairD = new Cursor();

    stage.addChild (crosshairD);

    crosshairD.enabled = false;

    Mouse.hide();

          crosshairD.mouseEnabled = false;

    stage.addEventListener (MouseEvent.MOUSE_MOVE, dragCursorD);

          stage.addEventListener (TouchEvent.TOUCH_BEGIN, clickedD);

}

function clickedD(event:TouchEvent):void{

          soundD.play();

          }

function dragCursorD (event:MouseEvent):void

{

    crosshairD.x = this.mouseX;

    crosshairD.y = this.mouseY;

}

This topic has been closed for replies.
Correct answer sinious

You're already using all TouchEvents except for moving the scope. Use TouchEvent.TOUCH_MOVE to move the scope instead:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/TouchEvent.html#TOUCH_MOVE

And your handler is moving to this.mouseX/Y not using the events event.localX/Y. Either should do for a desktop. Only touch for a device.

1 reply

sinious
siniousCorrect answer
Legend
December 11, 2012

You're already using all TouchEvents except for moving the scope. Use TouchEvent.TOUCH_MOVE to move the scope instead:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/TouchEvent.html#TOUCH_MOVE

And your handler is moving to this.mouseX/Y not using the events event.localX/Y. Either should do for a desktop. Only touch for a device.

Participating Frequently
December 18, 2012

Brilliant that change worked superbly! Thank a million life saver.

sinious
Legend
December 18, 2012

You're welcome and good luck!