[ Pobierz całość w formacie PDF ]
.BooleanA Boolean value is one that is either true or false.ActionScript also converts the values trueand false to 1 and 0 when appropriate.Boolean values are most often used with logicaloperators in ActionScript statements that make comparisons to control the flow of a script.Forexample, in the following script, the SWF file plays if the variable password is true:onClipEvent(enterFrame) {if (userName == true && password == true){play();}}See Using built-in functions on page 51 and Logical operators on page 47.About data types 35ObjectAn object is a collection of properties.Each property has a name and a value.The value of aproperty can be any Flash data type, even the object data type.This allows you to arrange objectsinside each other, or nest them.To specify objects and their properties, you use the dot (.)operator.For example, in the following code, hoursWorked is a property of weeklyStats, whichis a property of employee:employee.weeklyStats.hoursWorkedYou can use the built-in ActionScript objects to access and manipulate specific kinds ofinformation.For example, the Math object has methods that perform mathematical operationson numbers you pass to them.This example uses the sqrt() method:squareRoot = Math.sqrt(100);The ActionScript MovieClip object has methods that let you control movie clip symbol instanceson the Stage.This example uses the play() and nextFrame() methods:mcInstanceName.play();mc2InstanceName.nextFrame();You can also create custom objects to organize information in your Flash application.To addinteractivity to an application with ActionScript, you ll need many different pieces ofinformation: for example, you might need a user s name, the speed of a ball, the names of items ina shopping cart, the number of frames loaded, the user s ZIP Code, or the key that was pressedlast.Creating custom objects lets you organize this information into groups, simplify yourscripting, and reuse your scripts.MovieClipMovie clips are symbols that can play animation in a Flash application.They are the only datatype that refers to a graphic element.The MovieClip data type allows you to control movie clipsymbols using the methods of the MovieClip class.You call the methods using the dot (.)operator, as shown here:my_mc.startDrag(true);parent_mc.getURL("http://www.macromedia.com/support/" + product);NullThe null data type has only one value, null.This value means no value that is, a lack of data.The null value can be used in a variety of situations.Here are some examples:" To indicate that a variable has not yet received a value" To indicate that a variable no longer contains a value" As the return value of a function, to indicate that no value was available to be returned bythe function" As a parameter to a function, to indicate that a parameter is being omittedUndefinedThe undefined data type has one value, undefined, and is used for a variable that hasn t beenassigned a value.36 Chapter 2: ActionScript BasicsDetermining an item s data typeWhile testing and debugging your programs, you may discover problems that seem to be relatedto the data types of different items.In these cases, you may want to determine an item s data type.To do so, use the typeof operator, as shown in this example:trace(typeof(variableName));For more information on testing and debugging, see Chapter 3, Writing and DebuggingScripts, on page 55.Assigning data types to elementsFlash automatically assigns data types to the following kinds of language elements, as discussed inthe next section, Automatic data typing :" Variables" Parameters passed to a function, method, or class" Values returned from a function or method" Objects created as subclasses of existing classesHowever, you can also explicitly assign data types to items, which can help prevent or diagnosecertain errors in your scripts.For more information, see Strict data typing on page 38.Automatic data typingIn Flash, you do not need to explicitly define an item as holding either a number, a string, orother data type.Flash determines the data type of an item when it is assigned:var x = 3;In the expression var x = 3, Flash evaluates the element on the right side of the operator anddetermines that it is of the number data type.A later assignment may change the type of x; forexample, the statement x = "hello" changes the type of x to a string.A variable that hasn t beenassigned a value has a type of undefined.ActionScript converts data types automatically when an expression requires it.For example, whenyou pass a value to the trace() action, trace() automatically converts the value to a string andsends it to the Output panel.In expressions with operators, ActionScript converts data types asneeded; for example, when used with a string, the + operator expects the other operand to bea string
[ Pobierz całość w formacie PDF ]