Friday, 31 October 2014

Basic Flash Actionscript 3 Shooting Game Tutorial

Flash College





------------------------------------------------------------------------------------------------------------------
COPY AND PASTE BELOW ACTION SCRIPT CODE IN ACTION SCRIPT PANEL
CRATE TWO MOVIE CLIPS AND GIVE NAMEs player, bullet  
AND "Export For Action Script" Export In Frame 1  BOXes SHOULD BE CHECKED
WATCH THIS VIDEO
-----------------------------------------------------------------------------------------------------------------

var Player:player = new player();
Player.x = mouseX;
Player.y = mouseY;
addChild(Player);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemove);
stage.addEventListener(MouseEvent.MOUSE_DOWN, shoot);
function mousemove(e:MouseEvent):void{
Player.x = mouseX;
Player.y = mouseY;
}
function shoot(e:Event):void{
var Bullet:bullet = new bullet();
Bullet.x = Player.x;
Bullet.y = Player.y;
addChild(Bullet);
Bullet.addEventListener(Event.ENTER_FRAME, moveBullet);
}
function moveBullet(e:Event):void {
e.target.y -= 5;
if (e.target.y <= -10) {
e.target.removeEventListener(Event.ENTER_FRAME, moveBullet);
removeChild(MovieClip(e.target));
}
}

------------------------------------------------------------------------------------------------------------
YOU CAN WRITE UPPER CODE IN THIS WAY (SHOW SAME RESULT)
var Player:player = new player();
Player.x = mouseX;
Player.y = mouseY;
addChild(Player);
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemove);
function mousemove(e:MouseEvent):void{
Player.x = mouseX;
Player.y = mouseY;
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, shoot);
function shoot(e:Event):void{
var Bullet:bullet = new bullet();
Bullet.x = Player.x;
Bullet.y = Player.y;
addChild(Bullet);
Bullet.addEventListener(Event.ENTER_FRAME, moveBullet);
}
function moveBullet(e:Event):void {
e.target.y -= 5;
if (e.target.y <= -10) {
e.target.removeEventListener(Event.ENTER_FRAME, moveBullet);
removeChild(MovieClip(e.target));
}
}
------------------------------------------------------------------------------------------------------------
YOU CAN WRITE UPPER CODE IN THIS WAY (SHOW DIFFERENT RESULT)
USE Player AND Bullet AS INSTANCE NAME
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemove);
function mousemove(e:MouseEvent):void{
Player.x = mouseX;
Player.y = mouseY;
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, shoot);
function shoot(e:Event):void{
Bullet.x = Player.x;
Bullet.y = Player.y;
addChild(Bullet);
Bullet.addEventListener(Event.ENTER_FRAME, moveBullet);
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, moveBullet);
function moveBullet(e:Event):void {
e.target.y -= 5;
if (e.target.y <= -10) {
e.target.removeEventListener(Event.ENTER_FRAME, moveBullet);
removeChild(MovieClip(e.target));
}
}

----------------------------------------------------------------------------------------------------------
BULLET ANIMATION WITHOUT CLASS FILE
CRATE TWO MOVIE CLIPS AND GIVE INSTANCE NAMES
1- UFO_MC
2- beam (CREATE THIS MOVIE CLIP UNDER UFO_MC WITH STRAIGHT MOTION TWEEN AND STOP ACTION LAYER)

CRATE TWO BUTTONS AND GIVE INSTANCE NAMES
1- reset
2-  button_1

STOP ACTION FOR beam MOVIE CLIP INSIDE STOP ACTION LAYER

stop();

------------------------------------------------------------------------------------------------------------

reset.visible = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_PressKeyToMove);
function fl_PressKeyToMove(event:KeyboardEvent):void{
switch (event.keyCode){
case Keyboard.UP:{
UFO_MC.y -= 5;
break;
}
case Keyboard.DOWN:{
UFO_MC.y += 5;
break;
}
case Keyboard.RIGHT:{
UFO_MC.beam.play();
break;
}}}
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToHide);
function fl_ClickToHide(event:MouseEvent):void{
button_1.visible = false;
reset.visible = true;
UFO_MC.x = 40;
UFO_MC.y = 90;
}
reset.addEventListener(MouseEvent.CLICK, fl_ClickToHide_2);
function fl_ClickToHide_2(event:MouseEvent):void{
button_1.visible = true;
reset.visible = false;
}
reset.addEventListener(MouseEvent.CLICK, fl_ClickToPosition);
function fl_ClickToPosition(event:MouseEvent):void{
UFO_MC.x = 40;
UFO_MC.y = 90;
}






















EmoticonEmoticon