因此,我一直在编写此代码数周(我是 AS3 的初学者),但我一生都无法弄清楚如何编写接收触摸输入的工作移动按钮。此代码仿照 Adobe Samples 之一,但是当我运行它时它不起作用。
这是我的代码:
package MovementButtons
{
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.TouchEvent;
public class TouchInput extends MovieClip
{
public var bLeftPressed:Boolean = true;
public var bRightPressed:Boolean = true;
public var nSpeed:Number = 100;
}
public function TouchInput()
{
left_btn.addEventListener(TouchEvent.TOUCH_BEGIN, TouchBeginHandler, false, 0, true);
left_btn.addEventListener(MouseEvent.TOUCH_END, TouchEndHandler, false, 0, true);
right_btn.addEventListener(TouchEvent.TOUCH_BEGIN, TouchBeginHandler, false, 0, true);
right_btn.addEventListener(TouchEvent.TOUCH_END, TouchEndHandler, false, 0, true);
//Updating Screen
addEventListener(TouchEvent.TOUCH_BEGIN, enterFrameMoveHandler);
}
protected function enterFrameMoveHandler(event:TouchEvent):void
{
var click.txt:String= "The function is working";
while ( bLeftPressed ) {
guy_mc.x -= nSpeed;
}
while( bRightPressed ) {
guy_mc.x += nSpeed;
}
}
protected function TouchBeginHandler(event:TouchEvent):void
{
click.txt = "Its clicked.";
switch ( event.target )
{
case left_btn:
left = true;
break;
case right_btn:
right = true;
break;
}
}
protected function TouchEndHandler(event:MouseEvent):void
{
switch ( event.target )
{
case left_btn:
left = false;
break;
case right_btn:
right = false;
break;
}
}
}