The book is called: Teach yourself easy Flash MX actionscript by Bob van Duuren
Here are some other handy scripts:
INVENTORY SCRIPT
___________________________________
You need to create global booleans that, when true, will cause certain movie clips and buttons be visible.
I'm not absolutely sure this will work with nested buttons and/or movie clips, since I've tried similar things and had them not work for reasons unexplained.... Well, anyway, I'd suggest making a movie clip of the subscreen you want, and inside it have all the items. In the actionscript for the movie clip put stuff like:
this.item1_instance_name._visible = false;
this.item2_instance_name._visible = false;
this.item3_instance_name._visible = false;
if(haveItem1 == true){this.item1_instance_name._visible = true;}
if(haveItem2 == true) {this.item2_instance_name._visible = false;}
if(haveItem3 == true) {this.item3_instance_name._visible = false;}
//where "haveItem1" is the name of a global boolean that will initially be false, but will be toggled to true when you pick up the item.
Then in the main stage there could be a button that would have the actionscript:
on(release){
if(_root.subscreen_movieclip._visible == false){_root.subscreen_movieclip._visible = true}
else{_root.subscreen_movieclip._visible = false}
}
Don't forget to name your instances of each movie clip.
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;
}
}
NOTE: if you want to have the character to stop at a ground point, you must make a movieclip and label it ground