so......i decided to show you some easy AS2 scripts....
1. Button
Its one of the easy scripts:
- Code:
-
on(release){
gotoAndPlay("Scene 1",1);
}
when you press the button it goes to the scene which is named "Scene 1" and there to frame one
2. getURL (in this example its a button script)
- Code:
-
when you click the button it opens the URL in a new (_blank) window.
instead of _blank you might want to use _self(opens in the same window)
3.(INTERMEDIATE) simply walking script for games.
the first thing you need is creating a MC, its instanceName is hero.(thats the person you will walk with)
than you need to create an other MC which instanceName is ground.(its the ground =P)
the second thing you need is the variable for the speed....select your char(have to be a MC!) aand type the following:
- Code:
-
onClipEvent (load) {
var speed:Number = 3;
}
var stands for variable, speed is the name of the var and the :Number = 3 tag defined the speed.
the second thing you need is a variable who says that the char touchs the ground.....and ofcorse a gravity var a scale var(to lazy to explain this):
- Code:
-
var touchingGround:Boolean = false;
var grav:Number = 0;
var scale:Number = _xscale;
put this script in the variable section:
- Code:
-
onClipEvent (load) {
var speed:Number = 3;
var grav:Number = 0;
var touchingGround:Boolean = false;
var scale:Number = _xscale;
}
now, this is a bit difficult:
(i won't explain all only the important things)
- Code:
-
onClipEvent (enterFrame) {
if (!touchingGround) {
grav++;
this._y = grav;
} else {
grav = 0;
}
if (_root.ground.hitTest(_x, _y, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
//if the char touchs the ground
//the gravity goes up otherwise the char would fly(grav++)
//this stands for the char MC, _y is the axis , = grav means that the grav is now in use
//if the char doesn't touch the ground(else)
// gravity is 0, he jumps(grav = 0)
//if the Char hits the ground
//the script knows that he touchs the ground cause its true(touchingGround =true)
//if he doesn't touchs the ground
//its false, he jumps
now you have setted up the ground and the gravity.......whats missing?...right, the walking script for the char.
- Code:
-
if (Key.isDown(Key.LEFT)) {
_x -= speed;
this.gotoAndStop(2);
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT)) {
_x = speed;
this.gotoAndStop(2);
_xscale = scale;
}
im to lazy to explain this....its just a script that let you walk on the x axis.
this.gotoAndStop(2) just says that when you press "right" it goes to the current MC(our hero) and there to the second frame....ofcorse you can change that.
heres the whole script:
- Code:
-
onClipEvent (load) {
var speed:Number = 3;
var grav:Number = 0;
var touchingGround:Boolean = false;
var scale:Number = _xscale;
}
onClipEvent (enterFrame) {
if (!touchingGround) {
grav++;
this._y = grav;
} else {
grav = 0;
}
}
onClipEvent (enterFrame){
if (_root.ground.hitTest(_x, _y, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(Key.LEFT)) {
_x -= speed;
this.gotoAndStop(2);
_xscale = -scale;
}
if (Key.isDown(Key.RIGHT)) {
_x = speed;
this.gotoAndStop(2);
_xscale = scale;
}
}
example for the script:
http://www.truploader.com/view/043335contex menu:Res requested a context menu(rightclick menu) script:
first we need to hide the default items:
- Code:
-
var myMenu_cm:ContextMenu = new ContextMenu();
myMenu_cm.hideBuiltInItems();
_root.menu = myMenu_cm;
"var myMenu_cm:ContexMenu = new ContexMenu();" creates a variable that allows you to hide the menu.
"myMenu_cm.hideBuiltInItems();" selfexplaining....
"_root.menu = myMenu_cm;" makes the custom menu visible
so, thats the "hard" part.
you see, its very easy.
now we create some items for the menu.
- Code:
-
var newItem1_cmi = new ContextMenuItem ("Low Quality", low_quality);
function low_quality (){
_quality = "LOW";
}
in this example it'll set the quality to low.
"var newItem1_cmi = new ContextMenuItem ("Low Quality", low_quality);"
nothing to say here, it sets the variable for the new item and the name of it, where "Low Quality" is the name that shows up in the menu.
"function low_quality (){" adds a function to it
"_quality = "LOW";"
you could add anything you want here...something about, gotoAndPlay(Scene 1,1); or so.
I'll use the _qualty thing.
"}" -.-
now you created the item but it doesn't show up in the menu.
to do this we add a simply code UNDER the variable section:
- Code:
-
myMenu_cm.customItems.push(newItem1_cmi);
it says that "newItem1_cm"i shows now up.
THATS IT!
you can add as many items you want, just add a new item to it (newItem2_cm) and add the code above to it.
so, you may want to know how to add a separator between two items.
this is also verx simply:
newItem2_cmi.separatorBefore = true;
this adds a seperator BEFORE newItem2_cmi.......easy right?
you made you own context menu
I'll update this soon with some more scripts
btw sorry for bad grammar