« Home « Kết quả tìm kiếm

Creating Functions


Tóm tắt Xem thử

- You'll see that the function declaration begins with the word function, followed by the name of the function (which can be anything you choose, as long as it follows typical naming conventions).
- Following the function name is an area enclosed by parentheses.
- You can leave this area blank, or you can fill it with information (parameter data) that the function can use.
- function—that is, one that performs the same way whenever it's called (used).
- Giving the function information in this way is called passing in arguments or passing in.
- Following the optional parameter area is an open curly brace, followed by a carriage return and then some actions before the curly brace that concludes the function.
- In the space between the curly braces, you write the actions that you want your function to perform.
- These actions can also make use of any parameter information passed to the function (as you will see soon)..
- actions) in the Actions panel by clicking Statements >.
- User-Defined Functions, then double-clicking the function command..
- The only difference between this syntax and Syntax 1 is in the way the function name is assigned: the function name appears first, and the syntax for defining how the function.
- When you call a function, you're telling Flash to execute all the actions within that function.
- If parameter1 had a value of cat and parameter2 had a value of 36, then those two values would be sent to the function, for use by the actions within the function definition.
- This would result in the same function's working in a slightly different way from the first example, because the actions within the function would be making use of different parameter values..
- The foregoing examples assume that the function and function call reside on the same timeline.
- To call a function on a specific timeline, you need to place the target path to that timeline in front of the function call, like this:.
- Thus, if aVariableName had a value of "sayHello", the function call would actually look like _root.sayHello();..
- The Actions layer is where you will include all of the ActionScript for this exercise.
- On the TV layer, a movie clip instance named tv_mc has three layers on its timeline: the bottom layer.
- seen when changing channels on the TV..
- On the main timeline, a layer named Remote contains a movie clip instance named remote_mc.
- Inside remote_mc, you'll find a layer that contains most of the remote- control graphics, including a movie clip with an instance name of light_mc, as well as another layer that contains the buttons for the remote.
- Select Frame 1 of the Actions layer on the main timeline.
- With the Actions panel open, add the script:.
- The first line of this script creates a variable named tvPower, which is used to track the current state of the TV.
- A value of true means the television is on.
- The first part of the function uses an if statement to analyze the current value of tvPower.
- If tvPower is true (TV is on) when the function is called, the actions in the function change it to false (off) and set the value of the newChannel variable to 0.
- statement in this manner causes the value of tvPower to be set to its opposite each time the function is called, thus toggling the value of newChannel.
- By the time this statement is finished, newChannel has a value of 0 or 1..
- The function then sends the screen_mc movie clip instance (which is inside the tv_mc movie clip instance) to a frame based on the current value of newChannel + 1.
- You must add 1 to the value of newChannel to prevent the timeline from being sent to Frame 0 (newChannel will sometimes contain a value of 0, and there's no such thing as Frame 0 in a Flash movie timeline).
- In the end, this part of the.
- The function finishes by telling the light on the remote control to play, which causes it to blink, providing a visual indication that a button has been pressed..
- There is now a function on Frame 1 of the main, or root, timeline.
- Although this function contains several actions, none of them is executed until the function is called..
- With the Actions panel still open, add this script to the end of the current actions (after the function definition):.
- Every time the Power button is clicked, the togglePower() function is called, causing the actions within the function to be executed..
- Every time you press the Power button, the togglePower() function is called so that all the actions within that function are performed.
- As mentioned, the actions within the function toggle the state of the TV.

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt