Flashas getting started tutorial download page 1/2

Source: Internet
Author: User

Preliminary development of ActionScript Programming

Computer Program Is composed of commands, functions, operators, conditions, loops, and other structures. A command is a series of commands issued for a computer. A function executes computation and return values, and uses operators to combine several data in a specific way, one or more values are tested to return a Boolean value of true or false. The loop structure allows the program to repeatedly execute a series of identical commands.
A variable is a container for storing data. A variable has a variable name and a variable value.
Programming is a task that requires patience. First, you must understand the problem to be solved by a program. Then, you need to break down the problem into several steps and divide each step into smaller steps, until every step is easily solved.
After the program is compiled, there may be many vulnerabilities or defects, so you still need to debug the program until the program runs correctly.
3.1 BASIC program structure
A computer program consists of commands, functions, operators, conditions, loops, and other structures.
3.1.1 commands, functions, and operators
Prior to this, we used keywords to describe elements in ActionScript, such as the keyword gotoandplay, which is also a command.
The command is an element in ActionScript that tells flash how to perform a specific operation. It is called a command because it will be strictly followed. If you want to use gotoandplay to jump to a non-existent frame, such a command cannot be executed.
A command is the most basic element in a program. If you do not use a command in flash, you cannot perform any operation. You will learn many commands from this book.
A function is an element used to execute computation and return results in ActionScript. For example, a specific function can calculate and return the square root of a specified number.
Parameters can be used for both commands and functions. A parameter is a value passed to a command or function. For example, the gotoandplay Command requires at least one frame number or frame tag as the parameter. The function for finding the square root also requires a value as a parameter.
Unlike commands and functions, operators are mainly symbols rather than letters. For example, the + operator adds two numbers.
You will use a large number of commands, functions, and operators in the actionscript program.
3.1.2 Variables
To write complex computer programs, you often need to store a lot of information. Sometimes you only need to store the command for a short period of time. For example, if you need to repeat 10 times to execute the same command, you need to count the number of times the command is executed until it reaches 10 times.
All Programming Language All use variables to store information. A variable consists of two parts: the variable name and the value of the variable.
1. variable name
A variable name is a string consisting of a word or several words, or a letter. In general, you need to specify a meaningful name for the variable as much as possible.
For example, if you want to use a variable to store the user's name, using username as the variable name is a good choice. If you use N as the variable name, it seems a little too short; if you use name, it may be confused with the names of other objects in the video.
An unwritten rule has been formed when a variable name is specified for a variable in ActionScript, that is, the variable name often starts with a lowercase letter. When a new word appears, the first letter of the new word, such as username, is capitalized. For example, currentuserfirstname.
Spaces or special symbols are not allowed in variable names, but numbers are allowed.
2. Variable type
You can use variables to store different types of data. Numbers are the simplest types of variables.
You can store two different types of numbers in the variable: integer and floating point. The integer has no decimal point. For example, 117 and-3685 are all integers. Floating point numbers have decimal points, such as 0.1, 532.23, and-3.7.
You can also store strings in variables. A string is a sequence composed of characters. It can be one or more characters or even no character, that is, an empty string.
Use quotation marks to define a string to distinguish it from other variables. For example, 7 is a number, and "7" is a string, which consists of a character 7.
In other programming languages, you may need to define the specific types of variables to be used in the program in advance at the beginning of the program, but do not need to declare the variables in ActionScript, you only need to use them directly. When flash encounters them for the first time, it will automatically create variables for them.
In addition, there is no strict limitation on the types of data that variables can store. A variable can store strings in one location, while a variable can store numbers in another location.
This flexibility is not often used, but it can reduce unnecessary worries for programmers.
Another issue that programmers do not have to worry about is the space collection of discarded variables. That is, when you no longer need a variable, you may need to reclaim the storage space occupied by the variable. Most modern computer languages such as ActionScript can automatically recycle space, so you don't have to worry about it.
In addition to numbers and strings, there are also some variable data types. For example, an array can store a series of data instead of a single data.
3.1.3 Conditions
The program itself cannot make abstract decisions, but it can obtain data, analyze and compare the data, and then execute different tasks according to the analysis results.
For example, you want to check the name entered by the user and make sure that it contains at least three letters. What the program needs to do is to determine the user name. If there are 3 or more letters, perform one operation. If there are less than 3 letters, execute another operation.
Here, two steps are required to make a decision. The first step is to check whether the condition is met. If the name meets the three letter length and the condition is met, we call the condition value true ); otherwise, the condition is not met. We call the condition value false ). All conditions must be either true or false. The data type of either true or false is called boolean.
The second step is to select which values to execute based on the conditions of true or false. Code . Sometimes there is only one option. If the condition is true, this option is executed. If the condition is false, no code is executed. Sometimes there are two relative options. when the conditions are true and false, different codes are executed respectively.
For example, if you want a computer to execute three different tasks based on the value of one variable: 1, 2, or 3, it can be expressed as follows:
If the value of the variable is equal to 1, Run Command 1.
If the variable value is 2, Run Command 2.
If the value of the variable is 3, Run Command 3.
Conditions are always based on the comparison. You can compare the values of two variables to determine whether they are equal or whether one is greater than the other or less than the other. If the variables are strings, you can compare them in alphabetical order.
3.1.4 Loop
Unlike humans, computers are suitable for repetitive work. One thing can get bored when it is repeated just a few times, but it is still patient if it is used to repeatedly execute thousands of times on a computer.
Loop is a very important part of every programming language, and ActionScript is no exception. You can specify the number of times a command is executed, or make it run until the specified conditions are met.
In fact, conditions are an important part of the loop. The entire loop only requires a start point, an end point, and a condition indicating the end of the loop.
For example, you need to cycle 10 times and use a variable to count from 0. Once every cycle, the count is increased by 1. When the Count variable reaches 10, the loop ends, and the program continues to execute the part after the loop. The following content represents a standard loop structure:
(1) loop previous commands.
(2) When the cycle starts, the Count variable is set to 0.
(3) commands in the loop.
(4) Add 1 to the Count variable.
(5) If the Count variable is less than 10, perform step (3 ).
(6) commands after the loop.
In the preceding steps, steps (1) are executed only once, and steps (2) indicate the start of the loop. Steps (3), (4), and (5) will be executed 10 times, when the cycle ends, execute steps (6) and later.
3.2 corner of ActionScript
When writing your own scripts, you will use a variety of different keywords and symbols. To help you familiarize yourself with the composition of the script, let's take a look at a real example.
This is a script that acts on a button. When you click a button (specifically, when you release the button), execute it. It does not contain special functions, but it reflects the main structure of ActionScript.
On (release ){
VaR mynumber = 7;
VaR mystring = "Flash MX ActionScript ";
For (VAR I = 0; I <mynumber; I ++ ){
Trace (I );
If (I + 3 = 8 ){
Trace (mystring );
}
}
}
Line 1 of the script indicates that the statement in braces is executed when the button is released. The ON (release) structure can only be used for buttons. Other related usage such as on (Press), on (rolover), on (rolout), on (dragover), on (dragout).
Braces {at the end of row 1st indicate the beginning of a relatively independent code segment. The code from {to the opposite} is a whole, and they all belong to the release event of the button.
Note that the Code after braces has a tab (press the tab key once) indentation compared to the code after the 1st line, and the code after each line has the same indentation degree, until a new braces starts, the statement after the new braces adds a tab indent, and so on, which is similar to other programming languages. Flash automatically sets the code you added to the correct indent style.
In line 2 of the Code, create a local variable named mynumber and set the value of this variable to 7. The following line assigns the string Flash MX ActionScript to another variable mystring. We will introduce the two types of variables in detail later: local variables and global variables.
Indicates the end of a command. You must add a semicolon to the end of each complete command.
For indicates the beginning of a loop structure. Here, the loop is executed 7 (mynumber) times, that is, the I is incremented from 0 to 6, and the statement in the loop structure is executed every 1 increments. The section in the braces after for is the loop body.
The command trace sends the content in parentheses following it to the output window. The output window will be detailed in the next section.
If is a condition structure, it tests whether the content I + 3 = 8 is true. If it is true, the subsequent statement is executed; otherwise, the code segment is skipped.
There is only one TRACE command in the IF structure, which sends the value of the variable mystring to the output window.
In the above example, the script ends with three reverse braces}, 1st indicates the end of the IF statement, 2nd indicates the end of The for statement, and 3rd indicates the end of the entire on (Press) segment.
3.3 Output Window
The output window is a programming tool that only appears when you test a Flash video. Flash uses it to Display Error information or other important information. You can use the TRACE command in ActionScript to customize the information to be sent to the output window.
The output window is useful for testing programs. You can use the TRACE command to display the variable value in the output window or which part of the ActionScript is being executed.
The output window can also help you learn ActionScript. You can write some small programs and send the information to the output window, which will help you see the running results of the program.
To familiarize yourself with the output window, the best way is to use it more. Write a small program to send the information to the output window.
(1) Start Flash MX.
(2) Select the 1st frame of the timeline and open the 1st frame action panel.
(3) use the menu in the upper right corner to switch the action panel to EXPERT mode.
(4) click the mouse in the script editing area and place the cursor in the script editing area.
(5) enter the following ActionScript in the action panel:
Trace ("I like ActionScript! ");
In this case, the action panel is shown in 3-1.

