|
|
 |
|
|
|
|
|
Hey fellas. I did a search and didn't find any topics on this, so I figured I'd post it. (I apologize if I overlooked it).
I just got finished writing my first complete animation using scripting only, and was very excited to share. It's nothing special, just kinda cool.
Here
Here's the code used:
/******************************************************************
When the movie is loaded, it defines the varible "pos" as being
equal to the X position of the box on the stage.
It also defines two functions... lessThanDumbAss, and greaterThanDumbAss.
These check to see if the number the user entered was lower or higher
than what was suggested. If it is too high, or too low, it will say
"null" in the varible pos' input box, and set the X property of the box
to 30 and wait for a new number.
******************************************************************/
onLoad () {
box._X = pos;
}
function lessThanDumbAss()
{
if (pos < 30){
gotoAndStop(7);
if (pos = null){
gotoAndStop(7);
}
}
}
function greaterThanDumbAss()
{
if(pos > 250){
gotoAndStop(7);
if(pos = null){
gotoAndStop(7);
}
}
}
/*******************************************************************
Stop on the first frame, so none of the animation executes until a
number is typed in by the user, and the submit button is pressed.
*******************************************************************/
onFrame (1) {
stop();
}
/*******************************************************************
When the user enters a number and presses the submit button, it comes
to frame 2. At frame 2, the functions that were defined before are
executed, in search of a dumbass who can't read. =)
After that has been ruled out, if the number that was entered into the
varible "pos" was less than the X position of the box on the stage, then
go to frame 5 and subtract one pixel.
If the varible "pos" is greater than the X position of the box on the stage,
go to frame 3 and add one pixel.
If the number entered was equal to the X position of the box, the movie
stops and waits for a new number.
********************************************************************/
onFrame (2) {
lessThanDumbAss();
greaterThanDumbAss();
if (pos < box._X) {
gotoAndPlay(5);
}
if (pos > box._X) {
gotoAndPlay(3);
}
if (pos == box._X) {
stop();
}
}
/********************************************************************
On frame 3, if the X position of the box is greater than or equal to
the number that was entered, stop the movie, and go back to frame one
and await a new number to be entered. If it is not greater than or equal
to the number that was entered, add one pixel.
*********************************************************************/
onFrame(3){
if(box._X >= pos){
gotoAndStop(1);
}else{
box._X += 1;
}
}
/**********************************************************************
On frame 4, if the X position of the box is still not equal to the number
that was typed in the "pos" varible, go back to frame 3, and add another
pixel until they are equal.
**********************************************************************/
onFrame(4){
if(box._X != pos){
gotoAndPlay(3);
}
}
/**********************************************************************
On frame 5, if the number that was entered into the varible "pos" is
greater than or equal to the X position of the box on the stage, go to
frame 1 and stop, and await a new number to be entered. Otherwise,
subtract one pixel.
**********************************************************************/
onFrame(5){
if(pos >= box._X){
gotoAndStop(1);
}else{
box._X -= 1;
}
}
/**********************************************************************
On frame 6, if the X position of the box on the stage is still not equal to
the number that was entered into the varible "pos", go to frame 5 and
subtract 1 pixel until it is equal
**********************************************************************/
onFrame(6){
if(box._X != pos){
gotoAndPlay(5);
}else{
gotoAndStop(1);
}
}
/***********************************************************************
This section is for people who can't read only... of course, if you couldn't
read, you would be reading this now would you?
************************************************************************/
onFrame(7){
stop();
box._X = 30;
}
---------------------------------------------------
If you guys see an easier way I could have done this, please let me know.
-Tote
P.S. I know I went a little crazy with the comments, I was just having fun!
|
|
|
|