In any scripting or programming language, you will need some type of “memory” device something that can remember the values and properties of Objects or significant data. This type of memory device is referred to as a variable. Variables are named storage places for changeable pieces of data (numbers and letters). One of the first obstacles for designers learning a scripting language to overcome is the concept that variable names in and of themselves have no meaning or value to the computer. Remember that the computer can’t perform anything unless you tell it to. Even though any given scripting language has a certain set of “built-in” properties and functions, variables can simplify our scripting workload by creating shortcuts or aliases to other elements of the ActionScript language of the script. One prime example of a shortcut variable is the pathname to a deeply nested Movie Clip instance, such as:
Once pathToEgg is declared and given a value, then we can reuse it without referring to the lengthy path name, as in:
The important concept here is that you could just as easily have given pathToEgg a different name, such as myPath, or robPath, or whatever word(s) you’d like to use. As long as the syntax and formatting of the expression is correct, then you have nothing to worry about.
Variables in Flash are attached to the timeline of the movie or Movie Clip instance on which they are created. If you create a variable x on the Main Timeline, that variable is available for other scripting actions on that timeline. However, from other Movie Clip timelines, the variable is not directly accessible. To access the value of a variable on another timeline (such as a Movie Clip instance), enter the target path to the clip instance in which the variable resides, a dot (.), and then enter the variable name. For instance, this statement sets the variable x to be equal to the value of the variable y in Movie Clip instance named ball:x = _root.ball.y;
Whereas this statement sets the variable y to be equal to the value of the variable x on the Main Timeline:y = _root.x;
In programmer speak, a string is any combination of alphanumeric characters. By themselves, they have no meaning. It is up to you to assign something meaningful to them. For example, giving a variable the name firstName doesn’t mean much. We need to assign a value to the variable firstName to make it meaningful, and we can do something with it. For example, if firstName = “Susan”, then we could make something specific to “Susan” happen. You can also use much simpler name/value pairs, such as i = 0, to keep track of counts. If you want a specific Movie Clip animation to loop only three times, you can increment the value of i by 1 (for example, i = i + 1, i += 1, and i ++ all do the same thing) each time the animation loops back to the start. Then, you can stop the animation when it reaches the value of 3.
Flash uses the term expression to refer to two separate kinds of code fragments in ActionScript. An expression is either (a) a phrase of code used to compare values in a Conditional or a Loop (these are known as conditional expressions), or (b) a snippet of code that is interpreted at runtime (these are known as numeric expressions and string expressions). We discuss conditional expressions later. Numeric and string expressions are essentially just segments of ActionScript code that are dynamically converted to their calculated values when a movie runs. For instance, suppose you have a variable, y, set to a value of 3. In the statement x = y + 1, the y + 1 on the right side of the equal sign is an expression. Hence, when the movie runs, the statement x = y + 1 actually becomes x = 4, because the value of y (which is 3) is retrieved (or “interpreted”) and the calculation 3 + 1 is performed.
Numeric and string expressions are an extremely potent part of ActionScript because they permit nearly any of the options for Actions to be set based on mathematical calculations and external variables rather than requiring fixed information. Consider these two examples:
To change all the URLs in your movie from a staging server to a live server you’d just have to change the value of the server variable. Anywhere that you see the word expression in any Action options, you can use an interpreted ActionScript expression to specify the value of the option. Just enter the code, and then check the Expression option. To use a string inside an expression, simply add quotation marks around it.
Anything surrounded by quotation marks is taken as a literal string. For example, the conditional: if (status == ready) wrongly checks whether the value of the variable status is the same as the value of the nonexistent variable ready. The correct conditional would check whether the value of status is the same as the string “ready” by quoting it, as in: if (status == “ready”).
You can even have expressions that indirectly refer to previously established variables. In Flash 5, you can use the new Dots notation (and array access operators) to indirectly refer to variables, or you can use Flash 4’s eval() function (to maintain backward compatibility).
Array access operators
If you have a variable called name_1, you can write the expression _root[“name_” + “1”] to refer to the value of name_1. How is this useful? If you have more than one variable, but their prefix are the same (for example, name_1, name_2, name_3, and so on), you can write an expression with two variables as a generic statement to refer to any one of the previously established variables: _root[“name” + i], where i can be any predefined number.
Eval( )function and Flash 4’s Set Variable
If you want to use old-fashioned ActionScript to indirectly refer to variable names and values, then you have two ways to go about it:
Variables as declarations
In most scripting languages, you usually don’t have to declare a variable without its value; that is, you don’t need to say variable firstName and then address it again with a value. In Flash, you don’t need to preestablish a variable in order to invoke it. If you want to create a variable on the fly from a Movie Clip to the Main Timeline, you can. Most variables that you use in Flash will be declared in a timeline’s keyframes.
Variables as text fields
Since Flash 4, text could be specified as text fields. A text field can be used as a dynamic text container whose content can be updated via ActionScript and/or the intervention of a server-side script (known in Flash 5 as Dynamic Text), or it can accept input from the user (known in Flash 5 as Input Text).
You can access its properties by selecting a text field and opening the Text Options Panel. In this panel, you can define the parameters of the text variable, including its name. An Input Text field is editable when the Flash movie is played; the user can enter text into the text field. This newly typed text becomes the value of the text field variable. On a login screen, you can create an Input Text field with a name login, where the user enters his/her name, such as Joe. In ActionScript, this would be received as login = “Joe”. Any text that you type into a text field during the authoring process will be that variable’s initial value.
Flash Related Interview Questions
|Adv Java Interview Questions||J2EE Interview Questions|
|Adobe Flex 3 Interview Questions||Dreamweaver Interview Questions|
|3D Animation Interview Questions||Adobe Flash CS6 Interview Questions|
|Dreamweaver CS3 Interview Questions||Adobe Flex Interview Questions|
|Adobe Flex Actionscript Interview Questions||Gif Animation Interview Questions|
|Adobe Fireworks Interview Questions|
Understanding The Flash Framework
Exploring The Interface: Panels, Settings, And More
Using Tools For Navigation And Viewing
Working With Selections And The Pen Tool
Working With The Drawing And Painting Tools
Working With Text
Exploring The Timeline
Checking Out The Library: Symbols And Instances
Drawing In Flash
Animating In Flash
Using Bitmaps And Other Media With Flash
Designing Interfaces And Interface Elements
Understanding Sound For Flash
Importing And Editing Sounds In Flash
Optimizing Flash Sound For Export
Understanding Actions And Event Handlers
Navigating Flash Timelines
Controlling Movie Clips
Sharing And Loading Assets
Planning Code Structures
Creating Subroutines And Manipulating Data
Understanding Movie Clips As Complex Objects
Sending Data In And Out Of Flash
Understanding Html And Text Field Functions In Flash
What Is Generator?
Revving Up Generator
Working With Third-party, Server-side Applications
Working With Raster Graphics
Working With Vector Graphics
Working With Audio Applications
Working With 3d Graphics
Working With Quicktime
Working With Realplayer
Creating Full-motion Video With Flash
Creating Cartoon Animation With Flash
Planning Flash Production With Flowcharting Software
Working With Authoring Applications
Publishing Flash Movies
Integrating Flash Content With Html
Using Players, Projectors, And Screensaver Utilities
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.