ActionScript 3.0: Hello World Tutorial
- Launch Adobe Flash CS3
- CTRL+F7 to toggle the components window on and off (you want it visible). Or use Window - Components
- Drag a button onto your canvas.
- Give it an InstanceName of myButton.
- Change the button’s label from Label to Hello.
- Drag a Label onto your canvas.
- Give it an InstanceName of myLabel.
- Change the label’s text from Label to Snoozing or use any other
text you like.The numbered steps above are labelled onto the screen
shot below to indicate where your tasks are located.
Your window will look something like this ..
- Click on your canvas (but not on the button or label) and press F9
to toggle on the Actions - Frame window. If you see this message, read
this instruction again and do it right! “Current selection cannot have
actions applied to it.”
- In the Action - Frame window, enter this code …
myButton.addEventListener(MouseEvent.CLICK, sayHello);function sayHello(e:MouseEvent):void
{
myLabel.text = “Hello World!”;
}
11.Save your work to a well named folder and give your file a meaningful file name.
12.Press CTRL+ENTER to run your Flash Application. If it doesn’t work
correctly, look for mistakes in your code (copy and paste it to reduce
the chances or error). Look for mis-spellings of myButton and myLabel,
both in the code and in the Properties Window.
- Here is the code with explanatory comments.
// This line makes the button listen or wait for mouse clicks.
// When the button feels a mouse click, it calls the sayHello function.
myButton.addEventListener(MouseEvent.CLICK, sayHello);// This is the sayHello function.
// When this function is called, it sets the text property of myLabel to “Hello World!”.
// e:MouseEvent is the click experienced by the button.
// void is used here because this function, although useful, does not return a value.
function sayHello(e:MouseEvent):void
{
myLabel.text = “Hello World!”;
}
Optional tasks: Make your canvas smaller and change the background colour.
-
-
-
- Post Body
-
Looks good, Only thing I could suggest is use some duck typing when naming you variables.
I think what people found the most confusing learning flash was the crazy camel case naming conventions.
-
- Quote
- Posted 5 months ago.
-
-
- Post Body
-
true. Good point & advice Mr. Brown!
-
- Quote
- Posted 5 months ago.
Information
- 470 Views
-
Ratings
Likes
0
Negative
0