Hello i am new to this site and actionscript 3, so keep in mind my lack of knowledge. I have code that works fine in actionscript 3, which is what the adobe ios uses to write apps. The only problem is that I don’t know how to change the keyboard presses to button presses. Like in the iphone os a MouseEvent.Click registers when you press down on the screen. How do i change the keyboard presses to mouse clicks? here is the code. Thanks to all who attempt help this noob.
package
{
import flash.display.MovieClip
import flash.events.Event
import flash.events.KeyboardEvent
public class DocumentMain extends MovieClip
{
public var _player:Player;
public var _startMarker:StartMarker;
public var _boundaries:Boundaries;
private var _vy:Number;
private var _vx:Number;
public function DocumentMain():void
{
//assign default values
_startMarker.visible=false;
_vx = 0;
_vy = 0;
//set focus for keyboard input
stage.focus=stage;
//add event listeners
this.addEventListener(Event.ENTER_FRAME, enterFrameHanlder);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
}
private function enterFrameHanlder(e:Event):void
{
_vy += 2;
//gravitate the player
_player.x += _vx;
_player.y += _vy;
//move the player
//process collisions
processCollisions();
//scroll the stage
scrollStage();
}
private function keyDownHandler(e:KeyboardEvent):void
{
switch (e.keyCode)
{
case 37: //left arrow
_vx = -7;
break;
case 38: //up arrow
_vy = -20;
break;
case 39: //right arrow
_vx = 7;
break;
default:
}
}
private function keyUpHandler(e:KeyboardEvent):void
{
switch(e.keyCode){
case 37:
case 39:
_vx = 0;
break;
default:
}
}
private function processCollisions():void
{
//when the player is falling
if( _vy>0)
{
//respawn if player fell off the stage
if(_player.y>stage.stageHeight)
{
_player.x = _startMarker.x;
_player.y = _startMarker.y;
_boundaries.x = 0;
_boundaries.y = 0;
_vy = 0;
}
//otherwise, process collisions with boundaries
else
{
var collision:Boolean=false;
if (_boundaries.hitTestPoint(_player.x, _player.y, true))
{
collision = true;
}
if (collision)
{
while (collision)
{
_player.y -=0.1;
collision = false;
if (_boundaries.hitTestPoint(_player.x, _player.y, true))
{
collision = true;
}
}
_vy = 0;
}
}
}
}
private function scrollStage():void
{
_boundaries.x += (stage.stageWidth * .5) - _player.x;
_player.x = stage.stageWidth * .5;
_boundaries.y += (stage.stageHeight * .5) - _player.y;
_player.y = stage.stageHeight * .5;
}
}
}