Controlling objects by keyboard and mouse in Flash using AS3.0 - Flash Tutorials

VerkkoNetPublished: August 10, 2017
Published: August 10, 2017

In this vide, you can learn to work with mouse and keyboard, and controlling objects with mouse and keyboard in Flash using AS3.0

Website: http://samsolomonprabu.com/

Here's the source code:
---------------------------

import flash.events.MouseEvent;
import flash.events.KeyboardEvent;

upbtn.addEventListener(MouseEvent.CLICK, moveUpwards);
downbtn.addEventListener(MouseEvent.CLIC­K, moveDownwards);
rightbtn.addEventListener(MouseEvent.CLI­CK, moveRight);
leftbtn.addEventListener(MouseEvent.CLIC­K, moveLeft);

stage.addEventListener(KeyboardEvent.KEY­_DOWN, onKeyPress);

function onKeyPress(e:KeyboardEvent):void{

if(e.keyCode == 38){
baseball.y -= 10;
}else if(e.keyCode == 40){
baseball.y += 10;
}else if(e.keyCode == 37){
baseball.x -= 10;
}else if(e.keyCode == 39){
baseball.x += 10;
}

}

function moveUpwards(e:MouseEvent):void{

baseball.y -= 10;

}

function moveDownwards(e:MouseEvent):void{

baseball.y += 10;

}

function moveRight(e:MouseEvent):void{

baseball.x += 10;

}

function moveLeft(e:MouseEvent):void{

baseball.x -= 10;

}

Recommend tags
  • action script programming+1
  • as3+1
  • adobe flash+1
  • flash tutorials+1

action script programmingas3adobe flashflash tutorials

Comments

0 comments