Actionscript For Beginners: Buttons (AS2)

Actionscript For Beginners: Buttons (AS2)

Postby Buttersnack » Thu Aug 13, 2009 5:19 pm

Well, for you starting out, I thought I'd write up something about buttons. Make sure you're using AS2.

First convert something to a button. I hope you know how. Go into its actions, and enter whatever code you want.

Buttons use mouse events, which look like so:

Code: Select all
on (something) {
          whatever you want to happen here
}


The something can be many things, like press. Press will do the action specific as soon as you click the button.

Release. As soon as you release the button.

On keypress. For example, on (keypress(LEFT)) would do the action when you press left.

Etc, etc.

Now, for the action! A bit harder now. I'll start out simple.

Code: Select all
on (press) {
               gotoAndPlay (3)
}


Will go to the 3rd frame when pressed. Or, try variables:

Code: Select all
on (press) {
         score=1
}


I hope for your sake you can figure that out. Multiple actions time.

Code: Select all
on (release) {
   if (_quality == "LOW") {
      _quality = "MEDIUM";
   } else if (_quality == "MEDIUM") {
      _quality = "HIGH";
   } else if (_quality == "HIGH") {
      _quality = "LOW";
   }
}


You don't have to understand that all right now, but it shows that you can make as many things as you want happen from the same button.

But, I'll go in depth on the code anyway.

Code: Select all
on (release) {


Simple part.

Code: Select all
if (_quality == "LOW") {
      _quality = "MEDIUM";


If the quality was lowed before you released it (that's what == is for) the new quality is medium.

Code: Select all
on (release) {
   if (_quality == "LOW") {
      _quality = "MEDIUM";
   } else if (_quality == "MEDIUM") {
      _quality = "HIGH";
   } else if (_quality == "HIGH") {
      _quality = "LOW";
   }
}


Note how each bracket has an open { and a closed }. That begins and ends each statement. Make sure they are placed correctly, and there are enough! And yes, that quality code will really work!
Buttersnack
 
Posts: 54
Joined: Thu Aug 13, 2009 4:58 pm

Re: Actionscript For Beginners: Buttons (AS2)

Postby dark dan21 » Thu Aug 20, 2009 8:46 am

How do you convert something into a button?
Last edited by dark dan21 on Thu Aug 20, 2009 8:47 am, edited 1 time in total.
User avatar
dark dan21
 
Posts: 55
Joined: Thu Aug 13, 2009 11:15 am

Re: Actionscript For Beginners: Buttons (AS2)

Postby Buttersnack » Fri Aug 21, 2009 4:58 pm

...

You're not ready for this tutorial if you don't know that.
Buttersnack
 
Posts: 54
Joined: Thu Aug 13, 2009 4:58 pm

Re: Actionscript For Beginners: Buttons (AS2)

Postby shaduwz » Mon May 03, 2010 9:22 pm

If your using cs3, where you would normally convert to symbol, convert to button instead.
Totus mos cado sub mihi
Friendship is like peeing on yourself: everyone can see it, but only you get the warm feeling that it brings.
User avatar
shaduwz
Moderator-In-Training
 
Posts: 35
Joined: Wed Oct 07, 2009 9:05 pm


Return to ActionScript

Who is online

Users browsing this forum: No registered users and 1 guest

cron