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.CLICK, moveDownwards);
rightbtn.addEventListener(MouseEvent.CLICK, moveRight);
leftbtn.addEventListener(MouseEvent.CLICK, 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;
}
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.CLICK, moveDownwards);
rightbtn.addEventListener(MouseEvent.CLICK, moveRight);
leftbtn.addEventListener(MouseEvent.CLICK, 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;
}
Controlling objects by keyoard and mouse in Flash using AS3.0 - Flash Tutorials | |
644 views views | followers |
2 Likes | 2 Dislikes |
People & Blogs | Upload TimePublished on 9 Apr 2015 |
Không có nhận xét nào:
Đăng nhận xét