OMFG! AS: Main!
Ok, in this tutorial, you will learn how how to use onClipEvent handlers but on frames instead of MC's! So, before we begin, it would be useful if you check out Inglor's AS: Clip Events becuase this will almost be the same thing but instead, you will learn how to use them on frames. I would also like to note that I checked out AS: Functions but I didnt really find anything in it that will relate to this.
---------------------------
What will I learn?
In this tutorial, you will learn how to use clipEvents but on frames. If you do this, you wont have to use a whole bunch of "varialbe holders" that are MC's. I did this a lot in the past.
Why not just use MC's?
Well, becuase what if you are making an API game? In API games, everything is done with AS so that means no "variable holders" allowed. Also, you wont have such a mess and it will be a lot easier for you.
---------------------------
Since, load and enterFrame functions are most commonly used, Ill explain those in detail. But first, Ill just explain frame functions in general. First, open up your frames action panel. Type in:
onEnterFrame=function(){
That is a frame function in its most simplist form. But you noticed it didnt do anything. Thats becuase you have to give it actions. So here is a function with actions:
onLoad=function(){
_root.gotoAndPlay(2);
}
Thats just a simple function that will play frame 2 of the root timeline. There are many more functions. You can use all the ones you see in clipEvents but always make sure you have function(){. So, thats pretty much it and now Ill explain load and enterFrame in detail.
---------------------------
enterFrame
Ok, enterFrame is a way of executing an objects actions every FPS. It is useful if you use movement for example and you want something to move forever. It is most commonly used and by far probably the most easiest.
load
Load is a way to execute an objects actions once the object is loaded and appears on the time line. Always use this for variables and things. It is unnecessary to look for a variable every FPS and is also less buggy. One of my favorite uses of it is to make a reset button for dress-ups.
READ HERE IF YOU WANNA MAKE A RESET BUTTON!
Ok, here is a basic way of making a reset button. Give a piece of clothing these actions:
onClipEvent(load){
oldx=_x;
oldy=_y;
_name="clothing";
}
on(press){
startDrag("");
}
on(release){
stopDrag();
}
Then, make a button and give it this code:
on(release){
_root.clothing._x=_root.clothing.oldx;
_root.clothing._y=_root.clothing.oldy;
}
I will not explain how that works since this tutorial isn't about that, lol.
---------------------------
Well, thats my tutorial! If I missed something (which I probably did) post here!