ActionScript Codes Here
I thought I’d make a tutorial for just actionscript so I did here it is any questions you got just ask me.
Movie Clip Follows Mouse
onClipEvent(enterFrame) {
this._x = _root._xmouse;
this._y = _root._ymouse;
}
Movement with walls
onClipEvent (load) {
// Set the move speed
moveSpeed = 15;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
if (_root.Walls.hitTest(getBounds(_root).xMax,_y,true)) {
} else {
this._x += moveSpeed;
this.gotoAndStop(3);
}
// Move Right
} else if (Key.isDown(Key.UP)) {
if (_root.Walls.hitTest(_x,getBounds(_root).yMin,true)) {
} else {
this._y -= moveSpeed;
this.gotoAndStop(2);
}
// Move Up
} else if (Key.isDown(Key.DOWN)) {
if (_root.Walls.hitTest(_x,getBounds(_root).yMax,true)) {
} else {
this._y += moveSpeed;
this.gotoAndStop(5);
}
// Move Down
} else if (Key.isDown(Key.LEFT)) {
if (_root.Walls.hitTest(getBounds(_root).xMin,_y,true)) {
} else {
this._x -= moveSpeed;
this.gotoAndStop(4);
}
// Move Left
}
}
NOTE: To activate the walls, you must make a movieclip labelled “Walls”
Dragging Script
onClipEvent(mouseDown) {
if(this.hitTest(_root._xmouse, _root._ymouse)) {
this.startDrag(true);
}
}
onClipEvent(mouseUp) {
this.stopDrag();
}
If Button
on (release) {
variable += 1;
variable2 -= 1;
if (variable2 < 0) {
variable2 += 1;
variable -= 1;
}
}
Make Invisible Button
on (release) {
tellTarget ("_root.movieclip") {
_visible = false;
}
}
basic car
onClipEvent (enterFrame) {
// right
if (Key.isDown(Key.RIGHT)) {
_rotation = _rotation+move;
}
// left
if (Key.isDown(Key.LEFT)) {
_rotation = _rotation-move;
}
// up
if (Key.isDown(Key.UP)) {
if (move< {
move++;
}
} else if (move>0) {
move–;
}
// down
if (Key.isDown(Key.DOWN)) {
if (move>-10) {
move–;
}
} else if (move<0) {
move++;
}
// enter
if (Key.isDown(Key.ENTER)) {
_x = 200;
_y = 200;
_rotation = 0;
move = 0;
}
// _x & _y position
if (_rotation>180) {
_y = _y+(moveMath.cos(Math.PI/180_rotation));
_x = _x-(moveMath.sin(Math.PI/180_rotation));
}
if (_rotation<180) {
_y = _y-(moveMath.cos(Math.PI/180_rotation));
_x = _x+(moveMath.sin(Math.PI/180_rotation));
}
Movieclip runs away from mouse
onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse,_root._ymouse,true)) {
this._x = int(Math.random()*550);
this._y = int(Math.random()*400);
}
}
Character jumping script
onClipEvent (load) {
grav_y = 0;
jumping = false;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.SPACE) && !jumping) {
grav_y = 20;
jumping = true;
}
if (jumping == true) {
grav_y -= 1;
if (grav_y<=-10) {
grav_y = -10;
}
this._y -= grav_y;
}
if (_root.ground.hitTest(this._x, this._y+45, true)) {
grav_y = 0;
jumping = false;
}
}
Random Weather
onClipEvent (load) {
randomWeather = random (3);
if (randomWeather == 0) {
conditions = “Sunny”;
_root.rocket.noThrust = 3;
_root.rocket.thrust = 6;
} else if (randomWeather == 1) {
conditions = “Rainy”;
_root.rocket.noThrust = 2;
_root.rocket.thrust = 4;
} else {
conditions = “Night”;
_root.rocket.noThrust = 1;
_root.rocket.thrust = 2;
}
gotoAndStop(conditions);
_root.weatherText.text = "Weather: " + conditions;
}
SCORE SCRIPT
onClipEvent (enterFrame) {
if (this.hitTest(_root.player)) {
_root.score += 1;
if (_root.score == 100) {
_root.gotoAndPlay (frame);
}
}
}
This tutorial is for new Flash user who wish to create RPG games .
Note: This is just a start for making an RPG game, i will add a sequel to this tutorial later, if you guys post more.
You just need some Movie Clip and a few line of code to create this inventory system , it is very simple
Action script in frame
Note: This will create an inventory system in Flash movie frame one . You can move the inventory system anywhere in your flash movie by editing the code . Copy these code to your Flash movie , frame one .
currentslotnum = 1;
stop ();
function addToslot (item) {
if (!item.found) {
item._x = eval (“itemSlot” + currentslotnum)._x;
item._y = eval (“itemSlot” + currentslotnum)._y;
item.found = true;
currentslotnum++;
}
}
Now , you will need some Movie Clips work as the items . Create the Movie Clip with the images you want , then assign these lines of code to the Movie Clip .
onClipEvent (enterFrame) {
if (_root.character.hitTest (this)) {
_root.addToslot (this);
}
}
Now , you will need to create some Movie Clips which will store those items . Create the Movie Clip then name it itemSlot1 , itemSlot2 , itemSlot3 , etc .
Note: If you have 2 items , you just need to create 2 Movie Clips to store items .
Note: Name the Movie Clip itemSlot + Form 1 to the number base on the items you created in the movie .Almost done now …
Movie Clips - Character
The last step is just create a Movie Clip work as the character ( Player controllable Movie Clip ) . After it , name the Movie Clip “character” ( Of course , without the quotation marks . ) and assign these code to it .
onClipEvent (load) {
moveSpeed = 19;
}
onClipEvent (enterFrame) {
if (Key.isDown (Key.RIGHT)) {
this._x += moveSpeed;
} else if (Key.isDown (Key.UP)) {
this._y -= moveSpeed;
} else if (Key.isDown (Key.DOWN)) {
this._y += moveSpeed;
} else if (Key.isDown (Key.LEFT)) {
this._x -= moveSpeed;
}
}
Creating the DNA effect like in the FlashBox banner.
www.flashbox.cjb.net
Create an object like a cotton bud.Give it an instance name of dna1
You can use any colours but the colours I used are as follows:
A radial gradient set with colours from left to right:
255.255.255 at alpha 100%
255,255,200 at alpha 50%
255,255,255 at alpha 100%
243,126,12 at alpha 40%
255,255,255 at alpha 0%
Now create a layer and name it actions. In the first keyframe give action:
for (i=2; i<30; i=i+1)
{
duplicateMovieClip ("/dna1", “dna” add (i), i);
setProperty ("/dna" add i, _rotation, getProperty("/dna" add (i-1), _rotation)+11);
setProperty ("/dna" add i, _x, getProperty("/dna" add (i-1), _x)+10);
}
setProperty ("/dna1", _visible, “0”);
In the next keyframe give action
for(i=2; i < 30; i = i+1)
{ setProperty ("/dna" add i, _rotation, getProperty("/dna" add i, _rotation) + 5);
}
And finally give the third keyframe
gotoAndPlay (2);
And that’s it.