Figure 3-1 enter the TRACE command in the Action panel
(6) press Ctrl + enter to test the video. Because there is no image in the stage, you will see a blank window and an output window is displayed, showing I like ActionScript! 3-2.

Figure 3-2 The output window displays information in the TRACE command.
Like the action panel, there is also a drop-down menu in the upper right corner of the output window, as shown in 3-3, which contains commands such as copying, clearing, searching, saving to files, and printing.

Figure 3-3 drop-down menu of the Output Window
The last command in the drop-down menu is "debugging level". You can select one of "error", "warning", and "details". If you select "NONE ", no information is displayed.
3.4 basic ActionScript syntax
The basic structure of the program is introduced. The basic syntax of the program is described below.
3.4.1 Variables
1. Set Variables
The method for using variables in ActionScript is simple. You only need to assign a value to the variable name, for example:
Myvariable = 7;
In this example, when creating a variable named myvariable and setting its value to 7, you can take any name for the variable without using myvariable in this example.
You can use the output window to view the variable value. For example, add the following ActionScript to the action Panel of the first frame of a blank film:
X = 7;
Trace (X );
First, number 7 is stored in variable X. Then, use the TRACE command to send the value of variable X to the output window. When a video is played, the number 7 is displayed in the output window.
2. Global Variables
Variables can be divided into global variables and local variables based on the scope of the variables.
Global variables are variables that can be applied to all depth levels of the entire Flash video. You can set it in a frame, and use and change its value in other frames.
You do not need to use a special method to create a global variable. Just like in the previous example, you can directly set and use it to automatically become a global variable.
In many programming languages, global variables can be used anywhere. A flash video uses a concept called level ). Refresh the main timeline of a video as the root level. Video editing is a small video in the timeline. The graphics and scripts in a video clip are one level lower than the root level. You cannot directly use global variables at the root level for video editing.
3. Local Variables
A local variable can only exist in the current script, but does not exist in other frames. You can create different local variables in Different frames using the same variable name, which will not affect each other.
Local variables can be used to create modular code. After the script is executed, the local variables are deleted from the memory, and the global variables are retained until the video ends.
To create a local variable, you must use the keyword var. For example, the local variable mylocalvariable with the value of 15 is created in the following ActionScript:
Mylocalvariable = 15;
After using VAR to create a local variable, you no longer need to use the keyword VaR in the current Code. For example, the following code creates a local variable mylocalvariable with a value of 20, changes the value to 8, and then sends it to the output window.
VaR mylocalvariable = 20;
Mylocalvariable = 8;
Trace (mylocalvariable );
If you do not have special requirements, use local variables whenever possible.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.