Home
Help
Search
Calendar
Login
Register
Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Click here to join us on IRC (#charas on irc.freenode.net)!
Charas-Project
»
Game Creation
»
Requests
»
Tutorials
»
Flash - ActionScript tutorial 1
« previous
next »
Print
Pages: [
1
]
Author
Topic: Flash - ActionScript tutorial 1 (Read 2884 times)
GaryCXJk
<strong>Official Charas.EX Team Member</strong>
Exemplar
Posts: 1,586
FOUR OH FOUR'D
Flash - ActionScript tutorial 1
«
on:
January 02, 2004, 04:18:57 PM »
Warning! This tutorial doesn't work with Flash MX 2004, since Flash MX 2004 has a sucky new ActionScript thing. I think the guys of Macromedia should shoot themselves in the forehead for completely changing the ActionScript.
The scripts are tested in Flash MX. These codes should work with Flash 5, but I'm not certain.
I will call ActionScript AS from now on, to not confuse people. Also, AS is case sensitive, that means you need to write the capitals too.
ActionScript tutorial 1 - The basics
Well, this is the first AS tutorial here. I'll explain the basics of ActionScripting. I assume you already have the Flash basics, so I'll get on with it.
Okey. You can add AS in two ways. You can do it in Normal Mode or in Expert Mode. I suggest using Expert Mode right now, by pressing Ctrl+Shift+E. This is because you can only type things in Expert Mode, and therefore can also copy and paste things.
The first thing you need to know, where do you add the scripts? There are # things you can add AS to:
A frame;
A button;
A MovieClip (MC)
The most easiest thing to add AS to is a button. Just create a button and select it. Then, click on "Actions"
(if you can't find it on the screen, then click
Windows -> Actions
)
You will now see a window. On the left you can find some actions, on the right you can find the actions. If you can't type something in, then you are still in Normal Mode.
Okey, now type in the following thing:
on(release){
trace("Button was pressed.");
}
Now test the script by pressing Ctrl+Enter or by clicking Control -> Test Movie. If you click your button you will see a new window popping up saying "Button was pressed.". What did you do?
We'll start with the on-command. The on-command can only be used on a button or a MC. This is to specify certain conditions. It works just like the if-command, only, on buttons or MCs the on-command is necessary. The release means that when you pressed the button and released it when still over the button, the following commands (the ones between the two braces { } ) will be executed. There are also other things, but I'll explain later.
trace(...) makes a window pop up that says a message. The trace command only works within Flash. It's mostly used for debugging.
Okey, we want to do something more. Let's make a short animation of 20 frames, but we want to stop it at frame 10, where you can press a button to continue the animation.
I assume you already done that by now, if not, then make 20 frames with an animation and make a button appear at frame 10.
Now how do we want the animation to stop on frame 10? It's simple. You can add AS to a frame. Select frame 10 and add the next script:
stop();
Quite easy, eh? It's also very obvious what this thing does. Also note that the frame doesn't need an on-command. Now test the movie. Impressive, the movie stops at frame 10. But we want to make the button continue playing. What to do? Well, select the button and add the following script:
on(release){
play();
}
This too is obvious, eh? Test your movie. Yay!!! It's working!!!
Now let's make a little game. We want a button to appear and stop in Frame 20 of a 100 frames long movie. When you click the button, you will be sent to frame 100, but when the movie gets to frame 50, you will be brought back to frame 1. So you need to press the button as quickly as possible.
Okey, make the movie. We'll not going to use the stop() command. Instead, add this to frame 50:
gotoAndPlay(1);
What does this do? Well, to say it simple, it goes to frame 1 and plays the movie. Simple. But what about the button? Also, we want to make it stop at frame 100. Is there a gotoAndStop() command? Yes, there is!
on(release){
gotoAndStop(100);
}
Test your movie. Well, it works, but if I hold the button too long, it won't work right. We want it to go to frame 100 the instance you clicked on it. Well, all we have to do is replace the release with press.
on(press){
gotoAndStop(100);
}
This will give you the effect you wanted.
Try to experiment with these things. If you have questions about this lesson, please post it.
Next: MovieClips.
Logged
Play it now!
Charas Breakout DX
Area91: for MUGEN and RPG Maker VX Ace stuff
Print
Pages: [
1
]
« previous
next »
Charas-Project
»
Game Creation
»
Requests
»
Tutorials
»
Flash - ActionScript tutorial 1