Actionscript 3 (Event Listeners Primer)
The goal of this small article is to give an understanding of Events in Actionscript, by creating a small app that will demonstrate the clicking of button and the events that follow.
First we create 4 layers so we can organize what is going on, call them what you wish, if any anyone wants the flas. I will set up a zip for the blog, but the rest of us here is the example.
First layer "Buttons"
Drag 2 instances of the button onto the layer, put them anywhere you want.
Give them unique names "Button_One" and "Button_Two"
We use this names in our small function to give the text box some info.
Second layer for the dynamic text box, you create this using the text tool, and give it the unique name of "buttonName".
Third Layer static text box, you can name whatever, we are this only as a label.
Fourth layer is the script or actionscript layer where all the magic happens:
Here is what is on this layer:
//listeners for the two buttons
var txt:String = e.target.name;
//buttonName.text = txt;
txt = "Button One";
txt = "Button Two";
buttonName.text = txt;
All we doing here is assigning the listener to our buttons, so when we click it; it sends the Event Object a parameter.
If you uncomment trace you will notice the names that we gave the buttons, outputted to the output screen.
All we are doing is using a switch on the name of the button to output the text to the dynamic text box, simple (but we can go over that another time), for now you can see how to use simple events in AS 3.
Now the buttons can be drawn and then used, so total customization is at your disposal.
I know this is quick and dirty, but you can apply this to alot of flash projects and you can see it in another tutorial for a weather app.
Comments are welcome.
More by this Author
Today we are going to learn how to upload a file or image using PHP and a web form. No knowledge of PHP is needed or HTML as the full file structure is included: Build a simple HTML form: Please Choose a File
Today we will be creating a web based address book using PHP and MySql. It will be using the $_GET superglobal, as a means to review the database contents. First, create the database using this sql snippet: ...