PDA

View Full Version : English to AS2 [Flash][Advice][Actionscript]



Cryoma
03-25-2008, 07:10 PM
The basics of Action Script 2 can be pretty daunting at first, it is like a new language after all.
But it is pretty easy to learn, all you have to do is take the regular old english language, change the grammar a bit, and change the punctuation.
The differences between AS and english is called Syntax.
I'm going to show you a little sample of Syntax, to explain how it works.

Say you have a button, it has its up state and over state, that's basic and simple and anyone can do it, but how exactly do you make the button do stuff?
My example will be a play button, placed at the beginning of a movie.
Assuming you already have a movie (you don't have to, it can just be a couple frames of random scribbles), select the first frame of the timeline by clicking on it.
Then open up the actions panel, usually you can do this by pressing F9.
You should see a big text field with library component on the left, usually the whole things at the top above the timeline and stage (it might open in a new window).
Now, for the first bit of code.

If you were to play your movie right now, it would immediately start playing until it reaches the end, and then it will loop (start over).
With the first frame selected and the actions panel open, we want to place a stopping code.
This will make it so when you preview the movie, it opens up on the first frame not playing.
Basically, the code is:


stop.But that will not work, because it's in english.
All we have to do to translate it is change the syntax, basically the punctuation.
Let's convert it to this:


stop;That still won't work, but I'm explaining it step by step.
The ; is pretty much a period, it signals the end of a line, which could be considered a sentence.
Now we have to add one little detail to get a working code.


stop();The parentheses () have to be there so flash knows what exactly you want to stop.
If you wanted a certain movie clip to stop, and not the frame itself, you would enter that clips name in the parentheses.
You don't have to understand that really, and since we only want to stop the frame, we leave the contents of the parentheses blank.
Leaving it blank mean to apply that code to whatever the code is on, in our case the first frame.

Now test your movie, it should stay on the first frame when you watch it.
Try right clicking and pressing play, see what happens?
When you press play, it overrides the stopping code.
But of course, it would be much better to have a button on your movie so that people don't have to right click and press play.
They may not know how to do that!
So then, let's add a button.
First you gotta draw it out, it doesn't matter what it looks like, as long as it's easy to click.
After you finish drawing it on the first frame, select it and convert it to a Symbol (usually you can press F8).
A window should pop up with some options.
You can choose between Movie Clip, Button, or Graphic.
We want a button, so pick that and press ok (you don't need to name it).
There we go, we have our button, now on to the last part.

Let's add the code to the button, I'll do some step by step translations again.


on release, play the movie.That should make sense in english right?
In case you don't know what on release means, it basically means when the user lets go of clicking, or when the mouse comes up from clicking on the button.
So when they click, it will make the movie play.
Now to change it a bit into AS.


on release, gotoAndPlay;"And what's up with the gotoAndPlay bit??"
Well, it means exactly that.
When something happens (in our case it's the on release part), it will go to something and make it play.
"Well, what is that something?"
We haven't told it what yet.


on (release){
gotoAndPlay();
}"Woah, what happened?"
Well, on (release) is a function.
Functions always work like this:


on (function){
what happens goes here.
}The on (function) says what triggers the code to go off, like a click.
The stuff inside the {}s is what will be triggered, in our case it will trigger the playing of the movie.
"Hey, there's the parentheses again!"
Yup, now that we have the gotoAndPlay part, we have to tell it what exactly to play.
Since gotoAndPlay is a timeline control, we have to specify a Frame Number.
Since frame one won't play because of its code, let's make it skip to frame 2 and start playing.


on (release){
gotoAndPlay(2);
}There, I hope it makes sense, we've finished the play button.
BUT, there's still more.
What about the end of your movie?
Let's try going to the last frame, select that frame and bring up the AS area.
Put in:


stop();Now make a button on that frame, the same way as last time, and make it say "replay" or something.
After you've converted it to a button, put the same code on it as the first button.


on (release){
gotoAndPlay(2);
}There you go!
Try your movie out, it should be pretty snazzy by now, and feel free to copypasta this other places but please include my name!

~Chabitsku Ryoma

Scarecrow
03-25-2008, 07:24 PM
Hey, that'll be pretty useful for newbies. I never really thought of it that way.

Good work.

Index
03-25-2008, 07:40 PM
This'll really help me understand how to make codes. I'm still trying to get the hang of it. Well organized tutorial, I think it's good.

And you really should make a tutorial on how to make those signatures, Cryoma, they're awesome.

Komaru
03-25-2008, 07:41 PM
Shouldn't it be gotoAndPlay with a capital 'And'? I'm pretty sure it won't work otherwise.

Cryoma
03-27-2008, 06:55 PM
Shouldn't it be gotoAndPlay with a capital 'And'? I'm pretty sure it won't work otherwise.

Shouldn't it be gotoAndPlay with a capital 'And'? I'm pretty sure it won't work otherwise.
La typo ....D:
I'mma fix right now.

Chimaera
03-27-2008, 07:10 PM
There's this lil thing called ScriptAsisst.

Kitsune
03-27-2008, 08:55 PM
There's this lil thing called ScriptAsisst.

there's this lil thing called ThatIsNeverUsedUnlessYou'reALazyAssfukWhoCan'tCode .

Cryoma
03-27-2008, 11:06 PM
There's this thing called beinganoobandnotknowingmuchaboutflash.
(besides, it's better to learn the code than to have it done for you.)

Raffi
03-29-2008, 07:29 AM
Instead of using
on (release){
gotoAndPlay();
} You can use
on (release){
play();
}
Good tut though.

Oh, I just realised. I'm a LazyAssfukWhoCan'tCode D;

Gavel
03-29-2008, 09:39 AM
Instead of using
on (release){
gotoAndPlay();
} You can use
on (release){
play();
}
Well sure, if the button you're just making a button that will play from that frame your in. But if you want to make a button that will skip all the way to a frame way down the timeline (which is useful if you have a long intro that people will want to skip through), then you'd use gotoAndPlay();.

Raffi
03-30-2008, 05:22 AM
Yeah, that's true.

Cryoma
03-30-2008, 03:30 PM
Of course it's true.

newcomer
04-26-2008, 07:39 PM
Damn. action script is easier than I thought!

hat-man
05-22-2008, 08:56 PM
nice tut :D How long have you had a stickpage account?

Nikiyolstik
06-03-2008, 04:21 PM
Shouldn't it be gotoAndPlay with a capital 'And'? I'm pretty sure it won't work otherwise.

No, if you write whit a capital letter it will only get blue.

FBFAnimation
06-08-2008, 03:14 PM
Great tutorial. Thanks!

Lixu
06-09-2008, 07:24 AM
Well sure, if the button you're just making a button that will play from that frame your in. But if you want to make a button that will skip all the way to a frame way down the timeline (which is useful if you have a long intro that people will want to skip through), then you'd use gotoAndPlay();.

But if you followed this thread you could see that you can enter 5 between the () so flash knows its frame 5.

Cryoma
07-23-2008, 08:38 PM
Damn. action script is easier than I thought!

That's the spirit!

Cizzil
08-16-2008, 05:09 PM
thanks dude its extremely helpful

wolfears2
08-24-2008, 10:58 AM
Wow cryoma, nice theory. I didn't know you hung out on stickpage though D:

Wtf
08-24-2008, 11:49 AM
That's the spirit!
If this tutorial was just a few years younger, I wouldn't had so much confusion writing scripts.

I love your signature, by the way.

alphastickmania
09-17-2008, 12:43 PM
lol.

This is one of the most beautiful puesdo code to code tutorial I have ever seen.

Too bad the guys who study with me can't appreciate this.

Good stuff, Cryoma.

Cryoma
11-25-2008, 03:50 PM
With all this positive feedback, I believe another tutorial is due.

Hackor Pickel
01-14-2009, 10:39 AM
Nice, i've never really thought of as that way, sure to help the new as users :D

Kieran.
02-09-2009, 02:54 PM
nice tutorial..

Cade
02-10-2009, 07:49 PM
The tutorial was helpful.
That sig is awesome.

Kieran.
02-11-2009, 11:45 AM
lol, I showed this to a flash noob and he found it really helpful... so it really does work...

BumpThisThread
04-13-2010, 07:18 PM
My username must fulfill it's purpose.