Make a basic button in Flash CS4

November 9th, 2009

When I first started learning ActionScript 3.0, one thing I found was, unlike AS2, no one seemed to be putting up the basics of AS3. One of the first things I wanted to do was, of course, make a button. It took a lot of searching but I finally found a blog that just listed the changes that had been made to AS3 from AS2 and since I was pretty good with AS2, I figured it out on my own.

But even now, I still think it’s hard to find info on the basics for Flash CS4 and AS3. And since this is the first blog I’ve ever seriously tried to write, I thought What a great way to practice!

First off, we’re going to create a new Flash file (ActionScript 3.0).

Next draw a square on the stage.

Now we turn the square into symbol. Press F8 or right click on square and select “Convert to Symbol.” Call the name “button” and set the type to “Button”.

Finally, we have to give the button an instance name. This is so the code can access the button when it’s on the stage. In the properties panel, give the button an instance name of “button_btn”.

Now for the code.

First we have to write the function that the button will activate:

function buttonClicked(e:MouseEvent):void
{
trace(“Click”);
}

What this function will do is make “Click” appear in the Output panel every time the button is clicked. You can put whatever code you need inside the function. The trace is just there to make sure the button function is working.

Now we need to add an event listener so that the code will listen for when the button has been clicked. It’s simple and just one line.

button_btn.addEventListener(MouseEvent.CLICK, buttonClicked);

The instance name of the button is the first part of the line. Then we add an event listener to it and inside the event listener we are telling it we are listening for a mouse event, the CLICK is what kind of mouse event and the final part is saying with function to run.

Now press Ctrl-Shift to run the movie and when you click on the button, Click should appear in the output panel!

9 Responses to Make a basic button in Flash CS4

  1. Quidlybidly says:

    Amazing, very amazing topic. I’m going to blog about it also!

  2. uggs canada says:

    Historically, uggs in canada sheepskin boots were worn by pilots to keep their feet as warm as possible in high altitude during World War I and surfers who loved to wear UGG on the beach after they surfed in cold waters.

  3. Women’s Sunrise: These uggs bailey button uk boots have a sleek shape and long shaft, which is said to visually elongate the legs. A favorite color, chestnut suede can also be found at a discount with some online research.

  4. However, if prices are really your concern, there are indeed some websites offering quality uggs australia imitations at very affordable prices. Then the fourth tip is to find reliable website offering nice imitations

  5. Since ugg store become unsex, mens and also kids can find their styles in Ugg Boots.

  6. All the types of cheap genuine uggs have soft genuine sole inside having foam in it that give your feet a soft and warm touch.

  7. Since uggs store uk become unsex, mens and also kids can find their styles in Ugg Boots.

  8. Kevepulnede says:

    and soak up the festive atmosphere. This is an event not to be missed and it runs for 12 days from the 12th- amount of money to augment your closet. This brand guarantees to make you look stunning and glamorous. The They have some pretty unique home accessories and a great deal of inessential bits and bobs from all corners clothes for evening occasions and special events, and Reiss, where the gentlemen can get their fill of compared to the other great shopping venues in the UK, but the stores are mostly upscale, first-class and tartans, tweeds and basically anything Scottish, even bagpipes!No shopping trip to Edinburgh is complete

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>