Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Before we cover some of the fundamental structure and logic of ActionScript 3.0, let’s write another script to help get the feel of the language and build a little confidence. Specifically, we’ll build on the Hello World! exercise from Chapter 1 to introduce some of the material explained in detail in this chapter. We’ll give you a brief explanation here and then expand on each relevant topic as you read on. Create a new ActionScript 3.0 FLA file and type the following code into frame 1 using the Actions panel. You can compare your work with the hello_world_if_loop.fla source file.
1 var str:String = "Hello World!";
2
3 if (Math.random() < 0.5) {
4 var txtFld:TextField = new TextField();
5 addChild(txtFld);
6 txtFld.text = str;
7 } else {
8 for (var i:int = 0; i < 3; i++) {
9 trace(str);
10 }
11 }