ActionScript Language Reference
Trademarks Add Life to the Web, Afterburner, Aftershock, Andromedia, Allaire, Animation PowerPack, Aria, Attain, Authorware, Authorware Star, Backstage, Bright Tiger, Clustercats, ColdFusion, Contribute, Design In Motion, Director, Dream Templates, Dreamweaver, Drumbeat 2000, EDJE, EJIPT, Extreme 3D, Fireworks, Flash, Flash Lite, Flex, Fontographer, FreeHand, Generator, HomeSite, JFusion, JRun, Kawa, Know Your Site, Knowledge Objects, Knowledge Stream, Knowledge Track, LikeMinds, Lingo, Live Effects, MacRec
CONTENTS CHAPTER 1: Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Sample entry for most ActionScript elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Sample entry for classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Examples Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 CHAPTER 2: ActionScript Language Reference .
+ (addition) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 += (addition assignment) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 < (less than) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 << (bitwise left shift) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Button._height . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Button.menu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Button._name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Button.onDragOut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Button.onDragOver . . . . . . . . . . .
Camera.setQuality() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 Camera.width . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 clearInterval() . . . .
Date.setFullYear() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Date.setHours(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 Date.setMilliseconds() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 Date.setMinutes() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 Date.setMonth() . . . . . . . . . . . .
implements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 #include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330 Infinity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332 #initclip. . . . .
LoadVars.onData. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392 LoadVars.onLoad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393 LoadVars.send(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 LoadVars.sendAndLoad() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397 LoadVars.toString() . . . . . . . . . . . . . . .
Microphone.rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460 Microphone.setGain() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 Microphone.setRate() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462 Microphone.setSilenceLevel() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464 Microphone.setUseEchoSuppression(). . . . . . . . . .
MovieClip.hitTest() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534 MovieClip.lineStyle() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536 MovieClip.lineTo() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537 MovieClip.loadMovie() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 MovieClip.loadVariables() . . . . . . . . . . .
MovieClip._visible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592 MovieClip._width . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 MovieClip._x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594 MovieClip._xmouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595 MovieClip._xscale . . . . . . . . . . . . . .
Object() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659 Object class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 660 Object.addProperty() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662 Object.constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665 Object.__proto__ . . . . . . . . .
SharedObject.data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738 SharedObject.flush() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740 SharedObject.getLocal() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742 SharedObject.getSize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745 SharedObject.onStatus . . . . . . . . . . . . .
String.substr() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806 String.substring(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807 String.toLowerCase(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808 String.toUpperCase() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 809 " " (string delimiter) . . . . . . . .
TextField.StyleSheet.parseCSS() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866 TextField.StyleSheet.setStyle() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867 TextField.StyleSheet.transform() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869 TextField class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 870 TextField.addListener() . . . . . . . . . . . . . . . .
TextField._target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925 TextField.text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 926 TextField.textColor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 927 TextField.textHeight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 928 TextField.textWidth . . . . . . . .
undefined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 989 unescape() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991 unloadMovie(). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 992 unloadMovieNum() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993 updateAfterEvent() . . . . . . . .
XMLNode class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XMLSocket class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XMLSocket.close() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XMLSocket.connect() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . XMLSocket.onClose . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents
CHAPTER 1 Introduction This manual describes the syntax and use of ActionScript elements in Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004. To use examples in a script, copy the code example from this book and paste it into the Script pane or into an external script file. The manual lists all ActionScript elements—operators, keywords, statements, actions, properties, functions, classes, and methods. Note: The examples are written in ActionScript 2.
Availability Unless otherwise noted, the Availability section tells which versions of Flash Player support the element. The supported Flash Player version is not the same as the version of Flash used to author the content. For example, if you use Macromedia Flash MX 2004 or Macromedia Flash MX Professional 2004 to create content for Flash Player 6, you can use only ActionScript elements that are available to Flash Player 6.
Method and property summary tables Each class entry contains a table listing all of the associated methods. If the class has properties (often constants), event handlers, or event listeners, these elements are summarized in additional tables. All the elements listed in these tables also have their own entries, which follow the class entry. Constructor If a class requires that you use a constructor to access its methods and properties, the constructor is described in each class entry.
Chapter 1: Introduction
CHAPTER 2 ActionScript Language Reference –– (decrement) Availability Flash Player 4. Usage ––expression expression–– Parameters expression A number or a variable that evaluates to a number. Returns A number. Description Operator (arithmetic); a pre-decrement and post-decrement unary operator that subtracts 1 from the expression. The expression can be a variable, element in an array, or property of an object.
The following example loops from 10 to 1, and each iteration of the loop decreases the counter variable i by 1.
++ (increment) Availability Flash Player 4. Usage ++expression expression++ Parameters expression A number or a variable that evaluates to a number. Returns A number. Description Operator (arithmetic); a pre-increment and post-increment unary operator that adds 1 to expression. The expression can be a variable, element in an array, or property of an object. The pre-increment form of the operator (++expression) adds 1 to expression and returns the result.
this is execution 5 */ The following example uses ++ as a pre-increment operator: var a:Array = []; // var a:Array = new Array(); var i:Number = 0; while (i<10) { a.push(++i); } trace(a.toString());//traces: 1,2,3,4,5,6,7,8,9,10 This example also uses ++ as a pre-increment operator. var a:Array = []; for (var i = 1; i<=10; ++i) { a.push(i); } trace(a.
! (logical NOT) Availability Flash Player 4. Usage !expression Parameters expression An expression or a variable that evaluates to a Boolean value. Returns A Boolean value. Description Operator (logical); inverts the Boolean value of a variable or expression. If expression is a variable with the absolute or converted value true, the value of !expression is false. If the expression x && y evaluates to false, the expression !(x && y) evaluates to true.
!= (inequality) Availability Flash Player 5. Usage expression1 != expression2 Parameters None. Returns A Boolean value. Description Operator (inequality); tests for the exact opposite of the equality (==) operator. If expression1 is equal to expression2, the result is false. As with the equality (==) operator, the definition of equal depends on the data types being compared, as illustrated in the following list: • Numbers, strings, and Boolean values are compared by value.
trace("foo"); }; var b:Function = function() { trace("foo"); }; a(); // foo b(); // foo trace(a!=b); // true a = b; a(); // foo b(); // foo trace(a!=b); // false // trace statement output: foo foo true foo foo false The following example illustrates comparison by reference with two arrays: var a:Array = [ var b:Array = [ trace(a); // 1, trace(b); // 1, trace(a!=b); // a = b; trace(a); // 1, trace(b); // 1, trace(a!=b); // 1, 2, 3 ]; 1, 2, 3 ]; 2, 3 2, 3 true 2, 3 2, 3 false // trace statement output: 1,2
!== (strict inequality) Availability Flash Player 6. Usage expression1 !== expression2 Parameters None. Returns A Boolean value. Description Operator; tests for the exact opposite of the strict equality (===) operator. The strict inequality operator performs the same as the inequality operator except that data types are not converted. For more information, see “Automatic data typing” in Using ActionScript in Flash.
trace(s1 !== n); trace(s1 !== b); // true // true See also ! (logical NOT), != (inequality), && (logical AND), || (logical OR), == (equality), === (strict equality) !== (strict inequality) 33
% (modulo) Availability Flash Player 4. In Flash 4 files, the % operator is expanded in the SWF file as x - int(x/y) * y and may not be as fast or as accurate in later versions of Flash Player. Usage expression1 % expression2 Parameters None. Returns A number. Description Operator (arithmetic); calculates the remainder of expression1 divided by expression2. If either of the expression parameters are non-numeric, the modulo (%) operator attempts to convert them to numbers.
%= (modulo assignment) Availability Flash Player 4. Usage expression1 %= expression2 Parameters None. Returns A number. Description Operator (arithmetic compound assignment); assigns expression1 the value of expression1 % expression2. The following two expressions are equivalent: x %= y x = x % y For more information, see “Operator precedence and associativity” in Using ActionScript in Flash.
& (bitwise AND) Availability Flash Player 5. In Flash 4, the AND (&) operator was used for concatenating strings. In Flash 5 and later, the AND (&) operator is a bitwise AND, and you must use the addition (+) operator to concatenate strings. Flash 4 files that use the AND (&) operator are automatically updated to use addition (+) operator when imported into the Flash 5 or later authoring environment. Usage expression1 & expression2 Parameters None. Returns A 32-bit integer.
trace(0xFFFFFFFF & -1); // -1 trace(4294967295 & -1); // -1 trace(4294967295 & 4294967295); // -1 See Also &= (bitwise AND assignment), ^ (bitwise XOR), ^= (bitwise XOR assignment), | (bitwise OR), |= (bitwise OR assignment), ~ (bitwise NOT) & (bitwise AND) 37
&& (logical AND) Availability Flash Player 4. Usage expression1 && expression2 Parameters None. Returns A Boolean value. Description Operator (logical); performs a Boolean operation on the values of one or both of the expressions. Evaluates expression1 (the expression on the left side of the operator) and returns false if the expression evaluates to false. If expression1 evaluates to true, expression2 (the expression on the right side of the operator) is evaluated.
See also ! (logical NOT), != (inequality), !== (strict inequality), || (logical OR), == (equality), === (strict equality) && (logical AND) 39
&= (bitwise AND assignment) Availability Flash Player 5. Usage expression1 &= expression2 Parameters None. Returns A 32-bit integer; the value of expression1 & expression2. Description Operator; assigns expression1 the value of expression1 & expression2. For example, the following two expressions are equivalent: x &= y; x = x & y; For more information, see “Operator precedence and associativity” in Using ActionScript in Flash.
() (parentheses) Availability Flash Player 4. Usage (expression1 [, expression2]) (expression1, expression2) function(parameter1,..., parameterN) Parameters expression1, expression2 function Numbers, strings, variables, or text. The function to be performed on the contents of the parentheses. parameter1...parameterN A series of parameters to execute before the results are passed as parameters to the function outside the parentheses. Returns Nothing.
function foo() { a += b; } function bar() { b *= 10; } trace((foo(), bar(), a+b)); // outputs 23 Usage 3: The following example shows the use of parentheses with functions: var today:Date = new Date(); trace(today.
– (minus) Availability Flash Player 4. Usage (Negation) -expression (Subtraction) expression1 - expression2 Parameters None. Returns An integer or floating-point number. Description Operator (arithmetic); used for negating or subtracting. Usage 1: When used for negating, it reverses the sign of the numerical expression. Usage 2: When used for subtracting, it performs an arithmetic subtraction on two numerical expressions, subtracting expression2 from expression1.
* (multiplication) Availability Flash Player 4. Usage expression1 * expression2 Parameters None. Returns An integer or floating-point number. Description Operator (arithmetic); multiplies two numerical expressions. If both expressions are integers, the product is an integer. If either or both expressions are floating-point numbers, the product is a floating-point number. For more information, see “Operator precedence and associativity” in Using ActionScript in Flash.
*= (multiplication assignment) Availability Flash Player 4. Usage expression1 *= expression2 Parameters None. Returns The value of expression1 * expression2. If an expression cannot be converted to a numeric value, it returns NaN (not a number). Description Operator (arithmetic compound assignment); assigns expression1 the value of expression1 * expression2.
, (comma) Availability Flash Player 4. Usage (expression1, expression2 [, expressionN...]) Parameters None. Returns The value of expression1, expression2, and so on. Description Operator; evaluates expression1, then expression2, and so on. This operator is primarily used with the for loop statement and is often used with the parentheses () operator. For more information, see “Operator precedence and associativity” in Using ActionScript in Flash.
v = v + 4 , z++, v + 6; trace(v); // output: 4 trace(z); // output: 1 The following example is identical to the previous example except for the addition of the parentheses () operator and illustrates once again that, when used with the parentheses () operator, the comma (,) operator returns the value of the last expression in the series: var v:Number = 0; var z:Number = 0; v = (v + 4, z++, v + 6); trace(v); // output: 6 trace(z); // output: 1 See also () (parentheses) , (comma) 47
. (dot) Availability Flash Player 4. Usage object.property_or_method instancename.variable instancename.childinstance instancename.childinstance.variable Parameters An instance of a class. The object can be an instance of any of the built-in ActionScript classes or a custom class. This parameter is always to the left of the dot (.) operator. object The name of a property or method associated with an object.
this.createEmptyMovieClip("container_mc", this.getNextHighestDepth()); this.container_mc.createTextField("date_txt", this.getNextHighestDepth(), 0, 0, 100, 22); this.container_mc.date_txt.autoSize = true; this.container_mc.date_txt.text = new Date(); The dot (.) operator is used when targeting instances within the SWF file and when you need to set properties and values for those instances. .
: (type) Availability Flash Player 6. Usage [modifiers] var variableName:type function functionName():type { ... } function functionName(parameter1:type, ... , parameterN:type) [ :type ]{ ... } Note: To use this operator, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. Parameters variableName type An identifier for a variable. A native data type, class name that you have defined, or interface name.
Usage 2: The following example shows how to specify a function’s parameter type by defining a function named randomInt() that takes a parameter named integer of type Number: function randomInt(integer:Number):Number { return Math.round(Math.
?: (conditional) Availability Flash Player 4. Usage expression1 ? expression2 : expression3 Parameters expression1 An expression that evaluates to a Boolean value; usually a comparison expression, such as x < 5. expression2, expression3 Values of any type. Returns The value of expression2 or expression3. Description Operator; instructs Flash to evaluate expression1, and if the value of expression1 is true, it returns the value of expression2; otherwise it returns the value of expression3.
/ (division) Availability Flash Player 4. Usage expression1 / expression2 Parameters expression A number or a variable that evaluates to a number. Returns A floating-point number. Description Operator (arithmetic); divides expression1 by expression2. The result of the division operation is a double-precision floating-point number. For more information, see “Operator precedence and associativity” in Using ActionScript in Flash.
// (comment delimiter) Availability Flash 1. Usage // comment Parameters comment Any characters. Returns Nothing. Description Comment; indicates the beginning of a script comment. Any characters that appear between the comment delimiter (//) and the end-of-line character are interpreted as a comment and ignored by the ActionScript interpreter. For more information, see “Deprecated Flash 4 operators” in Using ActionScript in Flash.
/* (comment delimiter) Availability Flash Player 5. Usage /* comment */ /* comment comment */ Parameters comment Any characters. Returns Nothing. Description Comment; indicates one or more lines of script comments. Any characters that appear between the opening comment tag (/*) and the closing comment tag (*/), are interpreted as a comment and ignored by the ActionScript interpreter. Use the // (comment delimiter) to identify single-line comments.
/= (division assignment) Availability Flash Player 4. Usage expression1 /= expression2 Parameters expression1,expression2 A number or a variable that evaluates to a number. Returns A number. Description Operator (arithmetic compound assignment); assigns expression1 the value of expression1 / expression2. For example, the following two statements are equivalent: x /= y x = x / y For more information, see “Operator precedence and associativity” in Using ActionScript in Flash.
[] (array access) Availability Flash Player 4. Usage myArray = [a0, a1,...aN] myArray[i] = value myObject[propertyName] Parameters myArray The name of an array. a0, a1,...aN i Elements in an array; any native type or object instance, including nested arrays. An integer index greater than or equal to 0. myObject The name of an object. propertyName A string that names a property of the object. Returns Usage 1: A reference to an array.
Usage 2: Surround the index of each element with brackets ([]) to access it directly; you can add a new element to an array, or you can change or retrieve the value of an existing element.
In the following example, the expression inside the brackets is evaluated, and the result is used as the name of the variable to be retrieved from movie clip name_mc: name_mc["A" + i]; If you are familiar with the Flash 4 ActionScript slash syntax, you can use the eval() function to accomplish the same result: eval("name_mc.
^ (bitwise XOR) Availability Flash Player 5. Usage expression1 ^ expression2 Parameters expression1,expression2 A number. Returns A 32-bit integer. Description Operator (bitwise); converts expression1 and expression2 to 32-bit unsigned integers, and returns a 1 in each bit position where the corresponding bits in expression1 or expression2, but not both, are 1. Floating-point numbers are converted to integers by discarding any digits after the decimal point. The result is a new 32-bit integer.
^= (bitwise XOR assignment) Availability Flash Player 5. Usage expression1 ^= expression2 Parameters expression1,expression2 Integers and variables. Returns A 32-bit integer. Specifically, the value of expression1 ^ expression2. Description Operator (bitwise compound assignment); assigns expression1 the value of expression1 ^ expression2.
{} (object initializer) Availability Flash Player 5. Usage object = {name1: value1, name2: value2,...nameN: valueN} {expression1; [...expressionN]} Parameters object The object to create. name1,2,...N value1,2,...N The names of the properties. The corresponding values for each name property. Returns Usage 1: An Object object. Usage 2: Nothing, except when a function has an explicit return statement, in which case the return type is specified in the function implementation.
The following example shows how array and object initializers can be nested within each other: var person:Object = {name:"Gina Vechio", children:["Ruby", "Chickie", "Puppa"]}; The following example uses the information in the previous example and produces the same result using constructor functions: var person:Object = new Object(); person.name = "Gina Vechio"; person.children = new Array(); person.children[0] = "Ruby"; person.children[1] = "Chickie"; person.
| (bitwise OR) Availability Flash Player 5. Usage expression1 | expression2 Parameters expression1,expression2 A number. Returns A 32-bit integer. Description Operator (bitwise); converts expression1 and expression2 to 32-bit unsigned integers, and returns a 1 in each bit position where the corresponding bits of either expression1 or expression2 are 1. Floating-point numbers are converted to integers by discarding any digits after the decimal point. The result is a new 32-bit integer.
|| (logical OR) Availability Flash Player 4. Usage expression1 || expression2 Parameters expression1, expression2 A Boolean value or an expression that converts to a Boolean value. Returns A Boolean value. Description Operator (logical); evaluates expression1 (the expression on the left side of the operator) and returns true if the expression evaluates to true. If expression1 evaluates to false, expression2 (the expression on the right side of the operator) is evaluated.
} function fx2():Boolean { trace("fx2 called"); return true; } if (fx1() || fx2()) { trace("IF statement entered"); } /* The following is sent to the Output panel: fx1 called IF statement entered */ See also ! (logical NOT), != (inequality), !== (strict inequality), && (logical AND), == (equality), === (strict equality) 66 Chapter 2: ActionScript Language Reference
|= (bitwise OR assignment) Availability Flash Player 5. Usage expression1 |= expression2 Parameters expression1,expression2 A number or variable. Returns An integer. Description Operator (bitwise compound assignment); assigns expression1 the value of expression1 | For example, the following two statements are equivalent: expression2. x |= y; x = x | y; For more information, see “Operator precedence and associativity” in Using ActionScript in Flash.
~ (bitwise NOT) Availability Flash Player 5. Usage ~ expression Parameters expression A number. Returns A 32-bit integer. Description Operator (bitwise); also known as the one’s complement operator or the bitwise complement operator. Converts the expression to a 32-bit signed integer, and then applies a bitwise one’s complement. That is, every bit that is a 0 is set to 1 in the result, and every bit that is a 1 is set to 0 in the result. The result is a signed 32-bit integer.
/* To set the read-only flag in the flags variable, the following code uses the bitwise OR: */ flags |= ReadOnlyFlag; trace(flags); /* To clear the read-only flag in the flags variable, first construct a mask by using bitwise NOT on ReadOnlyFlag. In the mask, every bit is a 1 except for the read-only flag. Then, use bitwise AND with the mask to clear the readonly flag.
+ (addition) Availability Flash Player 4; Flash Player 5.In Flash 5 and later, + is either a numeric operator or a string concatenator depending on the data type of the parameter. In Flash 4, + is only a numeric operator. Flash 4 files that are brought into the Flash 5 or later authoring environment undergo a conversion process to maintain data type integrity.
Usage 3: Variables associated with dynamic and input text fields have the data type String. In the following example, the variable deposit is an input text field on the Stage. After a user enters a deposit amount, the script attempts to add deposit to oldBalance. However, because deposit is a String data type, the script concatenates (combines to form one string) the variable values rather than summing them. var oldBalance:Number = 1345.23; var currentBalance = deposit_txt.
+= (addition assignment) Availability Flash Player 4. Usage expression1 += expression2 Parameters expression1,expression2 A number or string. Returns A string or a number. Description Operator (arithmetic compound assignment); assigns expression1 the value of expression1 + expression2. For example, the following two statements have the same result: x += y; x = x + y; This operator also performs string concatenation.
< (less than) Availability Flash Player 4; Flash Player 5. In Flash 5 and later, the < (less than) operator is a comparison operator capable of handling various data types. In Flash 4, < is an numeric operator. Flash 4 files that are brought into the Flash 5 or later authoring environment undergo a conversion process to maintain data type integrity. The following illustrates the conversion of a Flash 4 file containing a numeric quality comparison.
<< (bitwise left shift) Availability Flash Player 5. Usage expression1 << expression2 Parameters expression1 A number or expression to be shifted left. expression2 A number or expression that converts to an integer from 0 to 31. Returns A 32-bit integer. Description Operator (bitwise); converts expression1 and expression2 to 32-bit integers, and shifts all the bits in expression1 to the left by the number of places specified by the integer resulting from the conversion of expression2.
If you trace the following example, you see that the bits have been pushed two spaces to the left: // 2 binary == 0010 // 8 binary == 1000 trace(2 << 2); // output: 8 See also >>= (bitwise right shift and assignment), >> (bitwise right shift), <<= (bitwise left shift and assignment), >>> (bitwise unsigned right shift), >>>= (bitwise unsigned right shift and assignment) << (bitwise left shift) 75
<<= (bitwise left shift and assignment) Availability Flash Player 5. Usage expression1 <<= expression2 Parameters expression1 A number or expression to be shifted left. expression2 A number or expression that converts to an integer from 0 to 31. Returns A 32-bit integer. Description Operator (bitwise compound assignment); this operator performs a bitwise left shift (<<=) operation and stores the contents as a result in expression1.
<= (less than or equal to) Availability Flash Player 4. In Flash 5 or later, the less than or equal to (<=) operator is a comparison operator capable of handling various data types. In Flash 4, <= is a numeric operator. Flash 4 files that are brought into the Flash 5 or later authoring environment undergo a conversion process to maintain data type integrity. The following illustrates the conversion of a Flash 4 file containing a numeric quality comparison.
= (assignment) Availability Flash Player 4. In Flash 5 or later, = is an assignment operator, and the == operator is used to evaluate equality. In Flash 4, = is a numeric equality operator. Flash 4 files that are brought into the Flash 5 or later authoring environment undergo a conversion process to maintain data type integrity.
The following example uses assignment by reference to create the moonsOfJupiter variable, which contains a reference to a newly created Array object. Assignment by value is then used to copy the value "Callisto" to the first element of the array referenced by the variable moonsOfJupiter: var moonsOfJupiter:Array = new Array(); moonsOfJupiter[0] = "Callisto"; The following example uses assignment by reference to create a new object, and assign a reference to that object to the variable neptune.
-= (subtraction assignment) Availability Flash Player 4. Usage expression1 -= expression2 Parameters expression1,expression2 A number or expression that evaluates to a number. Returns A number. Description Operator (arithmetic compound assignment); assigns expression1 the value of expression1 expression2. For example, the following two statements are equivalent: x -= y; x = x - y; String expressions must be converted to numbers; otherwise, NaN (not a number) is returned.
== (equality) Availability Flash Player 5. Usage expression1 == expression2 Parameters expression1,expression2 A number, string, Boolean value, variable, object, array, or function. Returns A Boolean value. Description Operator (equality); tests two expressions for equality. The result is true if the expressions are equal. The definition of equal depends on the data type of the parameter: • Numbers and Boolean values are compared by value and are considered equal if they have the same value.
var y:String = "steve"; trace(x == y); // output: false The following examples show comparison by reference. The first example compares two arrays with identical length and elements. The equality operator will return false for these two arrays. Although the arrays appear equal, comparison by reference requires that they both refer to the same array. The second example creates the thirdArray variable, which points to the same array as the variable firstArray.
=== (strict equality) Availability Flash Player 6. Usage expression1 === expression2 Returns A Boolean value. Description Operator; tests two expressions for equality; the strict equality (===)operator performs in the same way as the equality (==) operator, except that data types are not converted. (For more information, see “Automatic data typing” in Using ActionScript in Flash.) The result is true if both expressions, including their data types, are equal.
// Automatic data typing in this example converts false to “0” var string1:String = "0"; var bool2:Boolean = false; trace(string1 == bool2); // true trace(string1 === bool2); // false The following examples show how strict equality treats variables that are references differently than it treats variables that contain literal values. This is one reason to consistently use String literals and to avoid the use of the new operator with the String class.
> (greater than) Availability Flash Player 4. In Flash 5 or later, the greater-than (>) operator is a comparison operator capable of handling various data types. In Flash 4, > is a numeric operator. Flash 4 files that are brought into the Flash 5 or later authoring environment undergo a conversion process to maintain data type integrity. The following illustrates the conversion of a Flash 4 file containing a numeric quality comparison.
>= (greater than or equal to) Availability Flash Player 4. In Flash 5 or later, the greater than or equal to (>=) operator is a comparison operator capable of handling various data types. In Flash 4, >= is a numeric operator. Flash 4 files that are brought into the Flash 5 or later authoring environment undergo a conversion process to maintain data type integrity. The following illustrates the conversion of a Flash 4 file containing a numeric quality comparison.
>> (bitwise right shift) Availability Flash Player 5. Usage expression1 >> expression2 Parameters expression1 A number or expression to be shifted right. expression2 A number or expression that converts to an integer from 0 to 31. Returns A 32-bit integer. Description Operator (bitwise); converts expression1 and expression2 to 32-bit integers, and shifts all the bits in expression1 to the right by the number of places specified by the integer that results from the conversion of expression2.
The following example converts -1 to a 32-bit integer and shifts it 1 bit to the right: var x:Number = -1 >> 1; trace(x); // outputs -1 The following example shows the result of the previous example: var x:Number = -1 This is because -1 decimal equals 11111111111111111111111111111111 binary (thirty-two 1’s), shifting right by one bit causes the least significant (bit farthest to the right) to be discarded and the most significant bit to be filled in with 1.
>>= (bitwise right shift and assignment) Availability Flash Player 5. Usage expression1 >>= expression2 Parameters expression1 A number or expression to be shifted right. expression2 A number or expression that converts to an integer from 0 to 31. Returns A 32-bit integer. Description Operator (bitwise compound assignment); this operator performs a bitwise right-shift operation and stores the contents as a result in expression1.
>>> (bitwise unsigned right shift) Availability Flash Player 5. Usage expression1 >>> expression2 Parameters expression1 A number or expression to be shifted right. expression2 A number or expression that converts to an integer between 0 and 31. Returns A 32-bit unsigned integer. Description Operator (bitwise); the same as the bitwise right shift (>>) operator except that it does not preserve the sign of the original expression because the bits on the left are always filled with 0.
>>>= (bitwise unsigned right shift and assignment) Availability Flash Player 5. Usage expression1 >>>= expression2 Parameters expression1 A number or expression to be shifted left. expression2 A number or expression that converts to an integer from 0 to 31. Returns A 32-bit integer. Description Operator (bitwise compound assignment); performs an unsigned bitwise right-shift operation and stores the contents as a result in expression1.
Accessibility class CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Description The Accessibility class manages communication with screen readers. Screen readers are a type of assistive technology for visually impaired users that provides an audio version of screen content. The methods of the Accessibility class are static—that is, you don’t have to create an instance of the class to use its methods.
Accessibility.isActive() Availability Flash Player 6. Usage Accessibility.isActive() : Boolean Parameters None. Returns A Boolean value: true if the Flash Player is communicating with an accessibility aid (usually a screen reader); false otherwise. Description Method; indicates whether an accessibility aid is currently active and the player is communicating with it. Use this method when you want your application to behave differently in the presence of a screen reader or other accessibility aid.
Accessibility.updateProperties() Availability Flash Player 6 (6.0.65). Usage Accessibility.updateProperties() : Void Parameters None. Returns Nothing. Description Method; causes all changes to _accProps (accessibility properties) objects to take effect. For information on setting accessibility properties, see _accProps. If you modify the accessibility properties for multiple objects, only one call to Accessibility.
CHAPTER 2 ActionScript Language Reference _accProps Availability Flash Player 6.65. Usage _accProps.propertyName instanceName._accProps.propertyName Parameters propertyName An accessibility property name (see the following description for valid names). The instance name assigned to an instance of a movie clip, button, dynamic text field, or input text field. To refer to the _accProps object that represents the entire Flash document, omit instanceName.
Property Data type Equivalent in Accessibility panel Applies to description String Description Whole SWF files Movie clips Buttons Dynamic text Input text shortcut String Shortcut* Movie clips Buttons Input text * For the Shortcut field, use names of the form Control+A. Adding a keyboard shortcut to the Accessibility panel doesn’t create a keyboard shortcut; it merely advises screen readers of an existing shortcut.
If you don’t specify an accessibility property for a document or an object, any values set in the Accessibility panel are implemented. After you specify an accessibility property, you can’t revert its value to a value set in the Accessibility panel. However, you can set the property to its default value (false for Boolean values; empty strings for string values) by deleting the property from the _accProps object, as shown in the following example: my_mc._accProps.
CHAPTER 2 ActionScript Language Reference arguments object Availability Flash Player 5; property added in Flash Player 6. Description The arguments object is an array that contains the values that were passed as parameters to any function. Each time a function is called in ActionScript, an arguments object is automatically created for that function. A local variable, arguments, is also created and lets you refer to the arguments object.
arguments.callee Availability Flash Player 5. Usage arguments.callee:Function Description Property; refers to the function that is currently being called. Example You can use the arguments.callee property to make an anonymous function that is recursive, as shown in the following example: factorial = function (x:Number) { if (x<=1) { return 1; } else { return x*arguments.
arguments.caller Availability Flash Player 6. Usage arguments.caller:Function Description Property; refers to the calling function. The value of this property is null if the current function was not called by another function.
arguments.length Availability Flash Player 5. Usage arguments.length:Number Description Property; the number of parameters actually passed to a function. Example The following ActionScript includes a function called getArgLength, which returns the number of arguments that are passed into the function. Although the method expects three arguments, you can pass as many arguments as you want. function getArgLength(param_arg1:String, param_arg2:String, param_arg3:String) { return (arguments.
CHAPTER 2 ActionScript Language Reference Array() Availability Flash Player 6. Usage Array() : Array Array(numElements:Number) : Array Array( [element0:Object [, element1 , element2,...elementN ] ]) : Array Parameters element One or more elements to place in the array. Returns An array. Description Conversion function; creates a new, empty array or converts specified elements to an array.
CHAPTER 2 ActionScript Language Reference Array class Availability Flash Player 5 (became a native object in Flash Player 6, which improved performance significantly). Description The Array class lets you access and manipulate arrays. An array is an object whose properties are identified by a number representing their position in the array. This number is referred to as the index. All arrays are zero-based, which means that the first element in the array is [0], the second element is [1], and so on.
Constructor for the Array class Availability Flash Player 5. Usage new Array() : Array new Array(length:Number) : Array new Array(element0, element1, element2,...elementN) : Array Parameters length An integer that specifies the number of elements in the array. A list of two or more arbitrary values. The values can be of type Boolean, Number, String, Object, or Array. The first element in an array always has an index or position of 0. element0...
Usage 3: The following example creates the new Array object go_gos_array with an initial length of 5: var go_gos_array:Array = new Array("Belinda", "Gina", "Kathy", "Charlotte", "Jane"); trace(go_gos_array.length); // returns 5 trace(go_gos_array.
Array.concat() Availability Flash Player 5. Usage my_array.concat( [ value0:Object, value1,...valueN ]) : Array Parameters Numbers, elements, or strings to be concatenated in a new array. If you don’t pass any values, a duplicate of my_array is created. value0,...valueN Returns An array. Description Method; concatenates the elements specified in the parameters with the elements in my_array, and creates a new array.
Array.join() Availability Flash Player 5. Usage my_array.join([separator:String]) : String Parameters A character or string that separates array elements in the returned string. If you omit this parameter, a comma (,) is used as the default separator. separator Returns A string. Description Method; converts the elements in an array to strings, inserts the specified separator between the elements, concatenates them, and returns the resulting string.
Array.length Availability Flash Player 5. Usage my_array.length:Number Description Property; a non-negative integer specifying the number of elements in the array. This property is automatically updated when new elements are added to the array. When you assign a value to an array element (for example, my_array[index] = value), if index is a number, and index+1 is greater than the length property, the length property is updated to index+1.
Array.pop() Availability Flash Player 5. Usage my_array.pop() : Object Parameters None. Returns The value of the last element in the specified array. Description Method; removes the last element from an array and returns the value of that element. Example The following code creates the myPets_array array containing four elements, and then removes its last element: var myPets_array:Array = new Array("cat", "dog", "bird", "fish"); var popped:String = myPets_array.
Array.push() Availability Flash Player 5. Usage my_array.push(value,...) : Number Parameters value One or more values to append to the array. Returns An integer representing the length of the new array. Description Method; adds one or more elements to the end of an array and returns the array’s new length. Example The following example creates the array myPets_array with two elements, cat and dog. The second line adds two elements to the array.
Array.reverse() Availability Flash Player 5. Usage my_array.reverse() : Void Parameters None. Returns Nothing. Description Method; reverses the array in place. Example The following example uses this method to reverse the array numbers_array: var numbers_array:Array = new Array(1, 2, 3, 4, 5, 6); trace(numbers_array); // displays 1,2,3,4,5,6 numbers_array.reverse(); trace(numbers_array); // displays 6,5,4,3,2,1 Array.
Array.shift() Availability Flash Player 5. Usage my_array.shift() : Object Parameters None. Returns The first element in an array. Description Method; removes the first element from an array and returns that element. Example The following code creates the array myPets_array and then removes the first element from the array and assigns it to the variable shifted: var myPets_array:Array = new Array("cat", "dog", "bird", "fish"); var shifted:String = myPets_array.
Array.slice() Availability Flash Player 5. Usage my_array.slice( [ start:Number [ , end:Number ] ] ) : Array Parameters A number specifying the index of the starting point for the slice. If start is a negative number, the starting point begins at the end of the array, where -1 is the last element. start A number specifying the index of the ending point for the slice. If you omit this parameter, the slice includes all elements from the starting point to the end of the array.
Array.sort() Availability Flash Player 5; additional capabilities added in Flash Player 7. Usage my_array.sort() : Array my_array.sort(compareFunction:Function) : Array my_array.sort(option:Number | option |... ) : Array my_array.sort(compareFunction:Function, option:Number | option |... ) : Array Parameters A comparison function used to determine the sorting order of elements in an array.
By default, Array.sort() works as described in the following list: • Sorting is case-sensitive (Z precedes a). • Sorting is ascending (a precedes b). • The array is modified to reflect the sort order; multiple elements that have identical sort fields are placed consecutively in the sorted array in no particular order. • Numeric fields are sorted as if they were strings, so 100 precedes 99, because “1” is a lower string value than “9”.
trace("Sorted:"); //displays Sorted: trace(passwords_array); //displays ana:ring,anne:home,jay:mag,mom:glam,regina:silly See also | (bitwise OR), 116 Array.
Array.sortOn() Availability Flash Player 6; additional capabilities added in Flash Player 7. Usage my_array.sortOn("fieldName":String ) : Array my_array.sortOn("fieldName":String, option:Number | option |... ) : Array my_array.sortOn( [ "fieldName" , "fieldName" , ... ]:Array) : Array my_array.sortOn( [ "fieldName" , "fieldName" , ... ]:Array , option:Number | option |...
By default, Array.sortOn() works as described in the following list: • Sorting is case-sensitive (Z precedes a). • Sorting is ascending (a precedes b). • The array is modified to reflect the sort order; multiple elements that have identical sort fields are placed consecutively in the sorted array in no particular order. • Numeric fields are sorted as if they were strings, so 100 precedes 99, because “1” is a lower string value than “9”. You can use the option flags to override these defaults.
// barb // abcd Performing a default sort on the age field produces the following results: my_array.sortOn("age"); // 29 // 3 // 35 // 4 Performing a numeric sort on the age field produces the following results: my_array.sortOn("age", 16); // 3 // 4 // 29 // 35 Performing a descending numeric sort on the age field produces the following results: my_array.
// my_array[2].age = 35; // my_array[3].age = 4; Example The following example creates a new array and sorts it according to the fields name and city: The first sort uses name as the first sort value and city as the second. The second sort uses city as the first sort value and name as the second. var rec_array:Array = new Array(); rec_array.push( { name: "john", city: "omaha", zip: 68144 } ); rec_array.push( { name: "john", city: "kansas city", zip: 72345 } ); rec_array.
Array.splice() Availability Flash Player 5. Usage my_array.splice(start:Number, deleteCount:Number [, value0:Object, value1...valueN]) : Array Parameters An integer that specifies the index of the element in the array where the insertion or deletion begins. start deleteCount An integer that specifies the number of elements to be deleted. This number includes the element specified in the start parameter.
The following example creates an array and splices it using element index 1 for the start parameter, the number 0 for the deleteCount parameter, and the string chair for the value parameter. This does not remove anything from the original array, and adds the string chair at index 1: var myFurniture_array:Array = new Array("couch", "bed", "desk", "lamp"); trace( myFurniture_array.
Array.toString() Availability Flash Player 5. Usage my_array.toString() : String Parameters None. Returns A string. Description Method; returns a String value representing the elements in the specified Array object. Every element in the array, starting with index 0 and ending with index my_array.length-1, is converted to a concatenated string and separated by commas. To specify a custom separator, use Array.join().
Array.unshift() Availability Flash Player 5. Usage my_array.unshift(value1:Object,value2,...valueN) : Number Parameters One or more numbers, elements, or variables to be inserted at the beginning of the array. value1,...valueN Returns An integer representing the new length of the array. Description Method; adds one or more elements to the beginning of an array and returns the array’s new length. Example The following example shows the use of Array.
CHAPTER 2 ActionScript Language Reference asfunction Availability Flash Player 5. Usage asfunction:function:Function,"parameter":String Parameters function parameter An identifier for a function. A string that is passed to the function named in the function parameter. Returns Nothing. Description Protocol; a special protocol for URLs in HTML text fields. In HTML text fields, text can be linked using the HTML A tag.
CHAPTER 2 ActionScript Language Reference Boolean() Availability Flash Player 5; behavior changed in Flash Player 7. Usage Boolean(expression) : Boolean Parameters expression An expression to convert to a Boolean value. Returns A Boolean value. Description Function; converts the parameter expression to a Boolean value and returns a value as described in the following list: • If expression is a Boolean value, the return value is expression.
If files are published for Flash Player 6 or earlier, the results will differ for three of the preceding examples: trace(Boolean("true")); // output: false trace(Boolean("false")); // output: false trace(Boolean("Craiggers")); // output: false This example shows a string that will evaluate as true if the file is published for Flash Player 7, but will evaluate as false for Flash Player 6 or earlier: trace(Boolean("0")); This example shows a significant difference between use of the Boolean() function and t
CHAPTER 2 ActionScript Language Reference Boolean class Availability Flash Player 5 (became a native object in Flash Player 6, which improved performance significantly). Description The Boolean class is a wrapper object with the same functionality as the standard JavaScript Boolean object. Use the Boolean class to retrieve the primitive data type or string representation of a Boolean object. You must use the constructor new Boolean() to create a Boolean object before calling its methods.
Boolean.toString() Availability Flash Player 5. Usage myBoolean.toString() : String Parameters None. Returns A string; "true" or "false". Description Method; returns the string representation ("true" or "false") of the Boolean object. Example This example creates a variable of type Boolean and uses toString() to convert the value to a string for use in the trace statement: var myBool:Boolean = true; trace("The value of the Boolean myBool is: " + myBool.
Boolean.valueOf() Availability Flash Player 5. Usage myBoolean.valueOf() : Boolean Parameters None. Returns A Boolean value. Description Method: returns true if the primitive value type of the specified Boolean object is true; false otherwise. Example The following example shows how this method works, and also shows that the primitive value type of a new Boolean object is false: var x:Boolean = new Boolean(); trace(x.valueOf()); // false x = (6==3+3); trace(x.
break CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage break Parameters None. Returns Nothing. Description Statement; appears within a loop (for, for..in, do while or while) or within a block of statements associated with a particular case within a switch statement. When used in a loop, the break statement instructs Flash to skip the rest of the loop body, stop the looping action, and execute the statement following the loop statement.
See also for, for..in, do while, while, switch, case, continue, throw, try..catch..
CHAPTER 2 ActionScript Language Reference Button class Availability Flash Player 6. Description All button symbols in a SWF file are instances of the Button object. You can give a button an instance name in the Property inspector, and use the methods and properties of the Button class to manipulate buttons with ActionScript. Button instance names are displayed in the Movie Explorer and in the Insert Target Path dialog box in the Actions panel. The Button class inherits from the Object class.
Property Description Button.useHandCursor A Boolean value that indicates whether the pointing hand is displayed when the mouse passes over a button. Button._visible A Boolean value that indicates whether a button instance is hidden or visible. Button._width The width of a button instance, in pixels. Button._x The x coordinate of a button instance. Button._xmouse Read-only; the x coordinate of the mouse pointer relative to a button instance. Button.
Button._alpha Availability Flash Player 6. Usage my_btn._alpha:Number Description Property; the alpha transparency value of the button specified by my_btn. Valid values are 0 (fully transparent) to 100 (fully opaque). The default value is 100. Objects in a button with _alpha set to 0 are active, even though they are invisible.
Button.enabled Availability Flash Player 6. Usage my_btn.enabled:Boolean Description Property; a Boolean value that specifies whether a button is enabled. When a button is disabled (the enabled property is set to false), the button is visible but cannot be clicked. The default value is true. This property is useful if you want to disable part of your navigation; for example, you may want to disable a button in the currently displayed page so that it can’t be clicked and the page cannot be reloaded.
Button._focusrect Availability Flash Player 6. Usage my_btn._focusrect:Boolean Description Property; a Boolean value that specifies whether a button has a yellow rectangle around it when it has keyboard focus. This property can override the global _focusrect property. By default, the _focusrect property of a button instance is null; meaning, the button instance does not override the global _focusrect property.
Button.getDepth() Availability Flash Player 6. Usage my_btn.getDepth() : Number Returns An integer. Description Method; returns the depth of a button instance. Example If you create myBtn1_btn and myBtn2_btn on the Stage, you can trace their depth using the following ActionScript: trace(myBtn1_btn.getDepth()); trace(myBtn2_btn.getDepth()); If you load a SWF file called buttonMovie.
Button._height Availability Flash Player 6. Usage my_btn._height:Number Description Property; the height of the button, in pixels. Example The following example sets the height and width of a button called my_btn to a specified width and height. my_btn._width = 500; my_btn._height = 200; Button.
Button.menu Availability Flash Player 7. Usage my_btn.menu = contextMenu Parameters contextMenu A ContextMenu object. Description Property; associates the ContextMenu object contextMenu with the button object my_button. The ContextMenu class lets you modify the context menu that appears when the user right-clicks (Windows) or Control-clicks (Macintosh) in Flash Player. Example The following example assigns a ContextMenu object to a button instance named myBtn_btn.
Button._name Availability Flash Player 6. Usage my_btn._name:String Description Property; instance name of the button specified by my_btn. Example The following example traces all instance names of any Button instances within the current Timeline of a SWF file. for (i in this) { if (this[i] instanceof Button) { trace(this[i]._name); } } Button.
Button.onDragOut Availability Flash Player 6. Usage my_btn.onDragOut = function() : Void { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the mouse button is clicked over the button and the pointer then dragged outside of the button. You must define a function that executes when the event handler is invoked. Example The following example demonstrates how you can execute statements when the pointer is dragged off a button.
Button.onDragOver Availability Flash Player 6. Usage my_btn.onDragOver = function() : Void { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the user presses and drags the mouse button outside and then over the button. You must define a function that executes when the event handler is invoked. Example The following example defines a function for the onDragOver handler that sends a trace() statement to the Output panel.
Button.onKeyDown Availability Flash Player 6. Usage my_btn.onKeyDown = function() : Void { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when a button has keyboard focus and a key is pressed. The onKeyDown event handler is invoked with no parameters. You can use the Key.getAscii() and Key.getCode() methods to determine which key was pressed. You must define a function that executes when the event handler is invoked.
See also Button.onKeyUp Button.
Button.onKeyUp Availability Flash Player 6. Usage my_btn.onKeyUp = function() : Void { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when a button has input focus and a key is released. The onKeyUp event handler is invoked with no parameters. You can use the Key.getAscii() and Key.getCode() methods to determine which key was pressed. You must define a function that executes when the event handler is invoked.
Press Control+Enter to test the SWF file. Make sure you select Control > Disable Keyboard Shortcuts in the test environment. Then press the Tab key until the button has focus (a yellow rectangle appears around the my_btn instance) and start pressing keys on your keyboard. When you press keys, they are displayed in the Output panel. Button.
Button.onKillFocus Availability Flash Player 6. Usage my_btn.onKillFocus = function (newFocus:Object) : Void { // your statements here } Parameters newFocus The object that is receiving the focus. Returns Nothing. Description Event handler; invoked when a button loses keyboard focus. The onKillFocus handler receives one parameter, newFocus, which is an object representing the new object receiving the focus. If no object receives the focus, newFocus contains the value null.
Button.onPress Availability Flash Player 6. Usage my_btn.onPress = function() : Void { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when a button is pressed. You must define a function that executes when the event handler is invoked. Example In the following example, a function that sends a trace() statement to the Output panel is defined for the onPress handler. my_btn.onPress = function () { trace ("onPress called"); }; Button.
Button.onRelease Availability Flash Player 6. Usage my_btn.onRelease = function() : Void { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when a button is released. You must define a function that executes when the event handler is invoked. Example In the following example, a function that sends a trace() statement to the Output panel is defined for the onRelease handler. my_btn.
Button.onReleaseOutside Availability Flash Player 6. Usage my_btn.onReleaseOutside = function() : Void { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the mouse is released while the pointer is outside the button after the button is pressed while the pointer is inside the button. You must define a function that executes when the event handler is invoked.
Button.onRollOut Availability Flash Player 6. Usage my_btn.onRollOut = function() : Void { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the pointer moves outside a button area. You must define a function that executes when the event handler is invoked. Example In the following example, a function that sends a trace() statement to the Output panel is defined for the onRollOut handler. my_btn.
Button.onRollOver Availability Flash Player 6. Usage my_btn.onRollOver = function() : Void { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the pointer moves over a button area. You must define a function that executes when the event handler is invoked. Example In the following example, a function that sends a trace() statement to the Output panel is defined for the onRollOver handler. my_btn.
Button.onSetFocus Availability Flash Player 6. Usage my_btn.onSetFocus = function(oldFocus:Object) : Void { // your statements here } Parameters oldFocus The object to lose keyboard focus. Returns Nothing. Description Event handler; invoked when a button receives keyboard focus. The oldFocus parameter is the object that loses the focus. For example, if the user presses the Tab key to move the input focus from a text field to a button, oldFocus contains the text field instance.
Button._parent Availability Flash Player 6. Usage my_btn._parent:MovieClip.property _parent:MovieClip.property Description Property; a reference to the movie clip or object that contains the current movie clip or object. The current object is the one containing the ActionScript code that references _parent. Use _parent to specify a relative path to movie clips or objects that are above the current movie clip or object.
Button._quality Availability Flash Player 6. Usage my_btn._quality:String Description Property (global); sets or retrieves the rendering quality used for a SWF file. Device fonts are always aliased and therefore are unaffected by the _quality property. The _quality property can be set to the following values: • • "LOW" Low rendering quality. Graphics are not anti-aliased, and bitmaps are not smoothed. "MEDIUM" Medium rendering quality.
Button._rotation Availability Flash Player 6. Usage my_btn._rotation:Number Description Property; the rotation of the button, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement my_btn._rotation = 450 is the same as my_btn._rotation = 90.
Button._soundbuftime Availability Flash Player 6. Usage my_btn._soundbuftime:Number Description Property (global); an integer that specifies the number of seconds a sound prebuffers before it starts to stream. Note: Although you can specify this property for a Button object, it is actually a global property, and you can specify its value simply as _soundbuftime. For more information and an example, see _soundbuftime.
Button.tabEnabled Availability Flash Player 6. Usage my_btn.tabEnabled:Boolean Description Property; specifies whether my_btn is included in automatic tab ordering. It is undefined by default. If the tabEnabled property is undefined or true, the object is included in automatic tab ordering. If the tabIndex property is also set to a value, the object is included in custom tab ordering as well.
Button.tabIndex Availability Flash Player 6. Usage my_btn.tabIndex:Number Description Property; lets you customize the tab ordering of objects in a SWF file. You can set the tabIndex property on a button, movie clip, or text field instance; it is undefined by default. If any currently displayed object in the SWF file contains a tabIndex property, automatic tab ordering is disabled, and the tab ordering is calculated from the tabIndex properties of objects in the SWF file.
Button._target Availability Flash Player 6. Usage my_btn._target:String Description Read-only property; returns the target path of the button instance specified by my_btn. Example Add a button instance to the Stage with an instance name my_btn and add the following code to Frame 1 of the Timeline: trace(my_btn._target); //displays /my_btn Select my_btn and convert it to a movie clip. Give the new movie clip an instance name my_mc.
Button.trackAsMenu Availability Flash Player 6. Usage my_btn.trackAsMenu:Boolean Description Property; a Boolean value that indicates whether other buttons or movie clips can receive mouse release events. If you drag a button and then release on a second button, the onRelease event is registered for the second button. This allows you to create menus. You can set the trackAsMenu property on any button or movie clip object. If the trackAsMenu property has not been defined, the default behavior is false.
Button._url Availability Flash Player 6. Usage my_btn._url:String Description Read-only property; retrieves the URL of the SWF file that created the button. Example Create two button instances on the Stage called one_btn and two_btn. Enter the following ActionScript in Frame 1 of the Timeline: var one_btn:Button; var two_btn:Button; this.createTextField("output_txt", 999, 0, 0, 100, 22); output_txt.autoSize = true; one_btn.onRelease = function() { trace("clicked one_btn"); trace(this._url); }; two_btn.
Button.useHandCursor Availability Flash Player 6. Usage my_btn.useHandCursor:Boolean Description Property; a Boolean value that, when set to true (the default), indicates whether a pointing hand (hand cursor) displays when the mouse rolls over a button. If this property is set to false, the arrow pointer is used instead. You can change the useHandCursor property at any time; the modified button immediately takes on the new cursor behavior. The useHandCursor property can be read out of a prototype object.
Button._visible Availability Flash Player 6. Usage my_btn._visible:Boolean Description Property; a Boolean value that indicates whether the button specified by my_btn is visible. Buttons that are not visible (_visible property set to false) are disabled. Example Create two buttons on the Stage with the instance names myBtn1_btn and myBtn2_btn. Enter the following ActionScript in Frame 1 of the Timeline: myBtn1_btn.onRelease = function() { this._visible = false; trace("clicked "+this.
Button._width Availability Flash Player 6. Usage my_btn._width:Number Description Property; the width of the button, in pixels. Example The following example increases the width property of a button called my_btn, and displays the width in the Output panel. Enter the following ActionScript in Frame 1 of the Timeline: my_btn.onRelease = function() { trace(this._width); this._width *= 1.1; }; See also MovieClip.
Button._x Availability Flash Player 6. Usage my_btn._x:Number Description Property; an integer that sets the x coordinate of a button relative to the local coordinates of the parent movie clip. If a button is on the main Timeline, then its coordinate system refers to the upper left corner of the Stage as (0, 0). If the button is inside a movie clip that has transformations, the button is in the local coordinate system of the enclosing movie clip.
Button._xmouse Availability Flash Player 6. Usage my_btn._xmouse:Number Description Read-only property; returns the x coordinate of the mouse position relative to the button. Example The following example displays the xmouse position for the Stage and a button called my_btn that is placed on the Stage. Enter the following ActionScript in Frame 1 of the Timeline: this.createTextField("mouse_txt", 999, 5, 5, 150, 40); mouse_txt.html = true; mouse_txt.wordWrap = true; mouse_txt.border = true; mouse_txt.
Button._xscale Availability Flash Player 6. Usage my_btn._xscale:Number Description Property; the horizontal scale of the button as applied from the registration point of the button, expressed as a percentage. The default registration point is (0,0). Scaling the local coordinate system affects the _x and _y property settings, which are defined in pixels.
Button._y Availability Flash Player 6. Usage my_btn._y:Number Description Property; the y coordinate of the button relative to the local coordinates of the parent movie clip. If a button is in the main Timeline, its coordinate system refers to the upper left corner of the Stage as (0, 0). If the button is inside another movie clip that has transformations, the button is in the local coordinate system of the enclosing movie clip.
Button._ymouse Availability Flash Player 6. Usage my_btn._ymouse:Number Description Read-only property; indicates the y coordinate of the mouse position relative to the button. Example The following example displays the xmouse position for the Stage and a button called my_btn that is placed on the Stage. Enter the following ActionScript in Frame 1 of the Timeline: this.createTextField("mouse_txt", 999, 5, 5, 150, 40); mouse_txt.html = true; mouse_txt.wordWrap = true; mouse_txt.border = true; mouse_txt.
Button._yscale Availability Flash Player 6. Usage my_btn._yscale:Number Description Property; the vertical scale of the button as applied from the registration point of the button, expressed as a percentage. The default registration point is (0,0). Example The following example scales a button called my_btn. When you click and release the button, it grows 10% on the x and y axis. Enter the following ActionScript in Frame 1 of the Timeline: my_btn.onRelease = function(){ this._xscale *= 1.1; this.
CHAPTER 2 ActionScript Language Reference Camera class Availability Flash Player 6. Description The Camera class is primarily for use with Macromedia Flash Communication Server, but can be used in a limited way without the server. The Camera class lets you capture video from a video camera attached to the computer that is running Macromedia Flash Player—for example, to monitor a video feed from a web camera attached to your local system.
Property (read-only) Description Camera.motionLevel The amount of motion required to invoke Camera.onActivity(true). Camera.motionTimeOut The number of milliseconds between the time when the camera stops detecting motion and the time Camera.onActivity(false) is invoked. Camera.muted A Boolean value that specifies whether the user has allowed or denied access to the camera. Camera.name The name of the camera as specified by the camera hardware. Camera.
Camera.activityLevel Availability Flash Player 6. Usage active_cam.activityLevel:Number Description Read-only property; a numeric value that specifies the amount of motion the camera is detecting. Values range from 0 (no motion is being detected) to 100 (a large amount of motion is being detected). The value of this property can help you determine if you need to pass a setting to Camera.setMotionLevel(). If the camera is available but is not yet being used because Video.
Camera.bandwidth Availability Flash Player 6. Usage active_cam.bandwidth:Number Description Read-only property; an integer that specifies the maximum amount of bandwidth the current outgoing video feed can use, in bytes. A value of 0 means that Flash video can use as much bandwidth as needed to maintain the desired frame quality. To set this property, use Camera.setQuality(). Example The following example changes the maximum amount of bandwidth used by the camera feed.
Camera.currentFps Availability Flash Player 6. Usage active_cam.currentFps:Number Description Read-only property; the rate at which the camera is capturing data, in frames per second. This property cannot be set; however, you can use the Camera.setMode() method to set a related property—Camera.fps—which specifies the maximum frame rate at which you would like the camera to capture data.
Camera.fps Availability Flash Player 6. Usage active_cam.fps:Number Description Read-only property; the maximum rate at which you want the camera to capture data, in frames per second. The maximum rate possible depends on the capabilities of the camera; that is, if the camera doesn’t support the value you set here, this frame rate will not be achieved. • To set a desired value for this property, use Camera.setMode(). • To determine the rate at which the camera is currently capturing data, use the Camera.
Camera.get() Availability Flash Player 6. Usage Camera.get([index:Number]) : Camera Note: The correct syntax is Camera.get(). To assign the Camera object to a variable, use syntax like active_cam = Camera.get(). Parameters An optional zero-based integer that specifies which camera to get, as determined from the array returned by the Camera.names property. To get the default camera (which is recommended for most applications), omit this parameter.
The user can also specify permanent privacy settings for a particular domain by right-clicking (Windows) or Control-clicking (Macintosh) while a SWF file is playing, selecting Settings, opening the Privacy panel, and selecting Remember. You can’t use ActionScript to set the Allow or Deny value for a user, but you can display the Privacy panel for the user by using System.showSettings(0). If the user selects Remember, Flash Player no longer displays the Privacy dialog box for SWF files from this domain.
Camera.height Availability Flash Player 6. Usage active_cam.height:Number Description Read-only property; the current capture height, in pixels. To set a value for this property, use Camera.setMode(). Example The following code displays the current width, height and FPS of a video instance in a Label component instance on the Stage. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video.
Camera.index Availability Flash Player 6. Usage active_cam.index:Number Description Read-only property; a zero-based integer that specifies the index of the camera, as reflected in the array returned by Camera.names. Example The following example displays an array of cameras in a text field that is created at runtime, and tells you which camera you are currently using. Create a new video instance by selecting New Video from the Library options menu.
Camera.motionLevel Availability Flash Player 6. Usage active_cam.motionLevel:Number Description Read-only property; a numeric value that specifies the amount of motion required to invoke Camera.onActivity(true). Acceptable values range from 0 to 100. The default value is 50. Video can be displayed regardless of the value of the motionLevel property. For more information, see Camera.setMotionLevel(). Example The following example continually detects the motion level of a camera feed.
/* When the level of activity changes goes above or below the number defined in Camera.motionLevel, trigger the onActivity event handler. If the activityLevel is above the value defined in the motionLevel property isActive will be set to true. Otherwise, the activityLevel has fallen below the value defined in the motionLevel property (and stayed below that level for 2 seconds), so set the isActive parameter to false. */ my_cam.
Camera.motionTimeOut Availability Flash Player 6. Usage active_cam.motionTimeOut:Number Description Read-only property; the number of milliseconds between the time the camera stops detecting motion and the time Camera.onActivity(false) is invoked. The default value is 2000 (2 seconds). To set this value, use Camera.setMotionLevel(). Example In the following example, the ProgressBar instance changes its halo theme color when the activity level falls below the motion level.
See also Camera.onActivity, Camera.
Camera.muted Availability Flash Player 6. Usage active_cam.muted:Boolean Description Read-only property; a Boolean value that specifies whether the user has denied access to the camera (true) or allowed access (false) in the Flash Player Privacy Settings panel. When this value changes, Camera.onStatus is invoked. For more information, see Camera.get(). Example In the following example, an error message could be displayed if my_cam.muted evaluates to true.
Camera.name Availability Flash Player 6. Usage active_cam.name:String Description Read-only property; a string that specifies the name of the current camera, as returned by the camera hardware. Example The following example displays the name of the default camera in a text field. In Windows, this name is the same as the device name listed in the Scanners and Cameras Control Panel. Create a new video instance by selecting New Video from the Library options menu.
Camera.names Availability Flash Player 6. Usage Camera.names:Array Note: The correct syntax is Camera.names. To assign the return value to a variable, use syntax like cam_array = Camera.names. To determine the name of the current camera, use active_cam.name. Description Read-only class property; retrieves an array of strings reflecting the names of all available cameras without displaying the Flash Player Privacy Settings panel.
Camera.onActivity Availability Flash Player 6. Usage active_cam.onActivity = function(activity:Boolean) : Void { // your statements here } Parameters activity A Boolean value set to true when the camera starts detecting motion, false when it stops. Returns Nothing. Description Event handler; invoked when the camera starts or stops detecting motion. If you want to respond to this event handler, you must create a function to process its activity value.
Camera.onStatus Availability Flash Player 6. Usage active_cam.onStatus = function(infoObject:Object) : Void { // your statements here } Parameters infoObject A parameter defined according to the status message. Returns Nothing. Description Event handler; invoked when the user allows or denies access to the camera. If you want to respond to this event handler, you must create a function to process the information object generated by the camera.
trace("Camera access granted"); break; } }; See also Camera.get(), Camera.muted, System.showSettings(); System.
Camera.quality Availability Flash Player 6. Usage active_cam.quality:Number Description Read-only property; an integer specifying the required level of picture quality, as determined by the amount of compression being applied to each video frame. Acceptable quality values range from 1 (lowest quality, maximum compression) to 100 (highest quality, no compression). The default value is 0, which means that picture quality can vary as needed to avoid exceeding available bandwidth.
Camera.setMode() Availability Flash Player 6. Usage active_cam.setMode(width:Number, height:Number, fps:Number [,favorSize:Boolean]) : Void Parameters width The requested capture width, in pixels. The default value is 160. height The requested capture height, in pixels. The default value is 120. fps The requested rate at which the camera should capture data, in frames per second. The default value is 15.
Example The following example sets the camera capture mode. You can type a frame rate into a TextInput instance and press Enter or Return to apply the frame rate. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video. Add a TextInput component instance with the instance name fps_ti. Then add the following ActionScript to Frame 1 of the Timeline: var my_cam:Camera = Camera.get(); var my_video:Video; my_video.
Camera.setMotionLevel() Availability Flash Player 6. Usage active_cam.setMotionLevel(sensitivity:Number [, timeout:Number]) : Void Parameters sensitivity A numeric value that specifies the amount of motion required to invoke Acceptable values range from 0 to 100. The default value is 50. Camera.onActivity(true). timeout An optional numeric parameter that specifies how many milliseconds must elapse without activity before Flash considers activity to have stopped and invokes the Camera.
Example The following example sends messages to the Output panel when video activity starts or stops. Change the motion sensitivity value of 30 to a higher or lower number to see how different values affect motion detection. // Assumes a Video object named "myVideoObject" is on the Stage active_cam = Camera.get(); x = 0; function motion(mode) { trace(x + ": " + mode); x++; } active_cam.onActivity = function(mode) { motion(mode); } active_cam.setMotionLevel(30, 500); myVideoObject.
Camera.setQuality() Availability Flash Player 6. Usage active_cam.setQuality(bandwidth:Number, frameQuality:Number) : Void Parameters An integer that specifies the maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second. To specify that Flash video can use as much bandwidth as needed to maintain the value of frameQuality, pass 0 for bandwidth. The default value is 16384.
Example The following examples illustrate how to use this method to control bandwidth use and picture quality. // Ensure that no more than 8192 (8K/second) is used to send video active_cam.setQuality(8192,0); // Ensure that no more than 8192 (8K/second) is used to send video // with a minimum quality of 50 active_cam.setQuality(8192,50); // Ensure a minimum quality of 50, no matter how much bandwidth it takes active_cam.setQuality(0,50); See also Camera.bandwidth, Camera.get(), Camera.quality Camera.
Camera.width Availability Flash Player 6. Usage active_cam.width:Number Description Read-only property; the current capture width, in pixels. To set a desired value for this property, use Camera.setMode(). Example The following code displays the current width, height and FPS of a video instance in a Label component instance on the Stage. Create a new video instance by selecting New Video from the Library options menu. Add an instance to the Stage and give it the instance name my_video.
CHAPTER 2 ActionScript Language Reference case Availability Flash Player 4. Usage case expression: statement(s) Parameters expression statement(s) Any expression. Any statement or sequence of statements. Returns Nothing. Description Statement; defines a condition for the switch statement.
See also break, default, === (strict equality), switch 202 Chapter 2: ActionScript Language Reference
CHAPTER 2 ActionScript Language Reference class Availability Flash Player 6. Usage [dynamic] class className [ extends superClass ] [ implements interfaceName [, interfaceName... ] ] { // class definition here } Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in external script files—not in scripts written in the Actions panel.
To indicate that objects can add and access dynamic properties at runtime, precede the class statement with the dynamic keyword. To declare that a class implements an interface, use the implements keyword. To create subclasses of a class, use the extends keyword. (A class can extend only one class, but can implement several interfaces.) You can use implements and extends in a single statement.
}; var JPEG_mcl:MovieClipLoader = new MovieClipLoader(); JPEG_mcl.addListener(listenerObject); JPEG_mcl.loadClip(image, target_mc); } } In an external script file or in the Actions panel, use the new operator to create a ImageLoader object. var jakob_mc:MovieClip = this.createEmptyMovieClip("jakob_mc", this.getNextHighestDepth()); var jakob:ImageLoader = new ImageLoader("http://www.macromedia.com/devnet/mx/ blueprint/articles/nielsen/spotlight_jnielsen.
clearInterval() CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Usage clearInterval( intervalID:Number ) : Void Parameters intervalID A numeric (integer) identifier returned from a call to setInterval(). Returns Nothing. Description Function; cancels an interval created by a call to setInterval(). Example The following example first sets and then clears an interval call: function callback() { trace("interval called: "+getTimer()+" ms.
CHAPTER 2 ActionScript Language Reference Color class Availability Flash Player 5. Description The Color class lets you set the RGB color value and color transform of movie clips and retrieve those values once they have been set. You must use the constructor new Color() to create a Color object before calling its methods. Method summary for the Color class Method Description Color.getRGB() Returns the numeric RGB value set by the last setRGB() call. Color.
Color.getRGB() Availability Flash Player 5. Usage my_color.getRGB() : Number Parameters None. Returns A number that represents the RGB numeric value for the color specified. Description Method; returns the numeric values set by the last setRGB() call. Example The following code retrieves the RGB value for the Color object my_color, converts the value to a hexadecimal string, and assigns it to the myValue variable.
Color.getTransform() Availability Flash Player 5. Usage my_color.getTransform() : Object Parameters None. Returns An object whose properties contain the current offset and percentage values for the specified color. Description Method; returns the transform value set by the last Color.setTransform() call. Example The following example gets the transform object, and then sets new percentages for colors and alpha of my_mc relative to their current values.
Color.setRGB() Availability Flash Player 5. Usage my_color.setRGB(0xRRGGBB:Number) : Void Parameters The hexadecimal or RGB color to be set. RR, GG, and BB each consist of two hexadecimal digits that specify the offset of each color component. The 0x tells the ActionScript compiler that the number is a hexadecimal value. 0xRRGGBB Description Method; specifies an RGB color for a Color object. Calling this method overrides any previous Color.setTransform() settings. Returns Nothing.
Color.setTransform() Availability Flash Player 5. Usage my_color.setTransform(colorTransformObject:Object) : Void Parameters colorTransformObject An object created with the new Object constructor. This instance of the Object class must have the following properties that specify color transform values: ra, rb, ga, gb, ba, bb, aa, ab. These properties are explained below. Returns Nothing. Description Method; sets color transform information for a Color object.
Example This example creates a new Color object for a target SWF file, creates a generic object called myColorTransform with the properties defined above, and uses the setTransform() method to pass the colorTransformObject to a Color object.
ContextMenu class CHAPTER 2 ActionScript Language Reference Availability Flash Player 7. Description The ContextMenu class provides runtime control over the items in the Flash Player context menu, which appears when a user right-clicks (Windows) or Control-clicks (Macintosh) on Flash Player. You can use the methods and properties of the ContextMenu class to add custom menu items, control the display of the built-in context menu items (for example, Zoom In and Print), or create copies of menus.
Property summary for the ContextMenu class Property Description ContextMenu.builtInItems An object whose members correspond to built-in context menu items. ContextMenu.customItems An array, undefined by default, that contains ContextMenuItem objects. Event handler summary for the ContextMenu class Property Description ContextMenu.onSelect Invoked before the menu is displayed. Constructor for the ContextMenu class Availability Flash Player 7.
var showItem = true; // Change this to false to remove var my_cm:ContextMenu = new ContextMenu(menuHandler); my_cm.customItems.push(new ContextMenuItem("Hello", itemHandler)); function menuHandler(obj, menuObj) { if (showItem == false) { menuObj.customItems[0].enabled = false; } else { menuObj.customItems[0].enabled = true; } } function itemHandler(obj, item) { //...put code here... trace("selected!"); } this.
ContextMenu.builtInItems Availability Flash Player 7. Usage my_cm.builtInItems:Object Description Property; an object that has the following Boolean properties: save, zoom, quality, play, loop, rewind, forward_back, and print. Setting these variables to false removes the corresponding menu items from the specified ContextMenu object. These properties are enumerable and are set to true by default.
ContextMenu.copy() Availability Flash Player 7. Usage my_cm.copy() : ContextMenu Parameters None. Returns A ContextMenu object. Description Method; creates a copy of the specified ContextMenu object. The copy inherits all the properties of the original menu object. Example This example creates a copy of the ContextMenu object named my_cm whose built-in menu items are hidden, and adds a menu item with the text “Save...”.
ContextMenu.customItems Availability Flash Player 7. Usage my_cm.customItems:Array Description Property; an array of ContextMenuItem objects. Each object in the array represents a context menu item that you have defined. Use this property to add, remove, or modify these custom menu items. To add new menu items, you first create a new ContextMenuItem object, and then add it to the menu_mc.customItems array (for example, using Array.push()).
ContextMenu.hideBuiltInItems() Availability Flash Player 7. Usage my_cm.hideBuiltInItems() : Void Parameters None. Returns Nothing. Description Method; hides all built-in menu items (except Settings) in the specified ContextMenu object. If the Flash Debug Player is running, the Debugging menu item shows, although it is dimmed for SWF files that don’t have remote debugging enabled.
ContextMenu.onSelect Availability Flash Player 7. Usage my_cm.onSelect = function (item:Object, item_menu:ContextMenu) : Void{ // your code here } Parameters item A reference to the object (movie clip, button, or selectable text field) that was under the mouse pointer when the Flash Player context menu was invoked and whose menu property is set to a valid ContextMenu object. item_menu A reference to the ContextMenu object assigned to the menu property of object. Returns Nothing.
ContextMenuItem class CHAPTER 2 ActionScript Language Reference Availability Flash Player 7. Description You use the ContextMenuItem class to create custom menu items to display in the Flash Player context menu. Each ContextMenuItem object has a caption (text) that is displayed in the context menu, and a callback handler (a function) that is invoked when the menu item is selected. To add a new context menu item to a context menu, you add it to the customItems array of a ContextMenu object.
Constructor for the ContextMenuItem class Availability Flash Player 7. Usage new ContextMenuItem(caption:String, callbackFunction:Function, [ separatorBefore:Boolean, [ enabled:Boolean, [ visible:Boolean] ] ] ) : ContextMenuItem Parameters caption A string that specifies the text associated with the menu item. callbackFunction A function that you define, which is called when the menu item is selected.
ContextMenuItem.caption Availability Flash Player 7. Usage menuItem_cmi.caption:String Description Property; a string that specifies the menu item caption (text) displayed in the context menu. Example The following example displays the caption for the selected menu item (Pause Game) in the Output panel: var my_cm:ContextMenu = new ContextMenu(); var menuItem_cmi:ContextMenuItem = new ContextMenuItem("Pause Game", onPause); my_cm.customItems.
ContextMenuItem.copy() Availability Flash Player 7. Usage menuItem_cmi.copy() : ContextMenuItem Returns A ContextMenuItem object. Description Method; creates and returns a copy of the specified ContextMenuItem object. The copy includes all properties of the original object. Example This example creates a new ContextMenuItem object named original_cmi with the caption Pause and a callback handler set to the function onPause.
ContextMenuItem.enabled Availability Flash Player 7. Usage menuItem_cmi.enabled:Boolean Description Property; a Boolean value that indicates whether the specified menu item is enabled or disabled. By default, this property is true. Example The following example creates two new context menu items: Start and Stop. When the user selects Start, the number of milliseconds from when the SWF file started is traced. Start is then disabled in the menu.
ContextMenuItem.onSelect Availability Flash Player 7. Usage menuItem_cmi.onSelect = function (obj:Object, menuItem:ContextMenuItem) : Void { // your statements here } Parameters obj A reference to the movie clip (or Timeline), button, or selectable text field that the user right-clicked or Control-clicked. menuItem A reference to the selected ContextMenuItem object. Returns Nothing. Description Event handler; invoked when the specified menu item is selected from the Flash Player context menu.
ContextMenuItem.separatorBefore Availability Flash Player 7. Usage menuItem_cmi.separatorBefore:Boolean Description Property; a Boolean value that indicates whether a separator bar should appear above the specified menu item. By default, this property is false. Note: A separator bar always appears between any custom menu items and the built-in menu items. Example This example creates three menu items, labeled Open, Save, and Print. A separator bar divides the Save and Print items.
ContextMenuItem.visible Availability Flash Player 7. Usage menuItem_cmi.visible:Boolean Description Property; a Boolean value that indicates whether the specified menu item is visible when the Flash Player context menu is displayed. By default, this property is true. Example The following example creates two new context menu items: Start and Stop. When the user selects Start, the number of milliseconds from when the SWF file started is displayed. Start is then made invisible in the menu.
continue CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage continue Parameters None. Returns Nothing. Description Statement; jumps past all remaining statements in the innermost loop and starts the next iteration of the loop as if control had passed through to the end of the loop normally. It has no effect outside a loop.
In a for loop, continue causes the Flash interpreter to skip the rest of the loop body. In the following example, if the i modulo 3 equals 0, then the trace(i) statement is skipped: trace("example 3"); for (var i = 0; i<10; i++) { if (i%3 == 0) { continue; } trace(i); } In the following for..
CustomActions class CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Description The methods of the CustomActions class allow a SWF file playing in the Flash authoring tool to manage any custom actions that are registered with the authoring tool. A SWF file can install and uninstall custom actions, retrieve the XML definition of a custom action, and retrieve the list of registered custom actions.
CustomActions.get() Availability Flash Player 6. Usage CustomActions.get(customName:String) : String Parameters customName The name of the custom action definition to retrieve. Returns If the custom action XML definition is located, returns a string; otherwise, returns undefined. Description Method; reads the contents of the custom action XML definition file named customName. The name of the definition file must be a simple filename, without the .
CustomActions.install() Availability Flash Player 6. Usage CustomActions.install(customName:String, customXML:String) : Boolean Parameters customName customXML The name of the custom action definition to install. The text of the XML definition to install. Returns A Boolean value of false if an error occurs during installation; otherwise, a value of true is returned to indicate that the custom action has been successfully installed.
Then open a new FLA file in the same directory and select Frame 1 of the Timeline. Enter the following code into the Actions panel: var my_xml:XML = new XML(); my_xml.ignoreWhite = true; my_xml.onLoad = function(success:Boolean) { trace(success); CustomActions.install("dogclass", this.firstChild); trace(CustomActions.list()); }; my_xml.load("dogclass.
CustomActions.list() Availability Flash Player 6. Usage CustomActions.list() : Array Parameters None. Returns An array. Description Method; returns an Array object containing the names of all the custom actions that are registered with the Flash authoring tool. The elements of the array are simple names, without the .xml file extension, and without any directory separators (for example, “:”, “/”, or “\”). If there are no registered custom actions, list() returns a zero-length array.
CustomActions.uninstall() Availability Flash Player 6. Usage CustomActions.uninstall(customName:String) : Boolean Parameters customName The name of the custom action definition to uninstall. Returns A Boolean value of false if no custom actions are found with the name customName. If the custom actions were successfully removed, a value of true is returned. Description Method; removes the Custom Actions XML definition file named customName.
Date class CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Description The Date class lets you retrieve date and time values relative to universal time (Greenwich Mean Time, now called universal time or UTC) or relative to the operating system on which Flash Player is running. The methods of the Date class are not static but apply only to the individual Date object specified when the method is called. The Date.UTC() method is an exception; it is a static method.
Method Description Date.getMilliseconds() Returns the milliseconds according to local time. Date.getMinutes() Returns the minutes according to local time. Date.getMonth() Returns the month according to local time. Date.getSeconds() Returns the seconds according to local time. Date.getTime() Returns the number of milliseconds since midnight January 1, 1970, universal time. Date.getTimezoneOffset() Returns the difference, in minutes, between the computer’s local time and universal time.
Method Description Date.setUTCHours() Sets the hour according to universal time. Returns the new time in milliseconds. Date.setUTCMilliseconds() Sets the milliseconds according to universal time. Returns the new time in milliseconds. Date.setUTCMinutes() Sets the minutes according to universal time. Returns the new time in milliseconds. Date.setUTCMonth() Sets the month according to universal time. Returns the new time in milliseconds. Date.
Description Constructor; constructs a new Date object that holds the specified date or the current date and time.
Date.getDate() Availability Flash Player 5. Usage my_date.getDate() : Number Parameters None. Returns An integer. Description Method; returns the day of the month (an integer from 1 to 31) of the specified Date object according to local time. Local time is determined by the operating system on which Flash Player is running. Example The following example creates a new Date object and concatenates the returned values of Date.getMonth(), Date.getDate(), and Date.
Date.getDay() Availability Flash Player 5. Usage my_date.getDay() : Number Parameters None. Returns An integer representing the day of the week. Description Method; returns the day of the week (0 for Sunday, 1 for Monday, and so on) of the specified Date object according to local time. Local time is determined by the operating system on which Flash Player is running.
Date.getFullYear() Availability Flash Player 5. Usage my_date.getFullYear() : Number Parameters None. Returns An integer representing the year. Description Method; returns the full year (a four-digit number, such as 2000) of the specified Date object, according to local time. Local time is determined by the operating system on which Flash Player is running. Example The following example uses the constructor to create a Date object.
Date.getHours() Availability Flash Player 5. Usage my_date.getHours() : Number Parameters None. Returns An integer. Description Method; returns the hour (an integer from 0 to 23) of the specified Date object, according to local time. Local time is determined by the operating system on which Flash Player is running.
Date.getMilliseconds() Availability Flash Player 5. Usage my_date.getMilliseconds() : Number Parameters None. Returns An integer. Description Method; returns the milliseconds (an integer from 0 to 999) of the specified Date object, according to local time. Local time is determined by the operating system on which Flash Player is running.
Date.getMinutes() Availability Flash Player 5. Usage my_date.getMinutes() : Number Parameters None. Returns An integer. Description Method; returns the minutes (an integer from 0 to 59) of the specified Date object, according to local time. Local time is determined by the operating system on which Flash Player is running.
Date.getMonth() Availability Flash Player 5. Usage my_date.getMonth() : Number Parameters None. Returns An integer. Description Method; returns the month (0 for January, 1 for February, and so on) of the specified Date object, according to local time. Local time is determined by the operating system on which Flash Player is running.
Date.getSeconds() Availability Flash Player 5. Usage my_date.getSeconds() : Number Parameters None. Returns An integer. Description Method; returns the seconds (an integer from 0 to 59) of the specified Date object, according to local time. Local time is determined by the operating system on which Flash Player is running.
Date.getTime() Availability Flash Player 5. Usage my_date.getTime() : Number Parameters None. Returns An integer. Description Method; returns the number of milliseconds since midnight January 1, 1970, universal time, for the specified Date object. Use this method to represent a specific instant in time when comparing two or more Date objects.
Date.getTimezoneOffset() Availability Flash Player 5. Usage my_date.getTimezoneOffset() : Number Parameters None. Returns An integer. Description Method; returns the difference, in minutes, between the computer’s local time and universal time. Example The following example returns the difference between the local daylight saving time for San Francisco and universal time.
Date.getUTCDate() Availability Flash Player 5. Usage my_date.getUTCDate() : Number Parameters None. Returns An integer. Description Method; returns the day of the month (an integer from 1 to 31) in the specified Date object, according to universal time. Example The following example creates a new Date object and uses Date.getUTCDate() and Date.getDate(). The value returned by Date.getUTCDate() can differ from the value returned by Date.
Date.getUTCDay() Availability Flash Player 5. Usage my_date.getUTCDay() : Number Parameters None. Returns An integer. Description Method; returns the day of the week (0 for Sunday, 1 for Monday, and so on) of the specified Date object, according to universal time. Example The following example creates a new Date object and uses Date.getUTCDay() and Date.getDay(). The value returned by Date.getUTCDay() can differ from the value returned by Date.
Date.getUTCFullYear() Availability Flash Player 5. Usage my_date.getUTCFullYear() : Number Parameters None. Returns An integer. Description Method; returns the four-digit year of the specified Date object, according to universal time. Example The following example creates a new Date object and uses Date.getUTCFullYear() and Date.getFullYear(). The value returned by Date.getUTCFullYear() may differ from the value returned by Date.
Date.getUTCHours() Availability Flash Player 5. Usage my_date.getUTCHours() : Number Parameters None. Returns An integer. Description Method; returns the hour (an integer from 0 to 23) of the specified Date object, according to universal time. Example The following example creates a new Date object and uses Date.getUTCHours() and Date.getHours(). The value returned by Date.getUTCHours() may differ from the value returned by Date.
Date.getUTCMilliseconds() Availability Flash Player 5. Usage my_date.getUTCMilliseconds() : Number Parameters None. Returns An integer. Description Method; returns the milliseconds (an integer from 0 to 999) of the specified Date object, according to universal time. Example The following example creates a new Date object and uses getUTCMilliseconds() to return the milliseconds value from the Date object. var today_date:Date = new Date(); trace(today_date.getUTCMilliseconds()); Date.
Date.getUTCMinutes() Availability Flash Player 5. Usage my_date.getUTCMinutes() : Number Parameters None. Returns An integer. Description Method; returns the minutes (an integer from 0 to 59) of the specified Date object, according to universal time. Example The following example creates a new Date object and uses getUTCMinutes() to return the minutes value from the Date object: var today_date:Date = new Date(); trace(today_date.
Date.getUTCMonth() Availability Flash Player 5. Usage my_date.getUTCMonth() : Number Parameters None. Returns An integer. Description Method; returns the month (0 [January] to 11 [December]) of the specified Date object, according to universal time. Example The following example creates a new Date object and uses Date.getUTCMonth() and Date.getMonth(). The value returned by Date.getUTCMonth() can differ from the value returned by Date.
Date.getUTCSeconds() Availability Flash Player 5. Usage my_date.getUTCSeconds() : Number Parameters None. Returns An integer. Description Method; returns the seconds (an integer from 0 to 59) of the specified Date object, according to universal time. Example The following example creates a new Date object and uses getUTCSeconds() to return the seconds value from the Date object: var today_date:Date = new Date(); trace(today_date.
Date.getYear() Availability Flash Player 5. Usage my_date.getYear() : Number Parameters None. Returns An integer. Description Method; returns the year of the specified Date object, according to local time. Local time is determined by the operating system on which Flash Player is running. The year is the full year minus 1900. For example, the year 2000 is represented as 100. Example The following example creates a Date object with the month and year set to May 2004. The Date.
Date.setDate() Availability Flash Player 5. Usage my_date.setDate(date) : Number Parameters date An integer from 1 to 31. Returns An integer. Description Method; sets the day of the month for the specified Date object, according to local time, and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running. Example The following example initially creates a new Date object, setting the date to May 15, 2004, and uses Date.
Date.setFullYear() Availability Flash Player 5. Usage my_date.setFullYear(year:Number [, month:Number [, date:Number]] ) : Number Parameters A four-digit number specifying a year. Two-digit numbers do not represent four-digit years; for example, 99 is not the year 1999, but the year 99. year month date An integer from 0 (January) to 11 (December). This parameter is optional. A number from 1 to 31. This parameter is optional. Returns An integer.
Date.setHours() Availability Flash Player 5. Usage my_date.setHours(hour) : Number Parameters hour An integer from 0 (midnight) to 23 (11 p.m.). Returns An integer. Description Method; sets the hours for the specified Date object according to local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running. Example The following example initially creates a new Date object, setting the time and date to 8:00 a.m.
Date.setMilliseconds() Availability Flash Player 5. Usage my_date.setMilliseconds(millisecond:Number) : Number Parameters millisecond An integer from 0 to 999. Returns An integer. Description Method; sets the milliseconds for the specified Date object according to local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running. Example The following example initially creates a new Date object, setting the date to 8:30 a.m.
Date.setMinutes() Availability Flash Player 5. Usage my_date.setMinutes(minute:Number) : Number Parameters minute An integer from 0 to 59. Returns An integer. Description Method; sets the minutes for a specified Date object according to local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running. Example The following example initially creates a new Date object, setting the time and date to 8:00 a.m.
Date.setMonth() Availability Flash Player 5. Usage my_date.setMonth(month:Number [, date:Number ]) : Number Parameters month date An integer from 0 (January) to 11 (December). An integer from 1 to 31. This parameter is optional. Returns An integer. Description Method; sets the month for the specified Date object in local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running.
Date.setSeconds() Availability Flash Player 5. Usage my_date.setSeconds(second:Number) : Number Parameters second An integer from 0 to 59. Returns An integer. Description Method; sets the seconds for the specified Date object in local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running. Example The following example initially creates a new Date object, setting the time and date to 8:00:00 a.m. on May 15, 2004, and uses Date.
Date.setTime() Availability Flash Player 5. Usage my_date.setTime(milliseconds:Number) : Number Parameters milliseconds A number; an integer value where 0 is midnight on January 1, universal time. Returns An integer. Description Method; sets the date for the specified Date object in milliseconds since midnight on January 1, 1970, and returns the new time in milliseconds. Example The following example initially creates a new Date object, setting the time and date to 8:00 a.m.
Date.setUTCDate() Availability Flash Player 5. Usage my_date.setUTCDate(date:Number) : Number Parameters date A number; an integer from 1 to 31. Returns An integer. Description Method; sets the date for the specified Date object in universal time and returns the new time in milliseconds. Calling this method does not modify the other fields of the specified Date object, but Date.getUTCDay() and Date.getDay() can report a new value if the day of the week changes as a result of calling this method.
Date.setUTCFullYear() Availability Flash Player 5. Usage my_date.setUTCFullYear(year:Number [, month:Number [, date:Number]]) : Number Parameters year month date An integer that represents the year specified as a full four-digit year, such as 2000. An integer from 0 (January) to 11 (December). This parameter is optional. An integer from 1 to 31. This parameter is optional. Returns An integer.
Date.setUTCHours() Availability Flash Player 5. Usage my_date.setUTCHours(hour:Number [, minute:Number [, second:Number [, millisecond:Number]]]) : Number Parameters hour A number; an integer from 0 (midnight) to 23 (11 p.m.). minute A number; an integer from 0 to 59. This parameter is optional. second A number; an integer from 0 to 59. This parameter is optional. millisecond A number; an integer from 0 to 999. This parameter is optional. Returns An integer.
Date.setUTCMilliseconds() Availability Flash Player 5. Usage my_date.setUTCMilliseconds(millisecond:Number) : Number Parameters millisecond An integer from 0 to 999. Returns An integer. Description Method; sets the milliseconds for the specified Date object in universal time and returns the new time in milliseconds. Example The following example initially creates a new Date object, setting the date to 8:30 a.m. on May 15, 2004 with the milliseconds value set to 250, and uses Date.
Date.setUTCMinutes() Availability Flash Player 5. Usage my_date.setUTCMinutes(minute:Number [, second:Number [, millisecond:Number]]) : Number Parameters minute An integer from 0 to 59. second An integer from 0 to 59. This parameter is optional. millisecond An integer from 0 to 999. This parameter is optional. Returns An integer. Description Method; sets the minute for the specified Date object in universal time and returns the new time in milliseconds.
Date.setUTCMonth() Availability Flash Player 5. Usage my_date.setUTCMonth(month:Number [, date:Number]) : Number Parameters month date An integer from 0 (January) to 11 (December). An integer from 1 to 31. This parameter is optional. Returns An integer. Description Method; sets the month, and optionally the day, for the specified Date object in universal time and returns the new time in milliseconds. Calling this method does not modify the other fields of the specified Date object, but Date.
Date.setUTCSeconds() Availability Flash Player 5. Usage my_date.setUTCSeconds(second:Number [, millisecond:Number]) : Number Parameters second An integer from 0 to 59. millisecond An integer from 0 to 999. This parameter is optional. Returns An integer. Description Method; sets the seconds for the specified Date object in universal time and returns the new time in milliseconds. Example The following example initially creates a new Date object, setting the time and date to 8:00:00 a.m.
Date.setYear() Availability Flash Player 5. Usage my_date.setYear(year:Number) : Number Parameters A number that represents the year. If year is an integer between 0–99, setYear sets the year at 1900 + year; otherwise, the year is the value of the year parameter. year Returns An integer. Description Method; sets the year for the specified Date object in local time and returns the new time in milliseconds. Local time is determined by the operating system on which Flash Player is running.
Date.toString() Availability Flash Player 5. Usage my_date.toString() : String Parameters None. Returns A string. Description Method; returns a string value for the specified date object in a readable format. Example The following example returns the information in the dateOfBirth_date Date object as a string: var dateOfBirth_date:Date = new Date(74, 7, 12, 18, 15); trace (dateOfBirth_date); trace (dateOfBirth_date.
Date.UTC() Availability Flash Player 5. Usage Date.UTC(year:Number, month:Number [, date:Number [, hour:Number [, minute:Number [, second:Number [, millisecond:Number ]]]]]) : Number Parameters year month A four-digit integer that represents the year (for example, 2000). An integer from 0 (January) to 11 (December). date An integer from 1 to 31. This parameter is optional. hour An integer from 0 (midnight) to 23 (11 p.m.). minute An integer from 0 to 59. This parameter is optional.
CHAPTER 2 ActionScript Language Reference default Availability Flash Player 6. Usage default: statements Parameters statements Any statements. Returns Nothing. Description Statement; defines the default case for a switch statement. The statements execute if the expression parameter of the switch statement doesn’t equal (using the strict equality [===] operation) any of the expression parameters that follow the case keywords for a given switch statement.
CHAPTER 2 ActionScript Language Reference delete Availability Flash Player 5. Usage delete reference Parameters reference The name of the variable or object to eliminate. Returns A Boolean value. Description Operator; destroys the object reference specified by the reference parameter, and returns true if the reference is successfully deleted; false otherwise. This operator is useful for freeing memory used by scripts. You can use the delete operator to remove references to objects.
Usage 3: The following example deletes an object property: var my_array:Array = new Array(); my_array[0] = "abc"; // my_array.length == 1 my_array[1] = "def"; // my_array.length == 2 my_array[2] = "ghi"; // my_array.length == 3 // my_array[2] is deleted, but Array.length is not changed delete my_array[2]; trace(my_array.length); // output: 3 trace(my_array); // output: abc,def,undefined Usage 4: The following example shows the behavior of delete on object references: var ref1:Object = new Object(); ref1.
CHAPTER 2 ActionScript Language Reference do while Availability Flash Player 4. Usage do { statement(s) } while (condition) Parameters condition The condition to evaluate. statement(s) The statement(s) to execute as long as the condition parameter evaluates to true. Returns Nothing. Description Statement; similar to a while loop, except that the statements are executed once before the initial evaluation of the condition.
See also break, continue, while 282 Chapter 2: ActionScript Language Reference
duplicateMovieClip() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage duplicateMovieClip(target:String, newname:String, depth:Number) : Void Parameters target newname The target path of the movie clip to duplicate. A unique identifier for the duplicated movie clip. A unique depth level for the duplicated movie clip. The depth level is a stacking order for duplicated movie clips.
dynamic CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Usage dynamic class className [ extends superClass ] [ implements interfaceName [, interfaceName... ] ] { // class definition here } Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.
/* output: craig.age = 32 craig.name = Craiggers */ If you add an undeclared function, dance, an error is generated, as shown in the following example: trace(""); craig.dance = true; for (i in craig) { trace("craig."+i +" = "+ craig[i]); } /* output: **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 14: There is no property with the name 'dance'. craig.
CHAPTER 2 ActionScript Language Reference else Availability Flash Player 4. Usage if (condition){ statement(s); } else { statement(s); } Parameters condition An expression that evaluates to true or false. statement(s) An alternative series of statements to run if the condition specified in the if statement is false. Returns Nothing. Description Statement; specifies the statements to run if the condition in the if statement returns false.
CHAPTER 2 ActionScript Language Reference else if Availability Flash Player 4. Usage if (condition){ statement(s); } else if (condition){ statement(s); } Parameters condition An expression that evaluates to true or false. statement(s) An alternative series of statements to run if the condition specified in the if statement is false. Returns Nothing. Description Statement; evaluates a condition and specifies the statements to run if the condition in the initial if statement returns false.
#endinitclip CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Usage #endinitclip Parameters None. Returns Nothing. Description Compiler directive; indicates the end of a block of initialization actions. Example #initclip ...initialization actions go here...
CHAPTER 2 ActionScript Language Reference Error class Availability Flash Player 7. Description Contains information about an error that occurred in a script. You create an Error object using the Error constructor function. Typically, you throw a new Error object from within a try code block that is then caught by a catch or finally code block. You can also create a subclass of the Error class and throw instances of that subclass. Method summary for the Error class Method Description Error.
throw new Error("Strings to not match."); } } try { compareStrings("Dog", "dog"); // output: Strings to not match. } catch (e_err:Error) { trace(e_err.toString()); } See also throw, try..catch..
Error.message Availability Flash Player 7. Usage my_err.message:String Description Property; contains the message associated with the Error object. By default, the value of this property is "Error". You can specify a message property when you create an Error object by passing the error string to the Error constructor function. Example In the following example, a function throws a specified message depending on the parameters entered into theNum.
Error.name Availability Flash Player 7. Usage myError.name:String Description Property; contains the name of the Error object. By default, the value of this property is "Error". Example In the following example, a function throws a specified error depending on the two numbers that you try to divide.
Error.toString() Availability Flash Player 7. Usage my_err.toString() : String Returns A string. Description Method; returns the string "Error" by default or the value contained in Error.message, if defined. Example In the following example, a function throws an error (with a specified message) if the two strings that are passed to it are not identical: function compareStrings(str1_str:String, str2_str:String):Void { if (str1_str != str2_str) { throw new Error("Strings to not match.
CHAPTER 2 ActionScript Language Reference escape() Availability Flash Player 5. Usage escape(expression:String) : String Parameters expression The expression to convert into a string and encode in a URL-encoded format. Returns URL-encoded string. Description Function; converts the parameter to a string and encodes it in a URL-encoded format, where all nonalphanumeric characters are replaced with % hexadecimal sequences.
CHAPTER 2 ActionScript Language Reference eval() Availability Flash Player 5 or later for full functionality. You can use the eval() function when exporting to Flash Player 4, but you must use slash notation and can access only variables, not properties or objects. Usage eval(expression:String) : Object Parameters expression A string containing the name of a variable, property, object, or movie clip to retrieve. Returns A value, reference to an object or movie clip, or undefined.
You can also use the following ActionScript: for (var i = 1; i<=3; i++) { this["square"+i+"_mc"].
CHAPTER 2 ActionScript Language Reference extends Availability Flash Player 6. Usage class className extends otherClassName {} interface interfaceName extends otherInterfaceName {} Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel. Parameters className The name of the class you are defining.
The following example shows a second AS file, called Car.as, in the same directory. This class extends the Vehicle class, modifying it in three ways. First, the Car class adds a variable fullSizeSpare to track whether the car object has a full-size spare tire. Second, it adds a new method specific to cars, activateCarAlarm(), that activates the car’s anti-theft alarm. Third, it overrides the stop() function to add the fact that the Car class uses an anti-lock braking system to stop.
false CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage false Description Constant; a unique Boolean value that represents the opposite of true. When automatic data typing converts false to a number, it becomes 0; when it converts false to a string, it becomes "false". For more information, see “Automatic data typing” in Using ActionScript in Flash.
_focusrect CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage _focusrect = Boolean; Description Property (global); specifies whether a yellow rectangle appears around the button or movie clip that has keyboard focus. If _focusrect is set to its default value of true, then a yellow rectangle appears around the currently focused button or movie clip as the user presses the Tab key to navigate through objects in a SWF file.
CHAPTER 2 ActionScript Language Reference for Availability Flash Player 5. Usage for(init; condition; next) { statement(s); } Parameters An expression to evaluate before beginning the looping sequence; usually an assignment expression. A var statement is also permitted for this parameter. init condition An expression that evaluates to true or false. The condition is evaluated before each loop iteration; the loop exits when the condition evaluates to false.
The following example shows that curly braces ({}) are not necessary if only one statement will execute: var sum:Number = 0; for (var i:Number = 1; i<=100; i++) sum += i; trace(sum); // output: 5050 See also ++ (increment), –– (decrement), for..
CHAPTER 2 ActionScript Language Reference for..in Availability Flash Player 5. Usage for(variableIterant in object){ statement(s); } Parameters The name of a variable to act as the iterant, referencing each property of an object or element in an array. variableIterant object The name of an object to be iterated. statement(s) An instruction to execute for each iteration. Returns Nothing.
//output myObject.name = Tara myObject.age = 27 myObject.city = San Francisco The following example shows using for..in to iterate over the elements of an array: var myArray:Array = new Array("one", "two", "three"); for (var index in myArray) trace("myArray["+index+"] = " + myArray[index]); // output: myArray[2] = three myArray[1] = two myArray[0] = one The following example uses the typeof operator with for..
CHAPTER 2 ActionScript Language Reference fscommand() Availability Flash Player 3. Usage fscommand("command", "parameters") Parameters A string passed to the host application for any use, or a command passed to Flash Player. command parameters A string passed to the host application for any use, or a value passed to Flash Player. Returns Nothing. Description Function; lets the SWF file communicate with either Flash Player or the program hosting Flash Player, such as a web browser.
The exec command can contain only the characters A–Z, a–z, 0–9, period (.), and underscore (_). The exec command runs in the subdirectory fscommand only. In other words, if you use the fscommand exec command to call an application, the application must reside in a subdirectory named fscommand. Usage 2: To use the fscommand() function to send a message to a scripting language such as JavaScript in a web browser, you can pass any two parameters in the command and parameters parameters.
function myDocument_DoFSCommand(command, args) { if (command == "messagebox") { alert(args); } } In the Flash document, add the fscommand() function to a button: fscommand("messagebox", "This is a message box called from within Flash.") You can also use expressions for the fscommand() function and parameters, as in the following example: fscommand("messagebox", "Hello, " + name + ", welcome to our website!") To test the SWF file, select File > Publish Preview > HTML.
CHAPTER 2 ActionScript Language Reference function Availability Flash Player 5. Usage function functionname ([parameter0, parameter1,...parameterN]){ statement(s) } function ([parameter0, parameter1,...parameterN]){ statement(s) } Parameters functionname parameter The name of the new function. This parameter is optional. An identifier that represents a parameter to pass to the function. This parameter is optional. statement(s) Any ActionScript instruction you have defined for the body of the function.
Example The following example defines the function sqr, which accepts one parameter and returns the of the parameter: Math.pow(x, 2) function sqr(x:Number) { return Math.pow(x, 2); } var y:Number = sqr(3); trace(y); // output: 9 If the function is defined and used in the same script, the function definition may appear after using the function: var y:Number = sqr(3); trace(y); // output: 9 function sqr(x:Number) { return Math.
CHAPTER 2 ActionScript Language Reference Function class Availability Flash Player 6. Description Both user-defined and built-in functions in ActionScript are represented by Function objects, which are instances of the Function class. Method summary for the Function class 310 Method Description Function.apply() Invokes the function represented by a Function object, with parameters passed in through an array. Function.call() Invokes the function represented by a Function object.
Function.apply() Availability Flash Player 6. Usage myFunction.apply(thisObject:Object, argumentsArray:Array) Parameters thisObject The object to which myFunction is applied. argumentsArray An array whose elements are passed to myFunction as parameters. Returns Any value that the called function specifies. Description Method; specifies the value of this to be used within any function that ActionScript calls. This method also specifies the parameters to be passed to any called function.
trace("this == myObj? " + (this == myObj)); trace("arguments: " + arguments); } // instantiate an object var myObj:Object = new Object(); // create arrays to pass as a parameter to apply() var firstArray:Array = new Array(1,2,3); var secondArray:Array = new Array("a", "b", "c"); // use apply() to set the value of this to be myObj and send firstArray theFunction.
Function.call() Availability Flash Player 6. Usage myFunction.call(thisObject:Object, parameter1, ..., parameterN) Parameters thisObject An object that specifies the value of this within the function body. A parameter to be passed to the myFunction. You can specify zero or more parameters. parameter1 parameterN Returns Nothing. Description Method; invokes the function represented by a Function object.
var obj:Object = new myObject(); myMethod.call(obj, obj); The trace() statement displays: this == obj? true See also Function.
CHAPTER 2 ActionScript Language Reference get Availability Flash Player 6. Usage function get property() { // your statements here } Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.
Enter the following ActionScript in a frame on the Timeline: var giants:Team = new Team("San Fran", "SFO"); trace(giants.name); giants.name = "San Francisco"; trace(giants.name); /* output: San Fran San Francisco */ When you trace giants.name, you use the get method to return the value of the property. See also Object.
getProperty() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage getProperty(my_mc:Object, property:Object) : Object Parameters my_mc The instance name of a movie clip for which the property is being retrieved. property A property of a movie clip. Returns The value of the specified property. Description Function; returns the value of the specified property for the movie clip my_mc.
getTimer() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage getTimer() : Number Parameters None. Returns The number of milliseconds that have elapsed since the SWF file started playing. Description Function; returns the number of milliseconds that have elapsed since the SWF file started playing. Example In the following example, the getTimer() and setInterval() functions are used to create a simple timer: this.createTextField("timer_txt", this.
CHAPTER 2 ActionScript Language Reference getURL() Availability Flash 2. The GET and POST options are available only in Flash Player 4 and later versions. Usage getURL(url:String [, window:String [, "variables":String]]) : Void Parameters url The URL from which to obtain the document. window An optional parameter specifying the window or HTML frame into which the document should load.
In the following example, getURL() is used to send an e-mail message: myBtn_btn.onRelease = function(){ getURL("mailto:you@somedomain.com"); }; In the following ActionScript, JavaScript is used to open an alert window when the SWF file is embedded in a browser window: myBtn_btn.onRelease = function(){ getURL("javascript:alert('you clicked me')"); }; You can also use GET or POST for sending variables.
getVersion() CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage getVersion() : String Parameters None. Returns A string containing Flash Player version and platform information. Description Function; returns a string containing Flash Player version and platform information. The getVersion function returns information only for Flash Player 5 or later versions of Flash Player.
_global object CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Usage _global.identifier Parameters None. Returns A reference to the global object that holds the core ActionScript classes, such as String, Object, Math, and Array. Description Identifier; creates global variables, objects, or classes. For example, you could create a library that is exposed as a global ActionScript object, similar to the Math or Date object.
gotoAndPlay() CHAPTER 2 ActionScript Language Reference Availability Flash 2. Usage gotoAndPlay([scene:String,] frame:Object) : Void Parameters scene An optional string specifying the name of the scene to which the playhead is sent. A number representing the frame number, or a string representing the label of the frame, to which the playhead is sent. frame Returns Nothing. Description Function; sends the playhead to the specified frame in a scene and plays from that frame.
gotoAndStop() CHAPTER 2 ActionScript Language Reference Availability Flash 2. Usage gotoAndStop([scene:String,] frame:Object) : Void Parameters scene An optional string specifying the name of the scene to which the playhead is sent. A number representing the frame number, or a string representing the label of the frame, to which the playhead is sent. frame Returns Nothing. Description Function; sends the playhead to the specified frame in a scene and stops it.
CHAPTER 2 ActionScript Language Reference if Availability Flash Player 4. Usage if(condition) { statement(s); } Parameters condition An expression that evaluates to true or false. statement(s) The instructions to execute if or when the condition evaluates to true. Returns Nothing. Description Statement; evaluates a condition to determine the next action in a SWF file. If the condition is true, Flash runs the statements that follow the condition inside curly braces ({}).
} else { this._parent.message_txt.text = "Very good, you hit the button in "+difference+" seconds.
implements CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Usage myClass implements interface01 [, interface02, ...] Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.
CHAPTER 2 ActionScript Language Reference import Availability Flash Player 6. Usage import className import packageName.* Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This statement is supported in the Actions panel as well as in external class files. Parameters className packageName The fully qualified name of a class you have defined in an external class file.
For more information on importing, see “Importing classes” and “Using packages” in Using ActionScript in Flash.
#include CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage #include "[path] filename.as" Note: Do not place a semicolon (;) at the end of the line that contains the #include statement. Parameters [path] filename.as The filename and optional path for the script to add to the Actions panel or to the current script; .as is the recommended filename extension. Returns Nothing.
To specify an absolute path for the AS file, use the format supported by your platform (Macintosh or Windows). See the following example section. (This usage is not recommended because it requires the directory structure to be the same on any computer that you use to compile the script.) Note: If you place files in the First Run/Include directory or in the global Include directory, back up these files. If you ever need to uninstall and reinstall Flash, these directories might be deleted and overwritten.
Infinity CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage Infinity Description Constant; specifies the IEEE-754 value representing positive infinity. The value of this constant is the same as Number.POSITIVE_INFINITY.
#initclip CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Usage #initclip order Parameters An integer that specifies the execution order of blocks of #initclip code. This is an optional parameter. order Description Compiler directive; indicates the beginning of a block of initialization actions. When multiple clips are initialized at the same time, you can use the order parameter to specify which initialization occurs first.
instanceof CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Usage object instanceof class Parameters An ActionScript object. object class A reference to an ActionScript constructor function, such as String or Date. Returns If object is an instance of class, instanceof returns true; false otherwise. Also, _global returns false. instanceof Object Description Operator; determines whether an object belongs to a specified class. Tests whether object is an instance of class.
interface CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Usage interface InterfaceName [extends InterfaceName ] {} Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel. Description Keyword; defines an interface.
// filename Ib.as interface Ib { function o():Void; } class D implements Ia, Ib { function k():Number {return 15;} function n(x:Number):Number {return x*x;} function o():Void {trace("o");} } // external script mvar = new D(); trace(mvar.k()); trace(mvar.n(7)); trace(mvar.
intrinsic CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Usage intrinsic class className [ extends superClass ] [ implements interfaceName [, interfaceName... ] ] { // class definition here } Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.
this.radius = radius; this.getArea = function(){ return Math.PI*this.radius*this.radius; }; this.getDiameter = function() { return 2*this.radius; }; this.setRadius = function(param_radius) { this.radius = param_radius; } } // ActionScript 2.0 code that uses the Circle class var myCircle:Circle = new Circle(5); trace(myCircle.getArea()); trace(myCircle.getDiameter()); myCircle.setRadius("10"); trace(myCircle.radius); trace(myCircle.getArea()); trace(myCircle.
CHAPTER 2 ActionScript Language Reference isFinite() Availability Flash Player 5. Usage isFinite(expression:Object) : Boolean Parameters expression A Boolean value, variable, or other expression to be evaluated. Returns A Boolean value. Description Function; evaluates expression and returns true if it is a finite number or false if it is infinity or negative infinity. The presence of infinity or negative infinity indicates a mathematical error condition such as division by 0.
CHAPTER 2 ActionScript Language Reference isNaN() Availability Flash Player 5. Usage isNaN(expression:Object) : Boolean Parameters expression A Boolean, variable, or other expression to be evaluated. Returns A Boolean value. Description Function; evaluates the parameter and returns true if the value is NaN (not a number). This function is useful for checking whether a mathematical expression evaluates successfully to a number.
CHAPTER 2 ActionScript Language Reference Key class Availability Flash Player 6. Description The Key class is a top-level class whose methods and properties you can use without using a constructor. Use the methods of the Key class to build an interface that can be controlled by a user with a standard keyboard. The properties of the Key class are constants representing the keys most commonly used to control games.
Property Description Key code Key.PGUP The key code value for the Page Up key. 33 Key.RIGHT The key code value for the Right Arrow key. 39 Key.SHIFT The key code value for the Shift key. 16 Key.SPACE The key code value for the Spacebar. 32 Key.TAB The key code value for the Tab key. 9 Key.UP The key code value for the Up Arrow key. 38 Listener summary for the Key class 342 Method Description Key.onKeyDown Notified when a key is pressed. Key.
Key.addListener() Availability Flash Player 6. Usage Key.addListener (newListener:Object) : Void Parameters newListener An object with methods onKeyDown and onKeyUp. Returns Nothing. Description Method; registers an object to receive onKeyDown and onKeyUp notification. When a key is pressed or released, regardless of the input focus, all listening objects registered with addListener() have either their onKeyDown method or onKeyUp method invoked. Multiple objects can listen for keyboard notifications.
myListener.onKeyDown = myOnKeyDown; Key.addListener(myListener); my_btn.onPress = myOnPress; my_btn._accProps.shortcut = "Ctrl+7"; Accessibility.updateProperties(); See also Key.getCode(), Key.isDown(), Key.onKeyDown, Key.onKeyUp, Key.
Key.BACKSPACE Availability Flash Player 5. Usage Key.BACKSPACE:Number Description Property; constant associated with the key code value for the Backspace key (8). Example The following example creates a new listener object and defines a function for onKeyDown. The last line uses addListener() to register the listener with the Key object so that it can receive notification from the key down event. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.
Key.CAPSLOCK Availability Flash Player 5. Usage Key.CAPSLOCK:Number Description Property; constant associated with the key code value for the Caps Lock key (20). Example The following example creates a new listener object and defines a function for onKeyDown. The last line uses addListener() to register the listener with the Key object so that it can receive notification from the key down event. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.
Key.CONTROL Availability Flash Player 5. Usage Key.CONTROL:Number Description Property; constant associated with the key code value for the Control key (17). Example The following example assigns the keyboard shortcut Control+7 to a button with an instance name of my_btn and makes information about the shortcut available to screen readers (see _accProps). In this example, when you press Control+7 the myOnPress function displays the text hello in the Output panel.
Key.DELETEKEY Availability Flash Player 5. Usage Key.DELETEKEY:Number Description Property; constant associated with the key code value for the Delete key (46). Example The following example lets you draw lines with the mouse pointer using the Drawing API and listener objects. Press the Backspace or Delete key to remove the lines that you draw. this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth()); var mouseListener:Object = new Object(); mouseListener.onMouseDown = function() { this.
Key.DOWN Availability Flash Player 5. Usage Key.DOWN:Number Description Property; constant associated with the key code value for the Down Arrow key (40). Example The following example moves a movie clip called car_mc a constant distance (10) when you press the arrow keys. A sound plays when you press the Spacebar. Give a sound in the library a linkage identifier of horn_id for this example. var DISTANCE:Number = 10; var horn_sound:Sound = new Sound(); horn_sound.
Key.END Availability Flash Player 5. Usage Key.END:Number Description Property; constant associated with the key code value for the End key (35).
Key.ENTER Availability Flash Player 5. Usage Key.ENTER:Number Description Property; constant associated with the key code value for the Enter key (13). Example The following example moves a movie clip called car_mc a constant distance (10) when you press the arrow keys. The car_mc instance stops when you press Enter and delete the onEnterFrame event. var DISTANCE:Number = 5; var keyListener:Object = new Object(); keyListener.onKeyDown = function() { switch (Key.getCode()) { case Key.LEFT : car_mc.
Key.ESCAPE Availability Flash Player 5. Usage Key.ESCAPE:Number Description Property; constant associated with the key code value for the Escape key (27). Example The following example sets a timer. When you press Escape, the Output panel displays information that includes how long it took you to press the key. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.ESCAPE)) { // get the current timer, convert the value to seconds and round it to two decimal places.
Key.getAscii() Availability Flash Player 5. Usage Key.getAscii() : Number Parameters None. Returns A number; an integer that represents the ASCII value of the last key pressed. Description Method; returns the ASCII code of the last key pressed or released. The ASCII values returned are English keyboard values. For example, if you press Shift+2, Key.getAscii() returns @ on a Japanese keyboard, which is the same as it does on an English keyboard.
Key.getCode() Availability Flash Player 5. Usage Key.getCode() : Number Parameters None. Returns A number; an integer that represents the key code of the last key pressed. Description Method; returns the key code value of the last key pressed. To match the returned key code value with the key on a standard keyboard, see Appendix C, “Keyboard Keys and Key Code Values”. in Using ActionScript in Flash. Example The following example calls the getCode() method any time a key is pressed.
Key.HOME Availability Flash Player 5. Usage Key.HOME:Number Description Property; constant associated with the key code value for the Home key (36). Example The following example attaches a draggable movie clip called car_mc at the x and y coordinates of 0,0. When you press the Home key, car_mc returns to 0,0. Create a movie clip that has a linkage ID car_id, and add the following ActionScript to Frame 1 of the Timeline: this.attachMovie("car_id", "car_mc", this.
Key.INSERT Availability Flash Player 5. Usage Key.INSERT:Number Description Property; constant associated with the key code value for the Insert key (45). Example The following example creates a new listener object and defines a function for onKeyDown. The last line uses addListener() to register the listener with the Key object so that it can receive notification from the key down event and display information in the Output panel. var keyListener:Object = new Object(); keyListener.
Key.isDown() Availability Flash Player 5. Usage Key.isDown(keycode:Number) : Boolean Parameters keycode The key code value assigned to a specific key or a Key class property associated with a specific key. To match the returned key code value with the key on a standard keyboard, see Appendix C, “Keyboard Keys and Key Code Values” in Using ActionScript in Flash. Returns A Boolean value. Description Method: returns true if the key specified in keycode is pressed; false otherwise.
Key.isToggled() Availability Flash Player 5. Usage Key.isToggled(keycode:Number) : Boolean Parameters keycode The key code for the Caps Lock key (20) or the Num Lock key (144). Returns A Boolean value. Description Method: returns true if the Caps Lock or Num Lock key is activated (toggled to an active state); false otherwise. Although the term toggled usually means that something is switched between two options, the method Key.isToggled() will only return true if the key is toggled to an active state.
numLock_txt.autoSize = true; numLock_txt.html = true; // var keyListener:Object = new Object(); keyListener.onKeyDown = function() { capsLock_txt.htmlText = "Caps Lock: "+Key.isToggled(Key.CAPSLOCK); numLock_txt.htmlText = "Num Lock: "+Key.isToggled(144); }; Key.addListener(keyListener); Key.
Key.LEFT Availability Flash Player 5. Usage Key.LEFT:Number Description Property; constant associated with the key code value for the Left Arrow key (37). Example The following example moves a movie clip called car_mc a constant distance (10) when you press the arrow keys. A sound plays when you press the Spacebar. Give a sound in the library a linkage identifier of horn_id for this example. var DISTANCE:Number = 10; var horn_sound:Sound = new Sound(); horn_sound.
Key.onKeyDown Availability Flash Player 6. Usage keyListener.onKeyDown Description Listener; notified when a key is pressed. To use onKeyDown, you must create a listener object. You can then define a function for onKeyDown and use addListener() to register the listener with the Key object, as shown in the following example: var keyListener:Object = new Object(); keyListener.onKeyDown = function() { trace("DOWN -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.
Key.onKeyUp Availability Flash Player 6. Usage keyListener.onKeyUp Description Listener; notified when a key is released. To use onKeyUp, you must create a listener object. You can then define a function for onKeyUp and use addListener() to register the listener with the Key object, as shown in the following example: var keyListener:Object = new Object(); keyListener.onKeyDown = function() { trace("DOWN -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii())); }; keyListener.
Key.PGDN Availability Flash Player 5. Usage Key.PGDN:Number Description Property; constant associated with the key code value for the Page Down key (34). Example The following example rotates a movie clip called car_mc when you press the Page Down and Page Up keys. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.PGDN)) { car_mc._rotation += 5; } else if (Key.isDown(Key.PGUP)) { car_mc._rotation -= 5; } }; Key.addListener(keyListener); Key.
Key.PGUP Availability Flash Player 5. Usage Key.PGUP:Number Description Property; constant associated with the key code value for the Page Up key (33). Example The following example rotates a movie clip called car_mc when you press the Page Down and Page Up keys. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.PGDN)) { car_mc._rotation += 5; } else if (Key.isDown(Key.PGUP)) { car_mc._rotation -= 5; } }; Key.
Key.removeListener() Availability Flash Player 6. Usage Key.removeListener (listener:Object) : Boolean Parameters listener An object. Returns If the listener was successfully removed, the method returns true. If the listener was not successfully removed (for example, because the listener was not on the Key object’s listener list), the method returns false. Description Method; removes an object previously registered with Key.addListener().
Key.RIGHT Availability Flash Player 5. Usage Key.RIGHT:Number Description Property; constant associated with the key code value for the Right Arrow key (39). Example The following example moves a movie clip called car_mc a constant distance (10) when you press the arrow keys. A sound plays when you press the Spacebar. Give a sound in the library a linkage identifier of horn_id for this example. var DISTANCE:Number = 10; var horn_sound:Sound = new Sound(); horn_sound.
Key.SHIFT Availability Flash Player 5. Usage Key.SHIFT:Number Description Property; constant associated with the key code value for the Shift key (16). Example The following example scales car_mc when you press Shift. var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.SHIFT)) { car_mc._xscale *= 2; car_mc._yscale *= 2; } else if (Key.isDown(Key.CONTROL)) { car_mc._xscale /= 2; car_mc._yscale /= 2; } }; Key.addListener(keyListener); Key.
Key.SPACE Availability Flash Player 5. Usage Key.SPACE:Number Description Property; constant associated with the key code value for the Spacebar (32). Example The following example moves a movie clip called car_mc a constant distance (10) when you press the arrow keys. A sound plays when you press the Spacebar. Give a sound in the library a linkage identifier of horn_id for this example. var DISTANCE:Number = 10; var horn_sound:Sound = new Sound(); horn_sound.
Key.TAB Availability Flash Player 5. Usage Key.TAB:Number Description Property; constant associated with the key code value for the Tab key (9). Example The following example creates a text field, and displays the date in the text field when you press Tab. this.createTextField("date_txt", this.getNextHighestDepth(), 0, 0, 100, 22); date_txt.autoSize = true; var keyListener:Object = new Object(); keyListener.onKeyDown = function() { if (Key.isDown(Key.TAB)) { var today_date:Date = new Date(); date_txt.
Key.UP Availability Flash Player 5. Usage Key.UP:Number Description Property; constant associated with the key code value for the Up Arrow key (38). Example The following example moves a movie clip called car_mc a constant distance (10) when you press the arrow keys. A sound plays when you press the Spacebar. Give a sound in the library a linkage identifier of horn_id for this example. var DISTANCE:Number = 10; var horn_sound:Sound = new Sound(); horn_sound.
_level CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage _levelN Description Identifier; a reference to the root Timeline of _levelN. You must use loadMovieNum() to load SWF files into the Flash Player before you use the _level property to target them. You can also use _levelN to target a loaded SWF file at the level assigned by N.
loadMovie() CHAPTER 2 ActionScript Language Reference Availability Flash Player 3. Usage loadMovie(url:String,target:Object [, method:String]) : Void loadMovie(url:String,target:String [, method:String]) : Void Parameters The absolute or relative URL of the SWF or JPEG file to be loaded. A relative path must be relative to the SWF file at level 0. Absolute URLs must include the protocol reference, such as http:// or file:///.
Example Usage 1: The following example loads the SWF file circle.swf from the same directory and replaces a movie clip called mySquare that already exists on the Stage: loadMovie("circle.swf", mySquare); // equivalent statement (Usage 1): loadMovie("circle.swf", _level0.mySquare); // equivalent statement (Usage 2): loadMovie("circle.swf", “mySquare”); The following example loads the SWF file circle.
loadMovieNum() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Flash 4 files opened in Flash 5 or later are converted to use the correct syntax. Usage loadMovieNum(url:String,level:Number [, variables:String]) : Void Parameters The absolute or relative URL of the SWF or JPEG file to be loaded. A relative path must be relative to the SWF file at level 0.
The loadMovieNum() action also lets you load JPEG files into a SWF file while it plays. For images and SWF files, the upper left corner of the image aligns with the upper left corner of the Stage when the file loads. Also in both cases, the loaded file inherits rotation and scaling, and the original content is overwritten in the specified level. Use unloadMovieNum() to remove SWF files or images that were loaded with loadMovieNum(). Example The following example loads the JPEG image tim.
loadVariables() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4; behavior changed in Flash Player 7. Usage loadVariables (url:String , target:Object [, variables:String]) : Void Parameters An absolute or relative URL where the variables are located. If the SWF file issuing this call is running in a web browser, url must be in the same domain as the SWF file; for details, see the Description section. url target The target path to a movie clip that receives the loaded variables.
If you want to load variables into a specific level, use loadVariablesNum() instead of loadVariables(). Example The following example loads information from a text file called params.txt into the target_mc movie clip that is created using createEmptyMovieClip(). The setInterval() function is used to check the loading progress. The script checks for a variable in the params.txt file named done. this.createEmptyMovieClip("target_mc", this.getNextHighestDepth()); loadVariables("params.
loadVariablesNum() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4; behavior changed in Flash Player 7. Flash 4 files opened in Flash 5 or later are converted to use the correct syntax. Usage loadVariablesNum (url:String ,level:Number [, variables:String]) : Void Parameters An absolute or relative URL where the variables are located.
If you want to load variables into a target MovieClip, use loadVariables() instead of loadVariablesNum(). Example The following example loads information from a text file called params.txt into the main Timeline of the SWF at level 2 in Flash Player. The variable names of the text fields must match the variable names in the params.txt file. The setInterval() function is used to check the progress of the data being loaded into the SWF. The script checks for a variable in the params.txt file named done.
LoadVars class CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Description The LoadVars class is an alternative to the loadVariables() function for transferring variables between a Flash application and a server. You can use the LoadVars class to obtain verification of successful data loading and to monitor download progress. The LoadVars class lets you send all the variables in an object to a specified URL and load all the variables at a specified URL into an object.
Property summary for the LoadVars class Property Description LoadVars.contentType A string that indicates the MIME type of the data. LoadVars.loaded A Boolean value that indicates whether a load or sendAndLoad operation has completed. Event handler summary for the LoadVars class Event handler Description LoadVars.onData Invoked when data has been completely downloaded from the server, or when an error occurs while data is downloading from a server. LoadVars.
LoadVars.addRequestHeader() Availability Flash Player 6. Usage my_lv.addRequestHeader(headerName:String, headerValue:String) : Void my_lv.addRequestHeader(["headerName_1":String, "headerValue_1" ... "headerName_n", "headerValue_n":String]) : Void Parameters headerName headerValue A string that represents an HTTP request header name. A string that represents the value associated with headerName. Returns Nothing.
See also XML.addRequestHeader() LoadVars.
LoadVars.contentType Availability Flash Player 6. Usage my_lv.contentType:String Description Property; the MIME type that is sent to the server when you call LoadVars.send() or LoadVars.sendAndLoad(). The default is application/x-www-form-urlencoded. Example The following example creates a LoadVars object and displays the default content type of the data that is sent to the server. var my_lv:LoadVars = new LoadVars(); trace(my_lv.
LoadVars.decode() Availability Flash Player 7. Usage my_lv.decode(variables:String) : Void Parameters variables A URL-encoded query string containing name/value pairs. Returns Nothing. Description Method; converts the variable string to properties of the specified LoadVars object. This method is used internally by the LoadVars.onData event handler. Most users do not need to call this method directly. If you override the LoadVars.onData event handler, you can explicitly call LoadVars.
LoadVars.getBytesLoaded() Availability Flash Player 6. Usage my_lv.getBytesLoaded() : Number Parameters None. Returns An integer. Description Method; returns the number of bytes downloaded by LoadVars.load() or LoadVars.sendAndLoad(). This method returns undefined if no load operation is in progress or if a load operation has not yet begun. Example The following example uses a ProgressBar instance and a LoadVars object to download a text file.
LoadVars.getBytesTotal() Availability Flash Player 6. Usage my_lv.getBytesTotal() : Number Parameters None. Returns An integer. Description Method; returns the total number of bytes downloaded by LoadVars.load() or LoadVars.sendAndLoad(). This method returns undefined if no load operation is in progress or if a load operation has not started.
} }; my_lv.
LoadVars.load() Availability Flash Player 6; behavior changed in Flash Player 7. Usage my_lv.load(url:String) : Boolean Parameters A string; the URL from which to download the variables. If the SWF file issuing this call is running in a web browser, url must be in the same domain as the SWF file; for details, see the Description section. url Returns A Boolean value; false if no parameter is specified, true otherwise.
trace(this.toString()); } else { trace("Error loading/parsing LoadVars."); } }; my_lv.load("http://www.flash-mx.com/mm/params.txt"); For an in-depth example, see “Using the LoadVars class” in Using ActionScript in Flash and the Macromedia DevNet article “Macromedia Flash MX and PHP” at www.macromedia.com/ devnet/mx/flash/articles/flashmx_php.html. An example is also in the guestbook.fla file in the HelpExamples folder.
LoadVars.loaded Availability Flash Player 6. Usage my_lv.loaded:Boolean Description Property; a Boolean value that indicates whether a load or sendAndLoad operation has completed, undefined by default. When a LoadVars.load() or LoadVars.sendAndLoad() operation is started, the loaded property is set to false; when the operation completes, the loaded property is set to true. If the operation has not completed or has failed with an error, the loaded property remains set to false.
LoadVars.onData Availability Flash Player 6. Usage my_lv.onData = function(src:String) { // your statements here } Parameters src A string or undefined; the raw (unparsed) data from a LoadVars.load() or method call. LoadVars.sendAndLoad() Returns Nothing. Description Event handler; invoked when data has completely downloaded from the server or when an error occurs while data is downloading from a server.
LoadVars.onLoad Availability Flash Player 6. Usage my_lv.onLoad = function(success:Boolean) { // your statements here } Parameters success A Boolean value that indicates whether the load operation ended in success (true) or failure (false). Returns A Boolean value. Description Event handler; invoked when a LoadVars.load() or LoadVars.sendAndLoad() operation has ended.
To view a more robust example, see the login.fla file in the HelpExamples folder. Typical paths to the HelpExamples folder are: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ • LoadVars.loaded, LoadVars.load(), LoadVars.
LoadVars.send() Availability Flash Player 6. Usage my_lv.send(url:String,target:String [, method:String]) : Boolean Parameters url A string; the URL to which to upload variables. A string; the browser window or frame in which any response will appear. You can enter the name of a specific window or select from the following reserved target names: target • • • • "_self" specifies the current frame in the current window. "_blank" specifies a new window.
Example The following example copies two values from text fields and sends the data to a CFM script, which is used to handle the information. For example, the script might check if the user got a high score and then insert that data into a database table. var my_lv:LoadVars = new LoadVars(); my_lv.playerName = playerName_txt.text; my_lv.playerScore = playerScore_txt.text; my_lv.send("setscore.cfm", "_blank", "POST"); See also LoadVars.sendAndLoad(), XML.
LoadVars.sendAndLoad() Availability Flash Player 6; behavior changed in Flash Player 7. Usage my_lv.sendAndLoad(url:String, targetObject[, method:String]) : Boolean Parameters A string; the URL to which to upload variables. If the SWF file issuing this call is running in a web browser, url must be in the same domain as the SWF file; for details, see “Description”. url targetObject method LoadVars; the LoadVars object that receives the downloaded variables.
Example For the following example, add a TextInput instance called name_ti, a TextArea instance called result_ta, and a Button instance called submit_button to the Stage. When the user clicks the Login button instance in the following example, two LoadVars objects are created: send_lv and result_lv. The send_lv object copies the name from the name_ti instance and sends the data to greeting.cfm.
LoadVars.toString() Availability Flash Player 6. Usage my_lv.toString() : String Parameters None. Returns A string. Description Method; returns a string containing all enumerable variables in my_lv, in the MIME content encoding application/x-www-form-urlencoded. Example The following example instantiates a new LoadVars() object, creates two properties, and uses toString() to return a string containing both properties in URL encoded format: var my_lv:LoadVars = new LoadVars(); my_lv.
LocalConnection class CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Description The LocalConnection class lets you develop SWF files that can send instructions to each other without the use of fscommand() or JavaScript. LocalConnection objects can communicate only among SWF files that are running on the same client computer, but they can be running in different applications—for example, a SWF file running in a browser and a SWF file running in a projector.
Event handler summary for the LocalConnection class Event handler Description LocalConnection.allowDomain Invoked whenever the current (receiving) LocalConnection object receives a request to invoke a method from a sending LocalConnection object. LocalConnection.
See also LocalConnection.connect(), LocalConnection.
LocalConnection.allowDomain Availability Flash Player 6; behavior changed in Flash Player 7. Usage receiving_lc.allowDomain = function([sendingDomain:String]) : Boolean { // Your statements here return true or false } Parameters A string that represents an optional parameter specifying the domain of the SWF file that contains the sending LocalConnection object. sendingDomain Returns Nothing.
sendingDomain=="store.domain.com"); } Also, for files authored for Flash Player 7 or later, you can’t use this method to let SWF files hosted using a secure protocol (HTTPS) allow access from SWF files hosted in nonsecure protocols; you must use the LocalConnection.allowInsecureDomain event handler instead. Occasionally, you might encounter the following situation. Suppose you load a child SWF file from a different domain.
The following example sends a string to the previous SWF file and displays a status message about whether the local connection was able to connect to the file. A TextInput component called name_ti, a TextArea instance called status_ta and a Button instance called send_button are used to display content. var sending_lc:LocalConnection; var sendListener:Object = new Object(); sendListener.click = function(evt:Object) { sending_lc = new LocalConnection(); sending_lc.
LocalConnection.allowInsecureDomain Availability Flash Player 7. Usage receiving_lc.allowInsecureDomain = function([sendingDomain:String]) : Boolean { // Your statements here return true or false } Parameters A string that represents an optional parameter specifying the domain of the SWF file that contains the sending LocalConnection object. sendingDomain Returns A Boolean value.
}; my_lc.allowInsecureDomain = function(sendingDomain:String) { return (sendingDomain == this.domain()); } my_lc.sayHello = function(name:String) { welcome_txt.text = "Hello, "+name; }; my_lc.connect("lc_name"); See also LocalConnection.allowDomain, LocalConnection.connect() LocalConnection.
LocalConnection.close() Availability Flash Player 6. Usage receiving_lc.close() : Void Parameters None. Returns Nothing. Description Method; closes (disconnects) a LocalConnection object. Issue this command when you no longer want the object to accept commands—for example, when you want to issue a LocalConnection.connect() command using the same connectionName parameter in another SWF file.
LocalConnection.connect() Availability Flash Player 6. Usage receiving_lc.connect(connectionName:String) : Boolean Parameters connectionName A string that corresponds to the connection name specified in the command that wants to communicate with receiving_lc. LocalConnection.send() Returns A Boolean value: true if no other process running on the same client computer has already issued this command using the same value for the connectionName parameter; false otherwise.
If you are implementing communication between SWF files in different domains, specifying a string for connectionName that begins with an underscore (_) will make the SWF with the receiving LocalConnection object more portable between domains. Here are the two possible cases: • If the string for connectionName does not begin with an underscore (_), Flash Player adds a prefix with the superdomain and a colon (for example, "myDomain:connectionName").
playback_pb.setStyle("themeColor", "haloBlue"); this.createEmptyMovieClip("timer_mc", this.getNextHighestDepth()); var receiving_lc:LocalConnection = new LocalConnection(); receiving_lc.playMP3 = function(mp3Path:String, mp3Name:String) { song_lbl.text = mp3Name; playback_pb.indeterminate = true; my_sound = new Sound(); my_sound.onLoad = function(success:Boolean) { playback_pb.indeterminate = false; }; my_sound.onSoundComplete = function() { delete timer_mc.onEnterFrame; }; timer_mc.
LocalConnection.domain() Availability Flash Player 6; behavior changed in Flash Player 7. Usage my_lc.domain() : String Parameters None. Returns A string representing the domain of the location of the current SWF file; for more information, see the Description section. Description Method; returns a string representing the domain of the location of the current SWF file. In SWF files published for Flash Player 6, the returned string is the superdomain of the current SWF file.
my_lc.allowDomain = function(sendingDomain):String{ return (sendingDomain==this.domain() || sendingDomain=="www.macromedia.com"); } In the following example, a sending SWF file located at www.yourdomain.com invokes a method in a receiving SWF file located at www.mydomain.com. The sending SWF file includes its domain name as a parameter to the method it invokes, so the receiving SWF file can return a reply value to a LocalConnection object in the correct domain.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 return (aDomain == "mydomain.com"); } lc.aResult = function(aParam) { trace("The sum is " + aParam); } // determine our domain and see if we need to truncate it var channelDomain:String = lc.domain(); if (getVersion() >= 7 && this.getSWFVersion() >= 7) { // split domain name into elements var domainArray:Array = channelDomain.split("."); // if more than two elements are found, // chop off first element to create superdomain if (domainArray.
LocalConnection.onStatus Availability Flash Player 6. Usage sending_lc.onStatus = function(infoObject:Object) : Void{ // your statements here } Parameters A parameter defined according to the status message. For details about this parameter, see the Description section. infoObject Returns Nothing. Description Event handler; invoked after a sending LocalConnection object tries to send a command to a receiving LocalConnection object.
sending_lc = new LocalConnection(); sending_lc.onStatus = function(infoObject:Object) { switch (infoObject.level) { case 'status' : status_ta.text = "LocalConnection connected successfully."; break; case 'error' : status_ta.text = "LocalConnection encountered an error."; break; } }; sending_lc.send("lc_name", "sayHello", name_ti.text); }; send_button.addEventListener("click", sendListener); See also LocalConnection.send(), System.
LocalConnection.send() Availability Flash Player 6. Usage sending_lc.send (connectionName:String, method:String [, p1,...,pN]) : Boolean Parameters connectionName A string that corresponds to the connection name specified in the command that wants to communicate with sending_lc. LocalConnection.connect() method A string specifying the name of the method to be invoked in the receiving LocalConnection object.
• Include the superdomain in connectionName in the sending LocalConnection object—for example, myDomain.com:myConnectionName. In the receiving object, use LocalConnection.allowDomain to specify that connections from the specified superdomain will be accepted (in this case, myDomain.com) or that connections from any domain will be accepted. Note: You cannot specify a superdomain in connectionName in the receiving LocalConnection object—you can only do this in the sending LocalConnection object.
CHAPTER 2 ActionScript Language Reference Math class Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Description The Math class is a top-level class whose methods and properties you can use without using a constructor. Use the methods and properties of this class to access and manipulate mathematical constants and functions.
Method Description Math.pow() Computes x raised to the power of the y. Math.random() Returns a pseudo-random number between 0.0 and 1.0. Math.round() Rounds to the nearest integer. Math.sin() Computes a sine. Math.sqrt() Computes a square root. Math.tan() Computes a tangent. Property summary for the Math class All the following properties for the Math class are constants: 420 Property Description Math.E Euler’s constant and the base of natural logarithms (approximately 2.718). Math.
Math.abs() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.abs(x:Number) : Number Parameters x A number. Returns A number. Description Method; computes and returns an absolute value for the number specified by the parameter x. Example The following example shows how Math.
Math.acos() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.acos(x:Number) : Number Parameters x A number from -1.0 to 1.0. Returns A number; the arc cosine of the parameter x. Description Method; computes and returns the arc cosine of the number specified in the parameter x, in radians.
Math.asin() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.asin(x:Number) : Number; Parameters x A number from -1.0 to 1.0. Returns A number between negative pi divided by 2 and positive pi divided by 2. Description Method; computes and returns the arc sine for the number specified in the parameter x, in radians.
Math.atan() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.atan(tangent:Number) : Number Parameters tangent A number that represents the tangent of an angle. Returns A number between negative pi divided by 2 and positive pi divided by 2.
Math.atan2() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.atan2(y:Number, x:Number) : Number Parameters y A number specifying the y coordinate of the point. x A number specifying the x coordinate of the point. Returns A number.
Math.ceil() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.ceil(x:Number) : Number Parameters x A number or expression. Returns An integer that is both closest to, and greater than or equal to, parameter x. Description Method; returns the ceiling of the specified number or expression.
Math.cos() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.cos(x:Number) : Number Parameters x A number that represents an angle measured in radians. Returns A number from -1.0 to 1.0. Description Method; computes and returns the cosine of the specified angle in radians.
Math.E Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.E:Number Description Constant; a mathematical constant for the base of natural logarithms, expressed as e. The approximate value of e is 2.71828182845905. Example This example shows how Math.
Math.exp() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.exp(x:Number) : Number Parameters x The exponent; a number or expression. Returns A number. Description Method; returns the value of the base of the natural logarithm (e), to the power of the exponent specified in the parameter x. The constant Math.
Math.floor() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.floor(x:Number) : Number Parameters x A number or expression. Returns The integer that is both closest to, and less than or equal to, parameter x. Description Method; returns the floor of the number or expression specified in the parameter x.
Math.log() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.log(x:Number) : Number Parameters x A number or expression with a value greater than 0. Returns The logarithm of parameter x. Description Method; returns the logarithm of parameter x.
Math.LN2 Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.LN2:Number Description Constant; a mathematical constant for the natural logarithm of 2, expressed as loge2, with an approximate value of 0.6931471805599453.
Math.LN10 Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.LN10:Number Description Constant; a mathematical constant for the natural logarithm of 10, expressed as loge10, with an approximate value of 2.302585092994046. Example This example traces the value of Math.LN10. trace(Math.LN10); // output: 2.30258509299405 Math.
Math.LOG2E Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.LOG2E:Number Parameters None. Returns Nothing. Description Constant; a mathematical constant for the base-2 logarithm of the constant e (Math.E), expressed as log2e, with an approximate value of 1.442695040888963387. Example This example traces the value of Math.
Math.LOG10E Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.LOG10E:Number Description Constant; a mathematical constant for the base-10 logarithm of the constant e (Math.E), expressed as log10e, with an approximate value of 0.4342944819032518. Example This example traces the value of Math.LOG10E. trace(Math.
Math.max() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.max(x:Number , y:Number) : Number Parameters x A number or expression. y A number or expression. Returns A number. Description Method; evaluates x and y and returns the larger value.
Math.min() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.min(x:Number , y:Number) : Number Parameters x A number or expression. y A number or expression. Returns A number. Description Method; evaluates x and y and returns the smaller value.
Math.PI Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.PI:Number Parameters None. Returns Nothing. Description Constant; a mathematical constant for the ratio of the circumference of a circle to its diameter, expressed as pi, with a value of 3.141592653589793.
Math.pow() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.pow(x:Number , y:Number) : Number Parameters x A number to be raised to a power. y A number specifying a power the parameter x is raised to. Returns A number. Description Method; computes and returns x to the power of y. Example The following example uses Math.
Math.random() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.random() : Number Parameters None. Returns A number. Description Method; returns a pseudo-random number n, where 0 <= n < 1. The number returned is a pseudo-random number because it is not generated by a truly random natural phenomenon such as radioactive decay.
Math.round() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.round(x:Number) : Number Parameters x A number. Returns A number; an integer. Description Method; rounds the value of the parameter x up or down to the nearest integer and returns the value.
Math.sin() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.sin(x:Number) : Number Parameters x A number that represents an angle measured in radians. Returns A number; the sine of the specified angle (between -1.0 and 1.0). Description Method; computes and returns the sine of the specified angle in radians.
Math.sqrt() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.sqrt(x:Number) : Number Parameters x A number or expression greater than or equal to 0. Returns A number if parameter x is greater than or equal to zero; NaN (not a number) otherwise.
Math.SQRT1_2 Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.SQRT1_2:Number Description Constant; a mathematical constant for the square root of one-half, with an approximate value of 0.7071067811865476. Example This example traces the value of Math.SQRT1_2. trace(Math.SQRT1_2); // Output: 0.
Math.SQRT2 Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.SQRT2 Description Constant; a mathematical constant for the square root of 2, with an approximate value of 1.4142135623730951. Example This example traces the value of Math.SQRT2. trace(Math.SQRT2); // Output: 1.4142135623731 Math.
Math.tan() Availability Flash Player 5. In Flash Player 4, the methods and properties of the Math class are emulated using approximations and might not be as accurate as the non-emulated math functions that Flash Player 5 supports. Usage Math.tan(x:Number) Parameters x A number that represents an angle measured in radians. Returns A number; tangent of parameter x. Description Method; computes and returns the tangent of the specified angle.
Microphone class CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Description The Microphone class lets you capture audio from a microphone attached to the computer that is running Flash Player. The Microphone class is primarily for use with Flash Communication Server but can be used in a limited fashion without the server—for example, to transmit sound from your microphone through the speakers on your local system.
Property (read-only) Description Microphone.names Class property; an array of strings reflecting the names of all available sound capture devices, including sound cards and microphones. Microphone.rate The sound capture rate, in kHz. Microphone.silenceLevel The amount of sound required to activate the microphone. Microphone.silenceTimeOut The number of milliseconds between the time the microphone stops detecting sound and Microphone.onActivity(false) is called. Microphone.
Microphone.activityLevel Availability Flash Player 6. Usage active_mic.activityLevel:Number Description Read-only property; a numeric value that specifies the amount of sound the microphone is detecting. Values range from 0 (no sound is being detected) to 100 (very loud sound is being detected). The value of this property can help you determine a good value to pass to the Microphone.setSilenceLevel() method. If the microphone is available but is not yet being used because Microphone.
Microphone.gain Availability Flash Player 6. Usage active_mic.gain:Number Description Read-only property; the amount by which the microphone boosts the signal. Valid values are 0 to 100. The default value is 50. Example The following example uses a ProgressBar instance called gain_pb to display and a NumericStepper instance called gain_nstep to set the microphone’s gain value. this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.
Microphone.get() Availability Flash Player 6. Usage Microphone.get([index:Number]) : Microphone Note: The correct syntax is Microphone.get(). To assign the Microphone object to a variable, use syntax like active_mic = Microphone.get(). Parameters index An optional zero-based integer that specifies which microphone to get, as determined from the array that Microphone.names contains. To get the default microphone (which is recommended for most applications), omit this parameter.
The user can also specify permanent privacy settings for a particular domain by right-clicking (Windows) or Control-clicking (Macintosh) while a SWF file is playing, choosing Settings, opening the Privacy panel, and selecting Remember. You can’t use ActionScript to set the Allow or Deny value for a user, but you can display the Privacy panel for the user by using System.showSettings(0). If the user selects Remember, Flash Player no longer displays the Privacy dialog box for SWF files from this domain.
Microphone.index Availability Flash Player 6. Usage active_mic.index:Number Description Read-only property; a zero-based integer that specifies the index of the microphone, as reflected in the array returned by Microphone.names. Example The following example displays the names of the sound capturing devices available on your computer system in a ComboBox instance called mic_cb. An instance of the Label component, called mic_lbl, displays the index microphone.
Microphone.muted Availability Flash Player 6. Usage active_mic.muted:Boolean Description Read-only property; a Boolean value that specifies whether the user has denied access to the microphone (true) or allowed access (false). When this value changes, Microphone.onStatus is invoked. For more information, see Microphone.get(). Example This example gets the default microphone and checks whether it is muted. var active_mic:Microphone = Microphone.get(); trace(active_mic.muted); See also Microphone.
Microphone.name Availability Flash Player 6. Usage active_mic.name:String Description Read-only property; a string that specifies the name of the current sound capture device, as returned by the sound capture hardware. Example The following example displays information about the sound capturing device(s) on your computer system, including an array of names and the default device. var status_ta:mx.controls.TextArea; status_ta.html = false; status_ta.
Microphone.names Availability Flash Player 6. Usage Microphone.names:Array Note: The correct syntax is Microphone.names. To assign the return value to a variable, use syntax like mic_array = Microphone.names. To determine the name of the current microphone, use active_mic.name. Description Read-only class property; retrieves an array of strings reflecting the names of all available sound capture devices without displaying the Flash Player Privacy Settings panel.
Microphone.onActivity Availability Flash Player 6. Usage active_mic.onActivity = function(activity:Boolean) : Void { // your statements here } Parameters A Boolean value set to true when the microphone starts detecting sound, and false when it stops. activity Returns Nothing. Description Event handler; invoked when the microphone starts or stops detecting sound. If you want to respond to this event handler, you must create a function to process its activity value.
Microphone.onStatus Availability Flash Player 6. Usage active_mic.onStatus = function(infoObject:Object) : Void { // your statements here } Parameters infoObject A parameter defined according to the status message. Returns Nothing. Description Event handler; invoked when the user allows or denies access to the microphone. If you want to respond to this event handler, you must create a function to process the information object generated by the microphone.
var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); active_mic.onStatus = function(infoObj:Object) { status_txt._visible = active_mic.muted; muted_txt.htmlText = "Status: "+infoObj.code+""; }; this.createTextField("status_txt", this.getNextHighestDepth(), 0, 0, 100, 22); status_txt.html = true; status_txt.autoSize = true; status_txt.htmlText = "muted"; status_txt._x = (Stage.
Microphone.rate Availability Flash Player 6. Usage active_mic.rate:Number Description Read-only property; the rate at which the microphone is capturing sound, in kHz. The default value is 8 kHz if your sound capture device supports this value. Otherwise, the default value is the next available capture level above 8 kHz that your sound capture device supports, usually 11 kHz. To set this value, use Microphone.setRate().
Microphone.setGain() Availability Flash Player 6. Usage active_mic.setGain(gain:Number) : Void Parameters An integer that specifies the amount by which the microphone should boost the signal. Valid values are 0 to 100. The default value is 50; however, the user may change this value in the Flash Player Microphone Settings panel. gain Returns Nothing. Description Method; sets the microphone gain—that is, the amount by which the microphone should multiply the signal before transmitting it.
Microphone.setRate() Availability Flash Player 6. Usage active_mic.setRate(kHz:Number) : Void Parameters The rate at which the microphone should capture sound, in kHz. Acceptable values are 5, 8, 11, 22, and 44. The default value is 8 kHz if your sound capture device supports this value. Otherwise, the default value is the next available capture level above 8 kHz that your sound capture device supports, usually 11 kHz. kHz Returns Nothing.
See also Microphone.rate Microphone.
Microphone.setSilenceLevel() Availability Flash Player 6. Usage active_mic.setSilenceLevel(level:Number [, timeout:Number]) : Void Parameters An integer that specifies the amount of sound required to activate the microphone and invoke Microphone.onActivity(true). Acceptable values range from 0 to 100. The default value is 10. level timeout An optional integer parameter that specifies how many milliseconds must elapse without activity before Flash considers sound to have stopped and invokes Microphone.
Example The following example changes the silence level based on the user’s input in a NumericStepper instance called silenceLevel_nstep. The ProgressBar instance called silenceLevel_pb modifies its appearance depending on whether the audio stream is considered silent. Otherwise, it displays the activity level of the audio stream. var silenceLevel_pb:mx.controls.ProgressBar; var silenceLevel_nstep:mx.controls.NumericStepper; this.createEmptyMovieClip("sound_mc", this.
Microphone.setUseEchoSuppression() Availability Flash Player 6. Usage active_mic.setUseEchoSuppression(suppress:Boolean) : Void Parameters suppress A Boolean value indicating whether echo suppression should be used (true) or not (false). Returns Nothing. Description Method; specifies whether to use the echo suppression feature of the audio codec. The default value is false unless the user has selected Reduce Echo in the Flash Player Microphone Settings panel.
active_mic.setUseEchoSuppression(evt.target.selected); }; useEchoSuppression_ch.addEventListener("click", chListener); See also Microphone.setGain(), Microphone.useEchoSuppression Microphone.
Microphone.silenceLevel Availability Flash Player 6. Usage active_mic.silenceLevel:Number Description Read-only property; an integer that specifies the amount of sound required to activate the microphone and invoke Microphone.onActivity(true). The default value is 10. Example The following example changes the silence level based on the user’s input in a NumericStepper instance called silenceLevel_nstep.
See also Microphone.gain, Microphone.setSilenceLevel() Microphone.
Microphone.silenceTimeOut Availability Flash Player 6. Usage active_mic.silenceTimeOut:Number Description Read-only property; a numeric value representing the number of milliseconds between the time the microphone stops detecting sound and the time Microphone.onActivity(false) is invoked. The default value is 2000 (2 seconds). To set this value, use Microphone.setSilenceLevel().
silenceLevel_pb.label = "Activity level: (inactive)"; } }; See also Microphone.setSilenceLevel() Microphone.
Microphone.useEchoSuppression Availability Flash Player 6. Usage active_mic.useEchoSuppression:Boolean Description Property (read-only); a Boolean value of true if echo suppression is enabled, false otherwise. The default value is false unless the user has selected Reduce Echo in the Flash Player Microphone Settings panel. Example The following example turns on echo suppression if the user selects a CheckBox instance called useEchoSuppression_ch.
MMExecute() CHAPTER 2 ActionScript Language Reference Availability Flash Player 7. Usage MMExecute("Flash JavaScript API command;":String) Parameters Flash JavaScript API command Any command that you can use in a Flash JavaScript (JSFL) file. Returns A string representation of the result, if any, sent by the JavaScript statement. Description Function; lets you issue Flash JavaScript API (JSAPI) commands from ActionScript.
Now you can select your file from the bottom of the Window > Other Panels menu. The ActionScript trace function does not work from a Flash panel; this example uses the JavaScript fl.trace version to get the output. It might be easier to copy the results of MMExecute to a text field that is part of your Flash Panel file.
Mouse class CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Description The Mouse class is a top-level class whose properties and methods you can access without using a constructor. You can use the methods of the Mouse class to hide and show the mouse pointer (cursor) in the SWF file. The mouse pointer is visible by default, but you can hide it and implement a custom pointer that you create using a movie clip (see “Creating a custom mouse pointer” in Using Flash).
Mouse.addListener() Availability Flash Player 6. Usage Mouse.addListener (newListener:Object) Parameters newListener An object. Returns Nothing. Description Method; registers an object to receive notifications of the onMouseDown, onMouseMove, onMouseUp, and onMouseWheel listeners. (The onMouseWheel listener is supported only in Windows.) The newListener parameter should contain an object that has a defined method for at least one of the listeners.
To view the entire script, see the animation.fla file in the HelpExamples Folder. The following list shows typical paths to the HelpExamples Folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ Mouse.
Mouse.hide() Availability Flash Player 5. Usage Mouse.hide() : Boolean Parameters None. Returns A Boolean value: true if the pointer is visible; false otherwise. Description Method; hides the pointer in a SWF file. The pointer is visible by default. Example: The following code hides the standard mouse pointer, and sets the x and y positions of the cursor_mc movie clip instance to the x and y cursor position. Create a movie clip and set its Linkage identifier to cursor_id.
Mouse.onMouseDown Availability Flash Player 6. Usage someListener.onMouseDown Parameters None. Description Listener; notified when the mouse is pressed. To use the onMouseDown listener, you must create a listener object. You can then define a function for onMouseDown and use addListener() to register the listener with the Mouse object, as shown in the following code: var someListener:Object = new Object(); someListener.onMouseDown = function () { ... }; Mouse.
See also Mouse.
Mouse.onMouseMove Availability Flash Player 6. Usage someListener.onMouseMove Parameters None. Returns Nothing. Description Listener; notified when the mouse moves. To use the onMouseMove listener, you must create a listener object. You can then define a function for onMouseMove and use addListener() to register the listener with the Mouse object, as shown in the following code: var someListener:Object = new Object(); someListener.onMouseMove = function () { ... }; Mouse.
The following example hides the standard mouse pointer, and sets the x and y positions of the pointer_mc movie clip instance to the x and y pointer position. Create a movie clip and set its Linkage identifier to pointer_id. Add the following ActionScript to Frame 1 of the Timeline: // to use this script you need a symbol // in your library with a Linkage Identifier of "pointer_id". this.attachMovie("pointer_id", "pointer_mc", this.getNextHighestDepth()); Mouse.
Mouse.onMouseUp Availability Flash Player 6. Usage someListener.onMouseUp Parameters None. Returns Nothing. Description Listener; notified when the mouse is released. To use the onMouseUp listener, you must create a listener object. You can then define a function for onMouseUp and use addListener() to register the listener with the Mouse object, as shown in the following code: var someListener:Object = new Object(); someListener.onMouseUp = function () { ... }; Mouse.
Mouse.onMouseWheel Availability Flash Player 6 (Windows only). Usage someListener.onMouseWheel = function ( [ delta [, scrollTarget ] ] ) { // your statements here } Parameters An optional number indicating how many lines should be scrolled for each notch the user rolls the mouse wheel. A positive delta value indicates an upward scroll; a negative value indicates a downward scroll. Typical values are from 1 to 3; faster scrolling can produce larger values.
mouseListener.onMouseWheel = function(delta:Number) { line_mc._rotation += delta; }; mouseListener.onMouseDown = function() { trace("Down"); }; Mouse.addListener(mouseListener); See also Mouse.addListener(), TextField.mouseWheelEnabled Mouse.
Mouse.removeListener() Availability Flash Player 6. Usage Mouse.removeListener (listener:Object) : Boolean Parameters listener An object. Returns If the listener object is successfully removed, the method returns true; if the listener is not successfully removed (for example, if the listener was not on the Mouse object’s listener list), the method returns false. Description Method; removes an object that was previously registered with addListener().
mouseListener.onMouseUp = function() { this.isDrawing = false; }; Mouse.addListener(mouseListener); var clearListener:Object = new Object(); clearListener.click = function() { canvas_mc.clear(); }; clear_button.addEventListener("click", clearListener); // var stopDrawingListener:Object = new Object(); stopDrawingListener.click = function(evt:Object) { Mouse.removeListener(mouseListener); evt.target.enabled = false; startDrawing_button.enabled = true; }; stopDrawing_button.
Mouse.show() Availability Flash Player 5. Usage Mouse.show() : Number Parameters None. Returns An integer; either 0 or 1. If the mouse pointer was hidden before the call to Mouse.show(), then the return value is 0. If the mouse pointer was visible before the call to Mouse.show(), then the return value is 1. Description Method; displays the mouse pointer in a SWF file. The pointer is visible by default.
MovieClip class CHAPTER 2 ActionScript Language Reference Availability Flash Player 3. Description The methods for the MovieClip class provide the same functionality as actions that target movie clips. There are also additional methods that do not have equivalent actions in the Actions toolbox in the Actions panel. You do not need to use a constructor method to call the methods of the MovieClip class; instead, you reference movie clip instances by name, using the following syntax: my_mc.play(); my_mc.
Method Description MovieClip.globalToLocal() Converts Stage coordinates to the local coordinates of the specified movie clip. MovieClip.gotoAndPlay() Sends the playhead to a specific frame in the movie clip and plays the movie clip. MovieClip.gotoAndStop() Sends the playhead to a specific frame in the movie clip and stops the movie clip. MovieClip.hitTest() Returns true if bounding box of the specified movie clip intersects the bounding box of the target movie clip. MovieClip.
Method Description MovieClip.lineStyle() Defines the stroke of lines created with the MovieClip.lineTo() and MovieClip.curveTo() methods. MovieClip.lineTo() Draws a line using the current line style. MovieClip.moveTo() Moves the current drawing position to specified coordinates. Property summary for the MovieClip class Property Description MovieClip._alpha The transparency value of a movie clip instance. MovieClip.
Property Description MovieClip._target Read-only; the target path of a movie clip instance. MovieClip._totalframes Read-only; the total number of frames in a movie clip instance. MovieClip.trackAsMenu A Boolean value that indicates whether other movie clips can receive mouse release events. MovieClip._url Read-only; the URL of the SWF file from which a movie clip was downloaded. MovieClip.
Event handler Description MovieClip.onLoad Invoked when the movie clip is instantiated and appears in the Timeline. MovieClip.onMouseDown Invoked when the left mouse button is pressed. MovieClip.onMouseMove Invoked every time the mouse is moved. MovieClip.onMouseUp Invoked when the left mouse button is released. MovieClip.onPress Invoked when the mouse is pressed while the pointer is over a movie clip. MovieClip.
MovieClip._alpha Availability Flash Player 4. Usage my_mc._alpha:Number Description Property; the alpha transparency value of the movie clip specified by my_mc. Valid values are 0 (fully transparent) to 100 (fully opaque). The default value is 100. Objects in a movie clip with _alpha set to 0 are active, even though they are invisible. For example, you can still click a button in a movie clip whose _alpha property is set to 0.
MovieClip.attachAudio() Availability Flash Player 6; the ability to attach audio from Flash Video (FLV) files was added in Flash Player 7. Usage my_mc.attachAudio(source:Object) : Void Parameters The object containing the audio to play. Valid values are a Microphone object, a NetStream object that is playing an FLV file, and false (stops playing the audio). source Returns Nothing. Description Method; specifies the audio source to be played. To stop playing the audio source, pass false for source.
// updates the volume this.createTextField("volume_txt", this.getNextHighestDepth(), 0, 0, 100, 22); updateVolume(); function updateVolume() { volume_txt.text = "Volume: "+audio_sound.getVolume(); } The following example specifies a microphone as the audio source for a dynamically created movie clip instance called audio_mc: var active_mic:Microphone = Microphone.get(); this.createEmptyMovieClip("audio_mc", this.getNextHighestDepth()); audio_mc.
MovieClip.attachMovie() Availability Flash Player 5. Usage my_mc.attachMovie(idName:String, newName:String, depth:Number [, initObject:Object]) : MovieClip Parameters The linkage name of the movie clip symbol in the library to attach to a movie clip on the Stage. This is the name entered in the Identifier field in the Linkage Properties dialog box. idName A unique instance name for the movie clip being attached to the movie clip.
MovieClip.beginFill() Availability Flash Player 6. Usage my_mc.beginFill([rgb:Number[, alpha:Number]]) : Void Parameter A hex color value (for example, red is 0xFF0000, blue is 0x0000FF, and so on). If this value is not provided or is undefined, a fill is not created. rgb An integer between 0–100 that specifies the alpha value of the fill. If this value is not provided, 100 (solid) is used. If the value is less than 0, Flash uses 0. If the value is greater than 100, Flash uses 100.
MovieClip.beginGradientFill() Availability Flash Player 6. Usage my_mc.beginGradientFill(fillType:String, colors:Array, alphas:Array, ratios:Array, matrix:Object) : Void Parameter fillType Either the string "linear" or the string "radial". colors An array of RGB hex color values to be used in the gradient (for example, red is 0xFF0000, blue is 0x0000FF, and so on). alphas An array of alpha values for the corresponding colors in the colors array; valid values are 0–100.
If a matrixType property does not exist then the remaining parameters are all required; the function fails if any of them are missing. This matrix scales, translates, rotates, and skews the unit gradient, which is defined at (-1,-1) and (1,1). • matrixType, x, y, w, h, r.
Returns Nothing. Description Method; indicates the beginning of a new drawing path. If the first parameter is undefined, or if no parameters are passed, the path has no fill. If an open path exists (that is if the current drawing position does not equal the previous position specified in a MovieClip.moveTo() method), and it has a fill associated with it, that path is closed with a line and then filled. This is similar to what happens when you call MovieClip.endFill().
endFill(); } See also MovieClip.beginFill(), MovieClip.endFill(), MovieClip.lineStyle(), MovieClip.lineTo(), MovieClip.
MovieClip.clear() Availability Flash Player 6. Usage my_mc.clear() : Void Parameters None. Returns Nothing. Description Method; removes all the graphics created during runtime using the movie clip draw methods, including line styles specified with MovieClip.lineStyle(). Shapes and lines that are manually drawn during authoring time (with the Flash drawing tools) are unaffected. Example The following example draws a box on the Stage.
MovieClip.createEmptyMovieClip() Availability Flash Player 6. Usage my_mc.createEmptyMovieClip(instanceName:String, depth:Number) : MovieClip Parameters instanceName depth A string that identifies the instance name of the new movie clip. An integer that specifies the depth of the new movie clip. Returns A reference to the newly created movie clip. Description Method; creates an empty movie clip as a child of an existing movie clip.
MovieClip.createTextField() Availability Flash Player 6. Usage my_mc.createTextField(instanceName:String, depth:Number, x:Number, y:Number, width:Number, height:Number) : Void Parameters instanceName depth A string that identifies the instance name of the new text field. A positive integer that specifies the depth of the new text field. x An integer that specifies the x coordinate of the new text field. y An integer that specifies the y coordinate of the new text field.
variable = maxChars = styleSheet tabInded = null null = undefined undefined A text field created with createTextField() receives the following default TextFormat object: font = "Times New Roman" size = 12 color = 0x000000 bold = false italic = false underline = false url = "" target = "" align = "left" leftMargin = 0 rightMargin = 0 indent = 0 leading = 0 blockIndent = 0 bullet = false display = block tabStops = [] (empty array) You can extend the methods and event handlers of the MovieClip class by crea
MovieClip._currentframe Availability Flash Player 4. Usage my_mc._currentframe:Number Description Read-only property; returns the number of the frame in which the playhead is located in the Timeline specified by my_mc. Example The following example uses the _currentframe property to direct the playhead of the movie clip actionClip_mc to advance five frames ahead of its current location: actionClip_mc.gotoAndStop(actionClip_mc._currentframe + 5); MovieClip.
MovieClip.curveTo() Availability Flash Player 6. Usage my_mc.curveTo(controlX:Number, controlY:Number, anchorX:Number, anchorY:Number) : Void Parameters An integer that specifies the horizontal position of the control point relative to the registration point of the parent movie clip. controlX An integer that specifies the vertical position of the control point relative to the registration point of the parent movie clip.
The curve drawn in this example is a quadratic bezier curve. Quadratic bezier curves consist of two anchor points and a control point. The curve interpolates the two anchor points, and curves toward the control point. The following ActionScript creates a circle using MovieClip.curveTo() and the Math class: this.createEmptyMovieClip("circle2_mc", 2); circle2_mc.lineStyle(0, 0x000000); drawCircle(circle2_mc, 10, 10, 100); function drawCircle(mc:MovieClip, x:Number, y:Number, r:Number):Void { mc.
MovieClip._droptarget Availability Flash Player 4. Usage my_mc._droptarget:String Description Read-only property; returns the absolute path in slash syntax notation of the movie clip instance on which my_mc was dropped. The _droptarget property always returns a path that starts with a slash (/). To compare the _droptarget property of an instance to a reference, use the eval() function to convert the returned value from slash syntax to a dot syntax reference.
MovieClip.duplicateMovieClip() Availability Flash Player 5. Usage my_mc.duplicateMovieClip(newname:String, depth:Number [,initObject:Object]) : MovieClip Parameters A unique identifier for the duplicate movie clip. newname depth A unique number specifying the depth at which the SWF file specified is to be placed. (Supported for Flash Player 6 and later.) An object containing properties with which to populate the duplicated movie clip.
MovieClip.enabled Availability Flash Player 6. Usage my_mc.enabled:Boolean Description Property; a Boolean value that indicates whether a movie clip is enabled. The default value of enabled is true. If enabled is set to false, the movie clip’s callback methods and on action event handlers are no longer invoked, and the Over, Down, and Up frames are disabled. The enabled property does not affect the Timeline of the movie clip; if a movie clip is playing, it continues to play.
MovieClip.endFill() Availability Flash Player 6. Usage my_mc.endFill() : Void Parameters None. Returns Nothing. Description Method; applies a fill to the lines and curves added since the last call to beginFill() or beginGradientFill(). Flash uses the fill that was specified in the previous call to beginFill() or beginGradientFill(). If the current drawing position does not equal the previous position specified in a moveTo() method and a fill is defined, the path is closed with a line and then filled.
MovieClip.focusEnabled Availability Flash Player 6. Usage my_mc.focusEnabled:Boolean Description Property; if the value is undefined or false, a movie clip cannot receive input focus unless it is a button. If the focusEnabled property value is true, a movie clip can receive input focus even if it is not a button. Example The following example sets the focusEnabled property for the movie clip my_mc to false: my_mc.
MovieClip._focusrect Availability Flash Player 6. Usage my_mc._focusrect:Boolean Description Property; a Boolean value that specifies whether a movie clip has a yellow rectangle around it when it has keyboard focus. This property can override the global _focusrect property. The default value of the _focusrect property of a movie clip instance is null; meaning, the movie clip instance does not override the global _focusrect property.
MovieClip._framesloaded Availability Flash Player 4. Usage my_mc._framesloaded:Number Description Read-only property; the number of frames that have been loaded from a streaming SWF file. This property is useful for determining whether the contents of a specific frame, and all the frames before it, have loaded and are available locally in the browser. It is also useful for monitoring the downloading of large SWF files.
MovieClip.getBounds() Availability Flash Player 5. Usage my_mc.getBounds(targetCoordinateSpace:Object) : Object Parameters targetCoordinateSpace The target path of the Timeline whose coordinate system you want to use as a reference point. Returns An object with the properties xMin, xMax, yMin, and yMax. Description Method; returns properties that are the minimum and maximum x and y coordinate values of the instance specified by my_mc for the targetCoordinateSpace parameter. Note: Use MovieClip.
See also MovieClip.globalToLocal(), MovieClip.
MovieClip.getBytesLoaded() Availability Flash Player 5. Usage my_mc.getBytesLoaded() : Number Parameters None. Returns An integer indicating the number of bytes loaded. Description Method; returns the number of bytes that have already loaded (streamed) for the movie clip specified by my_mc. You can compare this value with the value returned by MovieClip.getBytesTotal() to determine what percentage of a movie clip has loaded.
MovieClip.getBytesTotal() Availability Flash Player 5. Usage my_mc.getBytesTotal() : Number Parameters None. Returns An integer indicating the total size, in bytes, of my_mc. Description Method; returns the size, in bytes, of the movie clip specified by my_mc. For movie clips that are external (the root SWF file or a movie clip that is being loaded into a target or a level), the return value is the size of the SWF file.
MovieClip.getDepth() Availability Flash Player 6. Usage my_mc.getDepth() : Number Parameters None. Returns An integer. Description Method; returns the depth of a movie clip instance. For more information, see “Managing movie clip depths” in Using ActionScript in Flash. You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see “Assigning a class to a movie clip symbol” in Using ActionScript in Flash.
MovieClip.getInstanceAtDepth() Availability Flash Player 7. Usage my_mc.getInstanceAtDepth(depth:Number) : MovieClip Parameters depth An integer that specifies the depth level to query. Returns A reference to the MovieClip instance located at the specified depth, or undefined if there is no movie clip at that depth. Description Method; lets you determine if a particular depth is already occupied by a movie clip. You can use this method before using MovieClip.attachMovie(), MovieClip.
MovieClip.getNextHighestDepth() Availability Flash Player 7. Usage my_mc.getNextHighestDepth() : Number Parameters None. Returns An integer that reflects the next available depth index that would render above all other objects on the same level and layer within my_mc. Description Method; lets you determine a depth value that you can pass to MovieClip.attachMovie(), MovieClip.duplicateMovieClip(), or MovieClip.
MovieClip.getSWFVersion() Availability Flash Player 7. Usage my_mc.getSWFVersion() : Number Parameters None. Returns An integer that specifies the Flash Player version that was targeted when the SWF file loaded into my_mc was published. Description Method; returns an integer that indicates the Flash Player version for which my_mc was published. If my_mc is a JPEG file, or if an error occurs and Flash can’t determine the SWF version of my_mc, -1 is returned.
MovieClip.getTextSnapshot() Availability Authoring: Flash MX 2004. Playback: SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later. Usage my_mc.getTextSnapshot() : TextSnapshot Parameters None. Returns A TextSnapshot object that contains the static text from my_mc. Description Method; returns a TextSnapshot object that contains the text in all the static text fields in the specified movie clip; text in child movie clips is not included.
for (var i in textSnap) { text_mc.textSnapshot_txt.htmlText += ""+i+"\t"+textSnap[i]; } text_mc.textSnapshot_txt.htmlText += ""; The following text appears in text_mc.
MovieClip.getURL() Availability Flash Player 5. Usage my_mc.getURL(URL:String [,window:String, variables:String]) : Void Parameters URL String; the URL from which to obtain the document. String; an optional parameter specifying the name, frame, or expression that specifies the window or HTML frame that the document is loaded into.
MovieClip.globalToLocal() Availability Flash Player 5. Usage my_mc.globalToLocal(point:Object) : Void Parameters The name or identifier of an object created with the generic Object class. The object specifies the x and y coordinates as properties. point Returns Nothing. Description Method; converts the point object from Stage (global) coordinates to the movie clip’s (local) coordinates. You can extend the methods and event handlers of the MovieClip class by creating a subclass.
See also MovieClip.getBounds(), MovieClip.localToGlobal() MovieClip.
MovieClip.gotoAndPlay() Availability Flash Player 5. Usage my_mc.gotoAndPlay(frame:Object) : Void Parameters A number representing the frame number, or a string representing the label of the frame, to which the playhead is sent. frame Returns Nothing. Description Method; starts playing the SWF file at the specified frame. If you want to specify a scene as well as a frame, use gotoAndPlay(). You can extend the methods and event handlers of the MovieClip class by creating a subclass.
MovieClip.gotoAndStop() Availability Flash Player 5. Usage my_mc.gotoAndStop(frame:Object) : Void Parameters frame The frame number to which the playhead is sent. Returns Nothing. Description Method; brings the playhead to the specified frame of the movie clip and stops it there. If you want to specify a scene in addition to a frame, use gotoAndStop(). You can extend the methods and event handlers of the MovieClip class by creating a subclass.
MovieClip._height Availability Flash Player 4. Usage my_mc._height:Number Description Property; the height of the movie clip, in pixels. Example The following code example displays the height and width of a movie clip in the Output panel: this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var image_mcl:MovieClipLoader = new MovieClipLoader(); var mclListener:Object = new Object(); mclListener.onLoadInit = function(target_mc:MovieClip) { trace(target_mc._name+" = "+target_mc.
MovieClip.hitArea Availability Flash Player 6. Usage my_mc.hitArea:Object Returns A reference to a movie clip. Description Property; designates another movie clip to serve as the hit area for a movie clip. If the hitArea property does not exist or is null or undefined, the movie clip itself is used as the hit area. The value of the hitArea property may be a reference to a movie clip object.
MovieClip.hitTest() Availability Flash Player 5. Usage my_mc.hitTest(x:Number, y:Number, shapeFlag:Boolean) : Boolean my_mc.hitTest(target:Object) : Boolean Parameters x The x coordinate of the hit area on the Stage. y The y coordinate of the hit area on the Stage. The x and y coordinates are defined in the global coordinate space. target The target path of the hit area that may intersect or overlap with the instance specified by my_mc.
See also MovieClip.getBounds(), MovieClip.globalToLocal(), MovieClip.localToGlobal() MovieClip.
MovieClip.lineStyle() Availability Flash Player 6. Usage my_mc.lineStyle([thickness:Number[, rgb:Number[, alpha:Number]]]) : Void Parameters An integer that indicates the thickness of the line in points; valid values are 0 to 255. If a number is not specified, or if the parameter is undefined, a line is not drawn. If a value of less than 0 is passed, Flash uses 0. The value 0 indicates hairline thickness; the maximum thickness is 255. If a value greater than 255 is passed, the Flash interpreter uses 255.
MovieClip.lineTo() Availability Flash Player 6. Usage my_mc.lineTo(x:Number, y:Number) : Void Parameters An integer indicating the horizontal position relative to the registration point of the parent movie clip. x An integer indicating the vertical position relative to the registration point of the parent movie clip. y Returns Nothing. Description Method; draws a line using the current line style from the current drawing position to (x, y); the current drawing position is then set to (x, y).
MovieClip.loadMovie() Availability Flash Player 5. Usage my_mc.loadMovie(url:String [,variables:String]) : Void Parameters The absolute or relative URL of the SWF file or JPEG file to be loaded. A relative path must be relative to the SWF file at level 0. Absolute URLs must include the protocol reference, such as http:// or file:///. url An optional parameter specifying an HTTP method for sending or loading variables. The parameter must be the string GET or POST.
Using event handlers with MovieClip.loadMovie() can be unpredictable. If you attach an event handler to a button using on() or if you create a dynamic handler using an event handler method such as MovieClip.onPress, and then you call loadMovie(), the event handler does not remain after the new content is loaded. However, if you attach an event handler to a movie clip using onClipEvent() or on(), and then call loadMovie() on that movie clip, the event handler remains after the new content is loaded.
MovieClip.loadVariables() Availability Flash Player 5; behavior changed in Flash Player 7. Usage my_mc.loadVariables(url:String [, variables:String]) : Void Parameters The absolute or relative URL for the external file that contains the variables to be loaded. If the SWF file issuing this call is running in a web browser, url must be in the same domain as the SWF file; for details, see “Description,” below. url variables An optional parameter specifying an HTTP method for sending variables.
You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see “Assigning a class to a movie clip symbol” in Using ActionScript in Flash. Example The following example loads information from a text file called params.txt into the target_mc movie clip that is created using createEmptyMovieClip(). The setInterval() function is used to check the loading progress. The script checks for a variable in the params.txt file named done. this.
MovieClip.localToGlobal() Availability Flash Player 5. Usage my_mc.localToGlobal(point:Object) : Void Parameters The name or identifier of an object created with the Object class, specifying the x and y coordinates as properties. point Returns Nothing. Description Method; converts the point object from the movie clip’s (local) coordinates to the Stage (global) coordinates. You can extend the methods and event handlers of the MovieClip class by creating a subclass.
MovieClip._lockroot Availability Flash Player 7. Usage my_mc._lockroot:Boolean Description Property; specifies what _root refers to when a SWF file is loaded into a movie clip. The _lockroot property is undefined by default. You can set this property within the SWF file that is being loaded or in the handler that is loading the movie clip. For example, suppose you have a document called Games.fla that lets a user choose a game to play, and loads the game (for example, Chess.
_lockroot -> true $version -> WIN 7,0,19,0 The following example loads two SWF files, lockroot.swf and nolockroot.swf. The lockroot.fla document contains the previous ActionScript. The nolockroot FLA file has the following code placed on Frame 1 of the Timeline: _root.myVar = 1; _root.myOtherVar = 2; trace("from nolockroot.swf"); for (i in _root) { trace(" "+i+" -> "+_root[i]); } trace(""); The lockroot.swf file has _lockroot applied to it, and nolockroot.swf does not.
nolockroot_mc._lockroot = true; nolockroot_mc.loadMovie("nolockroot.swf"); which would then trace the following: from current SWF file dumpRoot -> [type Function] $version -> WIN 7,0,19,0 nolockroot_mc -> _level0.nolockroot_mc lockroot_mc -> _level0.lockroot_mc from nolockroot.swf myOtherVar -> 2 myVar -> 1 from lockroot.swf myOtherVar -> 2 myVar -> 1 See also MovieClip.attachMovie(), MovieClip.loadMovie(), MovieClipLoader.onLoadInit, _root, and “About loading components” in Using Components. MovieClip.
MovieClip.menu Availability Flash Player 7. Usage my_mc.menu:ContextMenu = contextMenu Parameters contextMenu A ContextMenu object. Description Property; associates the specified ContextMenu object with the movie clip my_mc. The ContextMenu class lets you modify the context menu that appears when the user right-clicks (Windows) or Control-clicks (Macintosh) in Flash Player. Example The following example assigns the ContextMenu object menu_cm to the movie clip image_mc.
MovieClip.moveTo() Availability Flash Player 6. Usage my_mc.moveTo(x:Number, y:Number) : Void Parameters An integer indicating the horizontal position relative to the registration point of the parent movie clip. x An integer indicating the vertical position relative to the registration point of the parent movie clip. y Returns Nothing. Description Method; moves the current drawing position to (x, y).
MovieClip._name Availability Flash Player 4. Usage my_mc._name:String Description Property; the instance name of the movie clip specified by my_mc. Example The following example lets you right-click or Control-click a movie clip on the Stage and select “Info...” from the context menu to view information about that instance. Add several movie clips with instance names, and then add the following ActionScript to your AS or FLA file: var menu_cm:ContextMenu = new ContextMenu(); menu_cm.customItems.
MovieClip.nextFrame() Availability Flash Player 5. Usage my_mc.nextFrame() : Void Parameters None. Returns Nothing. Description Method; sends the playhead to the next frame and stops it. You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see “Assigning a class to a movie clip symbol” in Using ActionScript in Flash. Example The following example loads content into a SWF file using _framesloaded and nextFrame().
MovieClip.onData Availability Flash Player 6. Usage my_mc.onData = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when a movie clip receives data from a MovieClip.loadVariables() or MovieClip.loadMovie() call. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library.
// Therefore, this function is invoked when symbol_mc is instantiated // and also when replacement.swf is loaded. OnClipEvent( data ) { trace("The movie clip has received data"); } See also onClipEvent() MovieClip.
MovieClip.onDragOut Availability Flash Player 6. Usage my_mc.onDragOut = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the mouse button is pressed and the pointer rolls outside the object. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library.
MovieClip.onDragOver Availability Flash Player 6. Usage my_mc.onDragOver = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the pointer is dragged outside and then over the movie clip. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library.
MovieClip.onEnterFrame Availability Flash Player 6. Usage my_mc.onEnterFrame = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked repeatedly at the frame rate of the SWF file. The actions associated with the enterFrame event are processed before any frame actions that are attached to the affected frames. You must define a function that executes when the event handler is invoked.
MovieClip.onKeyDown Availability Flash Player 6. Usage my_mc.onKeyDown = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when a movie clip has input focus and a key is pressed. The onKeyDown event handler is invoked with no parameters. You can use the Key.getAscii() and Key.getCode() methods to determine which key was pressed. You must define a function that executes when the event handler is invoked.
When you tab to the movie clip and press a key, key was pressed displays in the Output panel. However, this does not occur after you move the mouse, because the movie clip loses focus. Therefore, you should use Key.onKeyDown in most cases. See also MovieClip.
MovieClip.onKeyUp Availability Flash Player 6. Usage my_mc.onKeyUp = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when a key is released. The onKeyUp event handler is invoked with no parameters. You can use the Key.getAscii() and Key.getCode() methods to determine which key was pressed. You must define a function that executes when the event handler is invoked.
MovieClip.onKillFocus Availability Flash Player 6. Usage my_mc.onKillFocus = function (newFocus:Object) { // your statements here } Parameters newFocus The object that is receiving the keyboard focus. Returns Nothing. Description Event handler; invoked when a movie clip loses keyboard focus. The onKillFocus method receives one parameter, newFocus, which is an object that represents the new object receiving the focus. If no object receives the focus, newFocus contains the value null.
MovieClip.onLoad Availability Flash Player 6. Usage my_mc.onLoad = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the movie clip is instantiated and appears in the Timeline. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library.
The following example displays the equivalent of the previous ActionScript example: this.createEmptyMovieClip("tester_mc", 1); var mclListener:Object = new Object(); mclListener.onLoadInit = function(target_mc:MovieClip) { trace("movie loaded"); }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.yourserver.com/your_movie.
MovieClip.onMouseDown Availability Flash Player 6. Usage my_mc.onMouseDown = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the mouse button is pressed. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library.
MovieClip.onMouseMove Availability Flash Player 6. Usage my_mc.onMouseMove = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the mouse moves. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library.
MovieClip.onMouseUp Availability Flash Player 6. Usage my_mc.onMouseUp = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the mouse button is released. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library.
MovieClip.onPress Availability Flash Player 6. Usage my_mc.onPress = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the user clicks the mouse while the pointer is over a movie clip. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library.
MovieClip.onRelease Availability Flash Player 6. Usage my_mc.onRelease = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked the mouse button is released over a movie clip. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library.
MovieClip.onReleaseOutside Availability Flash Player 6. Usage my_mc.onReleaseOutside = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked after the mouse button has been pressed inside the movie clip area and then released outside the movie clip area. You must define a function that executes when the event handler is invoked.
MovieClip.onRollOut Availability Flash Player 6. Usage my_mc.onRollOut = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the pointer moves outside a movie clip area. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library.
MovieClip.onRollOver Availability Flash Player 6. Usage my_mc.onRollOver = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked when the pointer moves over a movie clip area. You must define a function that executes when the event handler is invoked. You can define the function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol in the library.
MovieClip.onSetFocus Availability Flash Player 6. Usage my_mc.onSetFocus = function(oldFocus){ // your statements here } Parameters oldFocus The object to lose focus. Returns Nothing. Description Event handler; invoked when a movie clip receives keyboard focus. The oldFocus parameter is the object that loses the focus. For example, if the user presses the Tab key to move the input focus from a movie clip to a text field, oldFocus contains the movie clip instance.
MovieClip.onUnload Availability Flash Player 6. Usage my_mc.onUnload = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked in the first frame after the movie clip is removed from the Timeline. Flash processes the actions associated with the onUnload event handler before attaching any actions to the affected frame. You must define a function that executes when the event handler is invoked.
MovieClip._parent Availability Flash Player 5. Usage my_mc._parent.property _parent.property Description Property; a reference to the movie clip or object that contains the current movie clip or object. The current object is the object containing the ActionScript code that references _parent. Use the _parent property to specify a relative path to movie clips or objects that are above the current movie clip or object.
MovieClip.play() Availability Flash Player 5. Usage my_mc.play() : Void Parameters None. Returns Nothing. Description Method; moves the playhead in the Timeline of the movie clip. You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see “Assigning a class to a movie clip symbol” in Using ActionScript in Flash. Example Use the following ActionScript to play the main Timeline of a SWF file.
MovieClip.prevFrame() Availability Flash Player 5. Usage my_mc.prevFrame() : Void Parameters None. Returns Nothing. Description Method; sends the playhead to the previous frame and stops it. You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see “Assigning a class to a movie clip symbol” in Using ActionScript in Flash. Example In the following example, two movie clip buttons control the Timeline.
MovieClip._quality Availability Flash Player 6. Usage my_mc._quality:String Description Property (global); sets or retrieves the rendering quality used for a SWF file. Device fonts are always aliased and therefore are unaffected by the _quality property. The _quality property can be set to the following values: • • "LOW" Low rendering quality. Graphics are not anti-aliased, and bitmaps are not smoothed. "MEDIUM" Medium rendering quality.
MovieClip.removeMovieClip() Availability Flash Player 5. Usage my_mc.removeMovieClip() : Void Parameters None. Returns Nothing. Description Method; removes a movie clip instance created with duplicateMovieClip(), MovieClip.duplicateMovieClip(), or MovieClip.attachMovie(). You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see “Assigning a class to a movie clip symbol” in Using ActionScript in Flash.
MovieClip._rotation Availability Flash Player 4. Usage my_mc._rotation:Number Description Property; the rotation of the movie clip, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement my_mc._rotation = 450 is the same as my_mc._rotation = 90.
MovieClip.setMask() Availability Flash Player 6. Usage my_mc.setMask(mask_mc:Object) : Void Parameters my_mc The instance name of a movie clip to be masked. mask_mc The instance name of a movie clip to be a mask. Returns Nothing. Description Method; makes the movie clip in the parameter mask_mc a mask that reveals the movie clip specified by the my_mc parameter. This method allows multiple-frame movie clips with complex, multilayered content to act as masks. You can shut masks on and off at runtime.
MovieClip._soundbuftime Availability Flash Player 6. Usage my_mc._soundbuftime:Number Description Property (global); an integer that specifies the number of seconds a sound prebuffers before it starts to stream. Note: Although you can specify this property for a MovieClip object, it is actually a global property, and you can specify its value simply as _soundbuftime. For more information and an example, see _soundbuftime.
MovieClip.startDrag() Availability Flash Player 5. Usage my_mc.startDrag([lock:Boolean, [left:Number, top:Number, right:Number, bottom:Number]]) : Void Parameters A Boolean value specifying whether the draggable movie clip is locked to the center of the mouse position (true), or locked to the point where the user first clicked on the movie clip (false). This parameter is optional.
MovieClip.stop() Availability Flash Player 5. Usage my_mc.stop() : Void Parameters None. Returns Nothing. Description Method; stops the movie clip currently playing. You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see “Assigning a class to a movie clip symbol” in Using ActionScript in Flash. Example The following example shows how to stop a movie clip named aMovieClip: aMovieClip.
MovieClip.stopDrag() Availability Flash Player 5. Usage my_mc.stopDrag() : Void Parameters None. Returns Nothing. Description Method; ends a MovieClip.startDrag() method. A movie clip that was made draggable with that method remains draggable until a stopDrag() method is added, or until another movie clip becomes draggable. Only one movie clip is draggable at a time. You can extend the methods and event handlers of the MovieClip class by creating a subclass.
MovieClip.swapDepths() Availability Flash Player 5. Usage my_mc.swapDepths(depth:Number) my_mc.swapDepths(target:String) Parameters depth A number specifying the depth level where my_mc is to be placed. A string specifying the movie clip instance whose depth is swapped by the instance specified by my_mc. Both instances must have the same parent movie clip. target Returns Nothing.
MovieClip.tabChildren Availability Flash Player 6. Usage my_mc.tabChildren:Boolean Description Property; undefined by default. If tabChildren is undefined or true, the children of a movie clip are included in automatic tab ordering. If the value of tabChildren is false, the children of a movie clip are not included in automatic tab ordering. Example A list box UI widget built as a movie clip contains several items. The user can click each item to select it, so each item is a button.
MovieClip.tabEnabled Availability Flash Player 6. Usage my_mc.tabEnabled:Boolean Description Property; specifies whether my_mc is included in automatic tab ordering. It is undefined by default. If tabEnabled is undefined, the object is included in automatic tab ordering only if it defines at least one movie clip handler, such as MovieClip.onRelease. If tabEnabled is true, the object is included in automatic tab ordering.
MovieClip.tabIndex Availability Flash Player 6. Usage my_mc.tabIndex:Number Description Property; lets you customize the tab ordering of objects in a movie. The tabIndex property is undefined by default. You can set tabIndex on a button, movie clip, or text field instance. If an object in a SWF file contains a tabIndex property, automatic tab ordering is disabled, and the tab ordering is calculated from the tabIndex properties of objects in the SWF file.
MovieClip._target Availability Flash Player 4. Usage my_mc._target:String Description Read-only property; returns the target path of the movie clip instance specified by my_mc in slash notation. Use the eval() function to convert the target path to dot notation. Example The following example displays the target paths of movie clip instances in a SWF file, in both slash and dot notation. for (var i in this) { if (typeof (this[i]) == "movieclip") { trace("name: "+this[i]._name+",\t target: "+this[i].
MovieClip._totalframes Availability Flash Player 4. Usage my_mc._totalframes:Number Description Read-only property; returns the total number of frames in the movie clip instance specified in the MovieClip parameter. Example In the following example, two movie clip buttons control the Timeline. The prev_mc button moves the playhead to the previous frame, and the next_mc button moves the playhead to the next frame.
MovieClip.trackAsMenu Availability Flash Player 6. Usage my_mc.trackAsMenu:Boolean Description Property; a Boolean value that indicates whether or not other buttons or movie clips can receive mouse release events. This allows you to create menus. You can set the trackAsMenu property on any button or movie clip object. If the trackAsMenu property does not exist, the default behavior is false. You can change the trackAsMenu property at any time; the modified movie clip immediately takes on the new behavior.
MovieClip.unloadMovie() Availability Flash Player 5. Usage my_mc.unloadMovie() : Void Parameters None. Returns Nothing. Description Method; removes the contents of a movie clip instance. The instance properties and clip handlers remain. To remove the instance, including its properties and clip handlers, use MovieClip.removeMovieClip(). You can extend the methods and event handlers of the MovieClip class by creating a subclass.
MovieClip._url Availability Flash Player 4. Usage my_mc._url:String Description Read-only property; retrieves the URL of the SWF or JPEG file from which the movie clip was downloaded. Example The following example displays the URL of the image that is loaded into the image_mc instance in the Output panel. this.createEmptyMovieClip("image_mc", 1); var mclListener:Object = new Object(); mclListener.onLoadInit = function(target_mc:MovieClip) { trace("_url: "+target_mc.
MovieClip.useHandCursor Availability Flash Player 6. Usage my_mc.useHandCursor:Boolean Description Property; a Boolean value that indicates whether the hand cursor (pointing hand) appears when the mouse rolls over a movie clip. The default value of useHandCursor is true. If useHandCursor is set to true, the pointing hand used for buttons is displayed when the mouse rolls over a button movie clip. If useHandCursor is false, the arrow pointer is used instead.
MovieClip._visible Availability Flash Player 4. Usage my_mc._visible:Boolean Description Property; a Boolean value that indicates whether the movie clip specified by my_mc is visible. Movie clips that are not visible (_visible property set to false) are disabled. For example, a button in a movie clip with _visible set to false cannot be clicked. Example The following example sets the _visible property for two movie clips called myMC1_mc and myMC2_mc.
MovieClip._width Availability Flash Player 4 as a read-only property. Usage my_mc._width:Number Description Property; the width of the movie clip, in pixels. Example The following code example displays the height and width of a movie clip in the Output panel: this.createEmptyMovieClip("image_mc", this.getNextHighestDepth()); var image_mcl:MovieClipLoader = new MovieClipLoader(); var mclListener:Object = new Object(); mclListener.onLoadInit = function(target_mc:MovieClip) { trace(target_mc.
MovieClip._x Availability Flash Player 3. Usage my_mc._x:Number Description Property; an integer that sets the x coordinate of a movie clip relative to the local coordinates of the parent movie clip. If a movie clip is in the main Timeline, then its coordinate system refers to the upper left corner of the Stage as (0, 0). If the move clip is inside another movie clip that has transformations, the movie clip is in the local coordinate system of the enclosing movie clip.
MovieClip._xmouse Availability Flash Player 5. Usage my_mc._xmouse:Number Description Read-only property; returns the x coordinate of the mouse position. Example The following example returns the current x and y coordinates of the mouse on the Stage (_level0) and in relation to a movie clip on the Stage called my_mc. this.createTextField("mouse_txt", this.getNextHighestDepth, 0, 0, 150, 66); mouse_txt.html = true; mouse_txt.
MovieClip._xscale Availability Flash Player 4. Usage my_mc._xscale:Number Description Property; determines the horizontal scale (percentage) of the movie clip as applied from the registration point of the movie clip. The default registration point is (0,0). Scaling the local coordinate system affects the _x and _y property settings, which are defined in whole pixels.
MovieClip._y Availability Flash Player 3. Usage my_mc._y:Number Description Property; sets the y coordinate of a movie clip relative to the local coordinates of the parent movie clip. If a movie clip is in the main Timeline, then its coordinate system refers to the upper left corner of the Stage as (0, 0). If the move clip is inside another movie clip that has transformations, the movie clip is in the local coordinate system of the enclosing movie clip.
MovieClip._ymouse Availability Flash Player 5. Usage my_mc._ymouse:Number Description Read-only property; indicates the y coordinate of the mouse position. Example The following example returns the current x and y coordinates of the mouse on the Stage (_level0) and in relation to a movie clip on the Stage called my_mc. this.createTextField("mouse_txt", this.getNextHighestDepth, 0, 0, 150, 66); mouse_txt.html = true; mouse_txt.
MovieClip._yscale Availability Flash Player 4. Usage my_mc._yscale:Number Description Property; sets the vertical scale (percentage) of the movie clip as applied from the registration point of the movie clip. The default registration point is (0,0). Scaling the local coordinate system affects the _x and _y property settings, which are defined in whole pixels.
MovieClipLoader class CHAPTER 2 ActionScript Language Reference Availability Flash Player 7. Description This class lets you implement listener callbacks that provide status information while SWF or JPEG files are being loaded (downloaded) into movie clips. To use MovieClipLoader features, use MovieClipLoader.loadClip() instead of loadMovie() or MovieClip.loadMovie() to load SWF files. After you issue the MovieClipLoader.
Listener summary for the MovieClipLoader class Listener Description MovieClipLoader.onLoadComplete Invoked when a file loaded with MovieClipLoader.loadClip() has completely downloaded. MovieClipLoader.onLoadError Invoked when a file loaded with MovieClipLoader.loadClip() has failed to load. MovieClipLoader.onLoadInit Invoked when the actions on the first frame of the loaded clip have been executed. MovieClipLoader.
MovieClipLoader.addListener() Availability Flash Player 7. Usage my_mcl.addListener(listenerObject:Object) : Void Parameters listenerObject An object that listens for a callback notification from the MovieClipLoader event handlers. Returns Nothing. Description Method; registers an object to receive notification when a MovieClipLoader event handler is invoked. Example The following example loads an image into a movie clip called image_mc.
MovieClipLoader.getProgress() Availability Flash Player 7. Usage my_mcl.getProgress(target_mc:Object) : Object Parameters target_mc A SWF or JPEG file that is loaded using MovieClipLoader.loadClip(). Returns An object that has two integer properties: bytesLoaded and bytesTotal. Description Method; returns the number of bytes loaded and total number of bytes for a file that is being loaded using MovieClipLoader.loadClip(); for compressed movies, it reflects the number of compressed bytes.
MovieClipLoader.loadClip() Availability Flash Player 7. Usage my_mcl.loadClip(url:String, target:Object ) : Boolean Parameters The absolute or relative URL of the SWF file or JPEG file to be loaded. A relative path must be relative to the SWF file at level 0. Absolute URLs must include the protocol reference, such as http:// or file:///. Filenames cannot include disk drive specifications.
MovieClipLoader.getProgress() and MovieClipLoaderListener.onLoadProgress do not report the actual bytesLoaded and bytesTotal values in the Authoring player when the files are local. When you use the Bandwidth Profiler feature in the authoring environment, MovieClipLoader.getProgress() and MovieClipLoaderListener.onLoadProgress report the download at the actual download rate, not at the reduced bandwidth rate that the Bandwidth Profiler provides.
my_mcl.loadClip("http://www.macromedia.com/software/drk/images/box_drk5.jpg", clip1_mc); my_mcl.loadClip("http://www.macromedia.com/devnet/images/160x160/ ben_forta.jpg", clip2_mc); clip2_mc._x = 200; // loads into _level1 my_mcl.loadClip("http://www.macromedia.com/devnet/images/160x160/ mike_chambers.jpg", 1); // // Second set of listeners var another_mcl:MovieClipLoader = new MovieClipLoader(); var myListener2:Object = new Object(); myListener2.
MovieClipLoader.onLoadComplete Availability Flash Player 7. Usage listenerObject.onLoadComplete = function([target_mc:Object]) { // your statements here } Parameters listenerObject target_mc A listener object that was added using MovieClipLoader.addListener(). A movie clip loaded by a MovieClipLoader.loadClip() method. This parameter is optional. Returns Nothing. Description Listener; invoked when a file loaded with MovieClipLoader.loadClip() has completely downloaded.
target_mc.createTextField("timer_txt", target_mc.getNextHighestDepth(), 0, target_mc._height, target_mc._width, 22); target_mc.timer_txt.text = "loaded in "+timerMS+" ms."; }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.macromedia.com/images/shared/product_boxes/ 112x112/box_studio_112x112.jpg", image_mc); See also MovieClipLoader.addListener(), MovieClipLoader.onLoadStart, MovieClipLoader.
MovieClipLoader.onLoadError Availability Flash Player 7. Usage listenerObject.onLoadError = function(target_mc:Object, errorCode:String) { // your statements here } Parameters listenerObject A listener object that was added using MovieClipLoader.addListener(). target_mc A movie clip loaded by a MovieClipLoader.loadClip() method. errorCode A string that explains the reason for the failure. Returns One of two strings: "URLNotFound" or "LoadNeverCompleted".
} }; mclListener.onLoadInit = function(target_mc:MovieClip) { trace("success"); trace(image_mcl.getProgress(target_mc).bytesTotal+" bytes loaded"); }; var image_mcl:MovieClipLoader = new MovieClipLoader(); image_mcl.addListener(mclListener); image_mcl.loadClip("http://www.fakedomain.com/images/bad_hair_day.
MovieClipLoader.onLoadInit Availability Flash Player 7. Usage listenerObject.onLoadInit = function([target_mc:MovieClip]) { // your statements here } Parameters listenerObject target_mc A listener object that was added using MovieClipLoader.addListener(). A movie clip loaded by a MovieClipLoader.loadClip() method. This parameter is optional. Returns Nothing. Description Listener; invoked when the actions on the first frame of the loaded clip have been executed.
See also MovieClipLoader.
MovieClipLoader.onLoadProgress Availability Flash Player 7. Usage listenerObject.onLoadProgress = function([target_mc:Object [, loadedBytes:Number [, totalBytes:Number ] ] ] ) { // your statements here } Parameters listenerObject target_mc A listener object that was added using MovieClipLoader.addListener(). A movie clip loaded by a MovieClipLoader.loadClip() method. This parameter is optional. loadedBytes totalBytes The number of bytes that had been loaded when the listener was invoked.
lineTo(100, 10); lineTo(0, 10); lineTo(0, 0); } with (progressBar_mc.bar_mc) { beginFill(0xFF0000, 100); moveTo(0, 0); lineTo(100, 0); lineTo(100, 10); lineTo(0, 10); lineTo(0, 0); endFill(); _xscale = 0; } progressBar_mc._x = 2; progressBar_mc._y = 2; // var mclListener:Object = new Object(); mclListener.onLoadStart = function(target_mc:MovieClip) { progressBar_mc.bar_mc._xscale = 0; }; mclListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number) { progressBar_mc.
MovieClipLoader.onLoadStart Availability Flash Player 7. Usage listenerObject.onLoadStart = function([target_mc:Object]) { // your statements here } Parameters listenerObject target_mc A listener object that was added using MovieClipLoader.addListener(). A movie clip loaded by a MovieClipLoader.loadClip() method. This parameter is optional. Returns Nothing. Description Listener; invoked when a call to MovieClipLoader.loadClip() has successfully begun to download a file.
See also MovieClipLoader.onLoadError, MovieClipLoader.onLoadInit, MovieClipLoader.
MovieClipLoader.removeListener() Availability Flash Player 7. Usage my_mcl.removeListener(listenerObject:Object) : Void Parameters listenerObject A listener object that was added using MovieClipLoader.addListener(). Returns Nothing. Description Method; removes the listener that was used to receive notification when a MovieClipLoader event handler was invoked. No further loading messages will be received.
start_button.enabled = true; stop_button.enabled = false; // image_mcl.removeListener(mclListener); }; stop_button.
MovieClipLoader.unloadClip() Availability Flash Player 7. Usage my_mcl.unloadClip(target:Object) Parameters target The string or integer passed to the corresponding call to my_mcl.loadClip(). Returns Nothing. Description Method; removes a movie clip that was loaded by means of MovieClipLoader.loadClip(). If you issue this command while a movie is loading, MovieClipLoader.onLoadError is invoked. Example The following example loads an image into a movie clip called image_mc.
CHAPTER 2 ActionScript Language Reference NaN Availability Flash Player 5. Usage NaN Description Variable; a predefined variable with the IEEE-754 value for NaN (not a number). To determine if a number is NaN, use isNaN(). See also isNaN(), Number.
-Infinity CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage -Infinity Description Constant; specifies the IEEE-754 value representing negative infinity. The value of this constant is the same as Number.NEGATIVE_INFINITY.
CHAPTER 2 ActionScript Language Reference NetConnection class Availability Flash Player 7. Note: This class is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Description The NetConnection class provides the means to play back streaming FLV files from a local drive or HTTP address. For more information on video playback, see “Playing back external FLV files dynamically” in Using ActionScript in Flash.
See also NetStream class, Video.
NetConnection.connect() Availability Flash Player 7. Note: This method is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage my_nc.connect(null) : Void Parameters None (you must pass null). Returns Nothing. Description Constructor; opens a local connection through which you can play back video (FLV) files from an HTTP address or from the local file system.
CHAPTER 2 ActionScript Language Reference NetStream class Availability Flash Player 7. Note: This class is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Description The NetStream class provides methods and properties for playing Flash Video (FLV) files from the local file system or an HTTP address. You use a NetStream object to stream video through a NetConnection object.
Event handler summary for the NetStream class Event handler Description NetStream.onStatus Invoked every time a status change or error is posted for the NetStream object. Constructor for the NetStream class Availability Flash Player 7. Note: This class is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage new NetStream(my_nc:NetConnection) : NetStream Parameters my_nc A NetConnection object.
NetStream.bufferLength Availability Flash Player 7. Note: This property is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage my_ns.bufferLength:Number Description Read-only property; the number of seconds of data currently in the buffer. You can use this property in conjunction with NetStream.
NetStream.bufferTime Availability Flash Player 7. Note: This property is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage my_ns.bufferTime:Number Description Read-only property; the number of seconds assigned to the buffer by NetStream.setBufferTime(). The default value is .1(one-tenth of a second). To determine the number of seconds currently in the buffer, use NetStream.bufferLength.
NetStream.bytesLoaded Availability Flash Player 7. Usage my_ns.bytesLoaded:Number Description Read-only property; the number of bytes of data that have been loaded into the player. You can use this method in conjunction with NetStream.bytesTotal to estimate how close the buffer is to being full—for example, to display feedback to a user who is waiting for data to be loaded into the buffer.
var loaded_interval:Number = setInterval(checkBytesLoaded, 500, stream_ns); function checkBytesLoaded(my_ns:NetStream) { var pctLoaded:Number = Math.round(my_ns.bytesLoaded/my_ns.bytesTotal*100); loaded_txt.text = Math.round(my_ns.bytesLoaded/1000)+" of "+Math.round(my_ns.bytesTotal/1000)+" KB loaded ("+pctLoaded+"%)"; progressBar_mc.bar_mc._xscale = pctLoaded; if (pctLoaded>=100) { clearInterval(loaded_interval); } } See also NetStream.
NetStream.bytesTotal Availability Flash Player 7. Usage my_ns.bytesTotal:Number Description Read-only property; the total size in bytes of the file being loaded into the player. Example The following example creates a progress bar using the Drawing API and the bytesLoaded and bytesTotal properties that displays the loading progress of video1.flv into the video object instance called my_video. A text field called loaded_txt is dynamically created to display information about the loading progress as well.
loaded_txt.text = Math.round(my_ns.bytesLoaded/1000)+" of "+Math.round(my_ns.bytesTotal/1000)+" KB loaded ("+pctLoaded+"%)"; progressBar_mc.bar_mc._xscale = pctLoaded; if (pctLoaded>=100) { clearInterval(loaded_interval); } } See also NetStream.bytesLoaded, NetStream.
NetStream.close() Availability Flash Player 7. Note: This method is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage my_ns.close() : Void Parameters None. Returns Nothing. Description Method; stops playing all data on the stream, sets the NetStream.time property to 0, and makes the stream available for another use.
NetStream.currentFps Availability Flash Player 7. Note: This property is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage my_ns.currentFps:Number Description Read-only property; the number of frames per second being displayed.
NetStream.onStatus Availability Flash Player 7. Note: This handler is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage my_ns.onStatus = function(infoObject:Object) : Void{ // Your code here } Parameters infoObject A parameter defined according to the status or error message. For more information about this parameter, see “Description,” below. Returns Nothing.
Example The following example displays data about the stream in the Output panel: var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); my_video.attachVideo(stream_ns); stream_ns.play("video1.flv"); stream_ns.onStatus = function(infoObject:Object) { trace("NetStream.onStatus called: ("+getTimer()+" ms)"); for (var prop in infoObject) { trace("\t"+prop+":\t"+infoObject[prop]); } trace(""); }; See also System.
NetStream.pause() Availability Flash Player 7. Note: This method is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage my_ns.pause( [ pauseResume:Boolean ] ) : Void Parameters pauseResume A Boolean value specifying whether to pause play (true) or resume play (false). If you omit this parameter, NetStream.
NetStream.play() Availability Flash Player 7. Note: This method is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage my_ns.play("fileName":String); Parameters The name of an FLV file to play, in quotation marks. Both http:// and file:// formats are supported; the file:// location is always relative to the location of the SWF file. fileName Returns Nothing.
See also MovieClip.attachAudio(), NetStream.close(), NetStream.pause(), Video.attachVideo() NetStream.
NetStream.seek() Availability Flash Player 7. Note: This method is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage my_ns.seek(numberOfSeconds:Number) : Void Parameters numberOfSeconds The approximate time value, in seconds, to move to in an FLV file. The playhead moves to the keyframe of the video that’s closest to numberOfSeconds.
NetStream.setBufferTime() Availability Flash Player 7. Note: This method is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage my_ns.setBufferTime(numberOfSeconds:Number) : Void Parameters numberOfSeconds The number of seconds of data to be buffered before Flash begins displaying data. The default value is 0.1 (one-tenth of a second).
NetStream.time Availability Flash Player 7. Note: This property is also supported in Flash Player 6 when used with Flash Communication Server. For more information, see the Flash Communication Server documentation. Usage my_ns.time:Number Description Read-only property; the position of the playhead, in seconds. Example The following example displays the current position of the playhead in a dynamically created text field called time_txt.
new CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage new constructor() Parameters constructor A function followed by any optional parameters in parentheses. The function is usually the name of the object type (for example, Array, Number, or Object) to be constructed. Returns Nothing. Description Operator; creates a new, initially anonymous, object and calls the function identified by the constructor parameter.
newline CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage newline Parameters None. Returns Nothing. Description Constant; inserts a carriage return character (\n) that generates a blank line in text output generated by your code. Use newline to make space for information that is retrieved by a function or statement in your code. Example The following example shows how newline displays output from the trace() statement on multiple lines.
nextFrame() CHAPTER 2 ActionScript Language Reference Availability Flash 2. Usage nextFrame() : Void Parameters None. Returns Nothing. Description Function; sends the playhead to the next frame. Example In the following example, when the user presses the Right or Down arrow key, the playhead goes to the next frame and stops. If the user presses the Left or Up arrow key, the playhead goes to the previous frame and stops.
nextScene() CHAPTER 2 ActionScript Language Reference Availability Flash 2. Usage nextScene() : Void Parameters None. Returns Nothing. Description Function; sends the playhead to Frame 1 of the next scene. Example In the following example, when a user clicks the button that is created at runtime, the playhead is sent to Frame 1 of the next scene. Create two scenes, and enter the following ActionScript on Frame 1 of Scene 1. stop(); if (init == undefined) { this.
null CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage null Parameters None. Returns Nothing. Description Constant; a special value that can be assigned to variables or returned by a function if no data was provided. You can use null to represent values that are missing or that do not have a defined data type. Example In a numeric context, null evaluates to 0. Equality tests can be performed with null.
CHAPTER 2 ActionScript Language Reference Number() Availability Flash Player 4; behavior changed in Flash Player 7. Usage Number(expression) : Number Parameters expression An expression to convert to a number. Returns A number or NaN (not a number). Description Function; converts the parameter expression to a number and returns a value as described in the following list: • If expression is a number, the return value is expression.
See also NaN, Number class Number() 649
Number class CHAPTER 2 ActionScript Language Reference Availability Flash Player 5 (became a native object in Flash Player 6, which improved performance significantly). Description The Number class is a simple wrapper object for the Number data type. You can manipulate primitive numeric values by using the methods and properties associated with the Number class. This class is identical to the JavaScript Number class.
Constructor for the Number class Availability Flash Player 5. Usage new Number(value:Number) : Number Parameters The numeric value of the Number object being created or a value to be converted to a number. The default value is 0 if value is not provided. value Returns A reference to a Number object. Description Constructor; creates a new Number object. You must use the Number constructor when using Number.toString() and Number.valueOf().
Number.MAX_VALUE Availability Flash Player 5. Usage Number.MAX_VALUE:Number Description Property; the largest representable number (double-precision IEEE-754). This number is approximately 1.79e+308. Example The following ActionScript displays the largest and smallest representable numbers to the Output panel. trace("Number.MIN_VALUE = "+Number.MIN_VALUE); trace("Number.MAX_VALUE = "+Number.MAX_VALUE); This code displays the following values: Number.MIN_VALUE = 4.94065645841247e-324 Number.
Number.MIN_VALUE Availability Flash Player 5. Usage Number.MIN_VALUE Description Property; the smallest representable number (double-precision IEEE-754). This number is approximately 5e-324. Example The following ActionScript displays the largest and smallest representable numbers to the Output panel. trace("Number.MIN_VALUE = "+Number.MIN_VALUE); trace("Number.MAX_VALUE = "+Number.MAX_VALUE); This code displays the following values: Number.MIN_VALUE = 4.94065645841247e-324 Number.MAX_VALUE = 1.
Number.NaN Availability Flash Player 5. Usage Number.NaN Description Property; the IEEE-754 value representing Not A Number (NaN).
Number.NEGATIVE_INFINITY Availability Flash Player 5. Usage Number.NEGATIVE_INFINITY Description Property; specifies the IEEE-754 value representing negative infinity. The value of this property is the same as that of the constant -Infinity. Negative infinity is a special numeric value that is returned when a mathematical operation or function returns a negative value larger than can be represented. Example This example compares the result of dividing the following values.
Number.POSITIVE_INFINITY Availability Flash Player 5. Usage Number.POSITIVE_INFINITY Description Property; specifies the IEEE-754 value representing positive infinity. The value of this property is the same as that of the constant Infinity. Positive infinity is a special numeric value that is returned when a mathematical operation or function returns a value larger than can be represented. Example This example compares the result of dividing the following values.
Number.toString() Availability Flash Player 5; behavior changed in Flash Player 7. Usage myNumber.toString(radix:Number) : String Parameters Specifies the numeric base (from 2 to 36) to use for the number-to-string conversion. If you do not specify the radix parameter, the default value is 10. radix Returns A string. Description Method; returns the string representation of the specified Number object (myNumber).
Number.valueOf() Availability Flash Player 5. Usage myNumber.valueOf() : Number Parameters None. Returns Number. Description Method; returns the primitive value type of the specified Number object. Example The following example results in the primative value of the numSocks object. var numSocks = new Number(2); trace(numSocks.
CHAPTER 2 ActionScript Language Reference Object() Availability Flash Player 5. Usage Object( [ value ] ) : Object Parameters value A number, string, or Boolean value. Returns An object. Description Conversion function; creates a new empty object or converts the specified number, string, or Boolean value to an object. This command is equivalent to creating an object using the Object constructor (see “Constructor for the Object class” on page 660).
CHAPTER 2 ActionScript Language Reference Object class Availability Flash Player 5 (became a native object in Flash Player 6, which improved performance significantly). Description The Object class is at the root of the ActionScript class hierarchy. This class contains a small subset of the features provided by the JavaScript Object class. Method summary for the Object class Method Description Object.addProperty() Creates a getter/setter property on an object. Object.
Returns A reference to an Object object. Description Constructor; creates an Object object and stores a reference to the object’s constructor method in the object’s constructor property.
Object.addProperty() Availability Flash Player 6. In ActionScript 2.0 classes, you can use get or set instead of this method. Usage myObject.addProperty(prop:String, getFunc:Function, setFunc:Function) : Boolean Parameters prop A string; the name of the object property to create. getFunc The function that is invoked to retrieve the value of the property; this parameter is a Function object. setFunc The function that is invoked to set the value of the property; this parameter is a Function object.
Error condition What happens getFunc is not a valid function object. Returns false and the property is not added. setFunc is not a valid function object. Returns false and the property is not added. Example In the following example, an object has two internal methods, setQuantity() and getQuantity(). A property, bookcount, can be used to invoke these methods when it is either set or retrieved.
Book.prototype.addProperty("bookcount", Book.prototype.getQuantity, Book.prototype.setQuantity); Book.prototype.addProperty("bookname", Book.prototype.getTitle, null); var myBook = new Book(); myBook.bookcount = 5; trace("You ordered "+myBook.bookcount+" copies of "+myBook.bookname); The following example shows how to use the implicit getter and setter functions available in ActionScript 2.0. For more information, see “Implicit getter/setter methods” in Using ActionScript in Flash.
Object.constructor Availability Flash Player 5 Usage myObject.constructor Description Property; reference to the constructor function for a given object instance. The constructor property is automatically assigned to all objects when they are created using the constructor for the Object class. Example The following example is a reference to the constructor function for the myObject object. var my_str:String = new String("sven"); trace(my_str.
Object.__proto__ Availability Flash Player 5. Usage myObject.__proto__ Description Property; refers to the prototype property of the constructor function that created myObject. The __proto__ property is automatically assigned to all objects when they are created. The ActionScript interpreter uses the __proto__ property to access the prototype property of the object’s constructor function to find out what properties and methods the object inherits from its class.
Object.registerClass() Availability Flash Player 6. If you are using ActionScript 2.0 classes, you can use the ActionScript 2.0 Class field in the Linkage Properties or Symbol Properties dialog box to associate an object with a class instead of using this method. For more information, see “Assigning a class to a movie clip symbol”. in Using ActionScript in Flash. Usage Object.
Object.__resolve Availability Flash Player 6. Usage myObject.__resolve = function (name:String) { // your statements here }; Parameters name A string representing the name of the undefined property. Returns Nothing Description Property; a reference to a user-defined function that is invoked if ActionScript code refers to an undefined property or method.
var myObject:Object = new Object(); // define a function for __resolve to call myObject.myFunction = function (name) { trace("Method " + name + " was called"); }; // define the __resolve function myObject.__resolve = function (name) { return function () { this.myFunction(name); }; }; // test __resolve using undefined method names myObject.someMethod(); // output: Method someMethod was called myObject.
trace("Method "+name+" was called"); }; // define the __resolve function myObject.__resolve = function(name) { // reserve the name “onStatus” for local use if (name == "onStatus") { return undefined; } trace("Resolve called for "+name); // to check when __resolve is called // Not only call the function, but also save a reference to it var f:Function = function () { this.
myObject.someOtherMethod("hello","world"); // output: Method someOtherMethod was called with arguments: hello,world Object.
Object.toString() Availability Flash Player 5. Usage myObject.toString() : String Parameters None. Returns A string. Description Method; converts the specified object to a string and returns it. Example This example shows the return value for toString() on a generic object: var myObject:Object = new Object(); trace(myObject.toString()); // output: [object Object] This method can be overridden to return a more meaningful value.
} function toString():String { var doors:String = "door"; if (this.numDoors > 1) { doors += "s"; } return ("A vehicle that is " + this.color + " and has " + this.numDoors + " " + doors); } } // code to place into a FLA file var myVehicle:Vehicle = new Vehicle(2, "red"); trace(myVehicle.
Object.unwatch() Availability Flash Player 6. Usage myObject.unwatch (prop:String) : Boolean Parameters prop A string; the name of the object property that should no longer be watched. Returns A Boolean value: true if the watchpoint is successfully removed, false otherwise. Description Method; removes a watchpoint that Object.watch() created. This method returns a value of true if the watchpoint is successfully removed, false otherwise. Example See the example for Object.watch(). See also Object.
Object.valueOf() Availability Flash Player 5. Usage myObject.valueOf() : Object Parameters None. Returns The primitive value of the specified object or the object itself. Description Method; returns the primitive value of the specified object. If the object does not have a primitive value, the object is returned.
Object.watch() Availability Flash Player 6. Usage myObject.watch( prop:String, callback:Function [, userData:Object] ) : Boolean Parameters prop A string; the name of the object property to watch. The function to invoke when the watched property changes. This parameter is a function object, not a function name as a string. The form of callback is callback(prop, oldVal, newVal, userData). callback An arbitrary piece of ActionScript data that is passed to the callback method.
The Object.watch() method behaves similarly to the Object.watch() function in JavaScript 1.2 and later. The primary difference is the userData parameter, which is a Flash addition to Object.watch() that Netscape Navigator does not support. You can pass the userData parameter to the event handler and use it in the event handler. The Object.watch() method cannot watch getter/setter properties.
CHAPTER 2 ActionScript Language Reference on() Availability Flash 2. Not all events are supported in Flash 2. Usage on(mouseEvent) { // your statements here } Parameters statement(s) The instructions to execute when the mouseEvent occurs. A mouseEvent is a trigger called an event. When the event occurs, the statements following it within curly braces ({ }) execute.
on (release) { trace("X:"+this._x); trace("Y:"+this.
CHAPTER 2 ActionScript Language Reference onClipEvent() Availability Flash Player 5. Usage onClipEvent(movieEvent){ // your statements here } Parameters A movieEvent is a trigger called an event. When the event occurs, the statements following it within curly braces ({}) are executed. Any of the following values can be specified for the movieEvent parameter: • load • unload The action is initiated in the first frame after the movie clip is removed from the Timeline.
Example The following example uses onClipEvent() with the keyDown movie event and is designed to be attached to a movie clip or button. The keyDown movie event is usually used with one or more methods and properties of the Key object. The following script uses Key.getCode() to find out which key the user has pressed; if the pressed key matches the Key.RIGHT property, the playhead is sent to the next frame; if the pressed key matches the Key.LEFT property, the playhead is sent to the previous frame.
onUpdate CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Usage function onUpdate() { ...statements...; } Parameters None. Returns Nothing. Description Event handler; onUpdate is defined for a Live Preview used with a component. When an instance of a component on the Stage has a Live Preview, the authoring tool invokes the Live Preview’s onUpdate function whenever the component parameters of the component instance change.
buttonLabel.textColor = my_mc.
_parent CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage _parent.property _parent._parent.property Description Identifier; specifies or returns a reference to the movie clip or object that contains the current movie clip or object. The current object is the object containing the ActionScript code that references _parent. Use _parent to specify a relative path to movie clips or objects that are above the current movie clip or object.
parseFloat() CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage parseFloat(string:String) : Number Parameters string The string to read and convert to a floating-point number. Returns A number or NaN (not a number). Description Function; converts a string to a floating-point number. The function reads, or parses, and returns the numbers in a string until it reaches a character that is not a part of the initial number.
CHAPTER 2 ActionScript Language Reference parseInt() Availability Flash Player 5. Usage parseInt(expression:String [, radix:Number]) : Number Parameters expression A string to convert to an integer. radix An integer representing the radix (base) of the number to parse. Legal values are from 2 to 36. This parameter is optional. Returns A number or NaN (not a number). Description Function; converts a string to an integer.
The following examples show octal number parsing and return 511, which is the decimal representation of the octal 777: parseInt("0777") parseInt("777", 8) See also NaN, parseFloat() parseInt() 687
play() CHAPTER 2 ActionScript Language Reference Availability Flash 2. Usage play() : Void Parameters None. Returns Nothing. Description Function; moves the playhead forward in the Timeline. Example In the following example, there are two movie clip instances on the Stage with the instance names stop_mc and play_mc. The ActionScript stops the SWF file’s playback when the stop_mc movie clip instance is clicked. Playback resumes when the play_mc instance is clicked. this.stop_mc.
prevFrame() CHAPTER 2 ActionScript Language Reference Availability Flash 2. Usage prevFrame() : Void Parameters None. Returns Nothing. Description Function; sends the playhead to the previous frame. If the current frame is Frame 1, the playhead does not move. Example When the user clicks a button called myBtn_btn and the following ActionScript is placed on a frame in the Timeline for that button, the playhead is sent to the previous frame: stop(); this.myBtn_btn.
prevScene() CHAPTER 2 ActionScript Language Reference Availability Flash 2. Usage prevScene() : Void Parameters None. Returns Nothing. Description Function; sends the playhead to Frame 1 of the previous scene.
print() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4 (4.0.20.0) Note: If you are authoring for Flash Player 7 or later, you can create a PrintJob object, which gives you (and the user) more control over the printing process. For more information, see the PrintJob class entry. Usage print(target:Object, "Bounding box":String) : Void Parameters target The instance name of a movie clip to print. By default, all the frames in the target instance can be printed.
Example The following example prints all the printable frames in holder_mc with a print area defined by the bounding box of each frame: this.createEmptyMovieClip("holder_mc", 999); holder_mc.loadMovie("http://www.macromedia.com/devnet/mx/blueprint/articles/ nielsen/spotlight_jnielsen.jpg"); this.myBtn_btn.onRelease = function() { print(this._parent.
printAsBitmap() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4 (4.0.20.0) Note: If you are authoring for Flash Player 7 or later, you can create a PrintJob object, which gives you (and the user) more control over the printing process. For more information, see the PrintJob class entry. Usage printAsBitmap(target:Object, "Bounding box":String) : Void Parameters target The instance name of the movie clip to print. By default, all the frames in the movie clip are printed.
The Flash Player printing feature supports PostScript and non-PostScript printers. NonPostScript printers convert vectors to bitmaps. Example The following example prints all the printable frames in holder_mc with a print area defined by the bounding box of the frame: this.createEmptyMovieClip("holder_mc", 999); holder_mc.loadMovie("http://www.macromedia.com/devnet/mx/blueprint/articles/ back_button/sp_mchambers.jpg"); this.myBtn_btn.onRelease = function() { printAsBitmap(this._parent.
printAsBitmapNum() CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Note: If you are authoring for Flash Player 7 or later, you can create a PrintJob object, which gives you (and the user) more control over the printing process. For more information, see the PrintJob class entry. Usage printAsBitmapNum(level:Number, "Bounding box":String) : Void Parameters The level in Flash Player to print. By default, all the frames in the level print.
The Flash Player printing feature supports PostScript and non-PostScript printers. NonPostScript printers convert vectors to bitmaps. Example The following example prints the contents of the Stage when the user clicks the button myBtn_btn. The area to print is defined by the bounding box of the frame. myBtn_btn.
CHAPTER 2 ActionScript Language Reference PrintJob class Availability Flash Player 7. Description The PrintJob class lets you create content and print it to one or more pages. This class, in addition to offering improvements to print functionality provided by the print() method, lets you render dynamic content offscreen, prompt users with a single Print dialog box, and print an unscaled document with proportions that map to the proportions of the content.
To implement a print job, use the following methods in sequence. You must place all commands relating to a specific print job in the same frame, from the constructor through PrintJob.send() and delete. Replace the [params] to the my_pj.addPage() method calls with your custom parameters. // create PrintJob object var my_pj:PrintJob = new PrintJob(); // display print dialog box, but only initiate the print job // if start returns successfully. if (my_pj.
PrintJob.addPage() Availability Flash Player 7. Usage my_pj.addPage(target:Object [, printArea:Object] [, options:Object ] [, frameNumber:Number]) : Boolean Parameters A number or string; the level or instance name of the movie clip to print. Pass a number to specify a level (for example, 0 is the _root movie), or a string (in quotation marks [""]) to specify the instance name of a movie clip.
• If the content that you’re printing includes a bitmap image, use {printAsBitmap:true} to include any transparency and color effects. • If the content does not include bitmap images, omit this parameter or use {printAsBitmap:false} to print the content in higher quality vector format. If options is omitted or is passed incorrectly, vector printing is used. If you don’t want to specify a value for options but want to specify a value for frameNumber, pass null for options.
Example The following example shows several ways to issue the addPage() command: my_btn.onRelease = function() { var pageCount:Number = 0; var my_pj:PrintJob = new PrintJob(); if (my_pj.start()) { // Print entire current frame of the _root movie in vector format if (my_pj.addPage(0)){ pageCount++; // Starting at 0,0, print an area 400 pixels wide and 500 pixels high // of the current frame of the _root movie in vector format if (my_pj.
} } } } } // If addPage() was successful at least once, print the spooled pages. if (pageCount > 0){ my_pj.send(); } delete my_pj; } See also PrintJob.send(), PrintJob.
PrintJob.send() Availability Flash Player 7. Usage my_pj.send() : Void Parameters None. Returns Nothing. Description Method; used following PrintJob.start() and PrintJob.addPage() to send spooled pages to the printer. Because calls to PrintJob.send() will not be successful if related calls to PrintJob.start() and PrintJob.addpage() failed, you should check that calls to PrintJob.addpage() and PrintJob.start() were successful before calling PrintJob.send(): var my_pj:PrintJob = new PrintJob(); if (my_pj.
PrintJob.start() Availability Flash Player 7. Usage my_pj.start() : Boolean Parameters None. Returns A Boolean value: true if the user clicks OK when the print dialog boxes appear; false if the user clicks Cancel or if an error occurs. Description Method; displays the operating system’s print dialog boxes and starts spooling. The print dialog boxes let the user change print settings. When the PrintJob.
var myResult:Boolean = my_pj.start(); if(myResult) { // addPage() and send() statements here } delete my_pj; Example The following example shows how you might use the value of the orientation property to adjust the printout: // create PrintJob object var my_pj:PrintJob = new PrintJob(); // display print dialog box if (my_pj.
printNum() CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Note: If you are authoring for Flash Player 7 or later, you can create a PrintJob object, which gives you (and the user) more control over the printing process. For more information, see the PrintJob class entry. Usage printNum (level:Number, "Bounding box":String) : Void Parameters The level in Flash Player to print. By default, all the frames in the level print.
CHAPTER 2 ActionScript Language Reference private Availability Flash Player 6. Usage class someClassName{ private var name; private function name() { // your statements here } } Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.
import Login: var gus:Login = new Login("Gus", "Smith"); trace(gus.username); // output: Gus trace(gus.password); // output: undefined trace(gus.loginPassword); // error Because loginPassword is a private variable, you cannot access it from outside the Login.as class file. Attempts to access the private variable generate an error message.
CHAPTER 2 ActionScript Language Reference public Flash Player 6. Usage class someClassName{ public var name; public function name() { // your statements here } } Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.
CHAPTER 2 ActionScript Language Reference _quality Availability Flash Player 5. Usage _quality:String Description Property (global); sets or retrieves the rendering quality used for a movie clip. Device fonts are always aliased and therefore are unaffected by the _quality property. The _quality property can be set to the following values: • • "LOW" Low rendering quality. Graphics are not anti-aliased, and bitmaps are not smoothed. "MEDIUM" Medium rendering quality.
removeMovieClip() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage removeMovieClip(target) Parameters The target path of a movie clip instance created with duplicateMovieClip() or the instance name of a movie clip created with MovieClip.attachMovie(), MovieClip.duplicateMovieClip(), or MovieClip.createEmptyMovieClip(). target Returns None. Description Function; deletes the specified movie clip.
return CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage return[expression] Parameters expression A string, number, Boolean, array, or object to evaluate and return as a value of the function. This parameter is optional. Returns The evaluated expression parameter, if provided. Description Statement; specifies the value returned by a function. The return statement evaluates expression and returns the result as a value of the function in which it executes.
CHAPTER 2 ActionScript Language Reference _root Availability Flash Player 5. Usage _root.movieClip _root.action _root.property Parameters movieClip action property The instance name of a movie clip. An action or method. A property of the MovieClip object. Description Identifier; specifies or returns a reference to the root movie clip Timeline. If a movie clip has multiple levels, the root movie clip Timeline is on the level containing the currently executing script.
Selection class CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Description The Selection class lets you set and control the text field in which the insertion point is located (that is, the field that has focus). Selection-span indexes are zero-based (for example, the first position is 0, the second position is 1, and so on). There is no constructor function for the Selection class, because there can be only one currently focused field at a time.
Selection.addListener() Availability Flash Player 6. Usage Selection.addListener(newListener:Object) : Void Parameters newListener An object with an onSetFocus method. Returns None. Description Method; registers an object to receive keyboard focus change notifications. When the focus changes (for example, whenever Selection.setFocus() is invoked), all listening objects registered with addListener() have their onSetFocus method invoked. Multiple objects may listen for focus change notifications.
Selection.getBeginIndex() Availability Flash Player 5. Usage Selection.getBeginIndex() : Number Parameters None. Returns An integer. Description Method; returns the index at the beginning of the selection span. If no index exists or no text field currently has focus, the method returns -1. Selection span indexes are zero-based (for example, the first position is 0, the second position is 1, and so on). Example The following example creates a text field at runtime, and sets its properties.
Selection.getCaretIndex() Availability Flash Player 5. Usage Selection.getCaretIndex() : Number Parameters None. Returns An integer. Description Method; returns the index of the blinking insertion point (caret) position. If there is no blinking insertion point displayed, the method returns -1. Selection span indexes are zero-based (for example, the first position is 0, the second position is 1, and so on). Example The following example creates and sets the properties of a text field at runtime.
Selection.getEndIndex() Availability Flash Player 5. Usage Selection.getEndIndex() : Number Parameters None. Returns An integer. Description Method; returns the ending index of the currently focused selection span. If no index exists, or if there is no currently focused selection span, the method returns -1. Selection span indexes are zero-based (for example, the first position is 0, the second position is 1, and so on). Example This example is excerpted from the Strings.
See the Strings.fla file for the entire script. Typical paths to the HelpExamples folder are: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ See Also Selection.getBeginIndex() Selection.
Selection.getFocus() Availability Flash Player 5. Instance names for buttons and text fields work in Flash Player 6 and later. Usage Selection.getFocus() : String Parameters None. Returns A string or null. Description Method; returns a string specifying the target path of the object that has focus. • If a TextField object has focus, and the object has an instance name, this method returns the target path of the TextField object. Otherwise, it returns the TextField’s variable name.
Selection.onSetFocus Availability Flash Player 6. Usage someListener.onSetFocus = function( [ oldFocus:Object [, newFocus:Object ] ]){ // statements; } Parameters oldfocus The object losing focus. This parameter is optional. newfocus The object receiving focus. This parameter is optional. Description Listener; notified when the input focus changes. To use this listener, you must create a listener object. You can then define a function for this listener and use Selection.
status_txt.htmlText status_txt.htmlText status_txt.htmlText status_txt.htmlText status_txt.htmlText status_txt.htmlText = "setFocus triggered"; += ""; += " \toldFocus:\t"+oldFocus; += " \tnewFocus:\t"+newFocus; += " \tgetFocus:\t"+Selection.getFocus(); += ""; }; Selection.addListener(someListener); See also Selection.addListener(), Selection.
Selection.removeListener() Availability Flash Player 6. Usage Selection.removeListener(listener:Object) Parameters listener The object that will no longer receive focus notifications. Returns If listener was successfully removed, the method returns a true value. If listener was not successfully removed—for example, if listener was not on the Selection object’s listener list— the method returns a value of false. Description Method; removes an object previously registered with Selection.addListener().
Selection.setFocus() Availability Flash Player 5. Instance names for buttons and movie clips work only in Flash Player 6 and later. Usage Selection.setFocus("instanceName":String) Parameters instanceName A string specifying the path to a button, movie clip, or text field instance. Returns A Boolean value; true if the focus attempt is successful, false if it fails. Description Method; gives focus to the selectable (editable) text field, button, or movie clip specified by instanceName.
status_txt.text = "fill in username"; Selection.setFocus("username_txt"); return false; } if (password_txt.text.length == 0) { status_txt.text = "fill in password"; Selection.setFocus("password_txt"); return false; } status_txt.text = "success!"; Selection.setFocus(null); return true; } See also Selection.getFocus(), Selection.onSetFocus Selection.
Selection.setSelection() Availability Flash Player 5. Usage Selection.setSelection(start:Number, end:Number) : Void Parameters The beginning index of the selection span. start end The ending index of the selection span. Returns Nothing. Description Method; sets the selection span of the currently focused text field. The new selection span will begin at the index specified in the start parameter, and end at the index specified in the end parameter.
CHAPTER 2 ActionScript Language Reference set Availability Flash Player 6. Usage function set property(varName) { // your statements here } Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.
In a FLA or AS file that is in the same directory as Login.as, enter the following ActionScriptin Frame 1 of the Timeline: var gus:Login = new Login("Gus", "Smith"); trace(gus.username); // output: Gus gus.username = "Rupert"; trace(gus.username); // output: Rupert In the following example, the get function executes when the value is traced. The set function triggers only when you pass it a value, as shown in the line: gus.username = “Rupert”; See also get, Object.
CHAPTER 2 ActionScript Language Reference set variable Availability Flash Player 4. Usage set("variableString", expression) Parameters variableString expression A string that names a variable to hold the value of the expression parameter. A value assigned to the variable. Returns Nothing. Description Statement; assigns a value to a variable. A variable is a container that holds data. The container is always the same, but the contents can change.
set("name", "Jakob"); trace(name); The following code loops three times and creates three new variables, called caption0, caption1, and caption2: for (var i = 0; i<3; i++) { set("caption"+i, "this is caption "+i); } trace(caption0); trace(caption1); trace(caption2); See also var, call() 730 Chapter 2: ActionScript Language Reference
CHAPTER 2 ActionScript Language Reference setInterval() Availability Flash Player 6. Usage setInterval(functionName:Function, interval:Number [, param1:Object, param2, ..., paramN]) : Number Parameters functionName interval A function name or a reference to an anonymous function. The time in milliseconds between calls to the functionName parameter. param1, param2, ..., paramN methodName Optional parameters passed to the function or parameter.
Usage 3: This example uses a method of an object. You must use this syntax when you want to call a method that is defined for an object. obj = new Object(); obj.interval = function() { trace("interval function called"); } setInterval( obj, "interval", 1000 ); obj2 = new Object(); obj2.
If you work with setInterval() within classes, you need to be sure to use the this keyword when you call the function. The setInterval() function does not have access to class members if you do not use the keyword. This is illustrated in the following example. For a FLA file with a button called deleteUser_btn, add the following ActionScript to Frame 1: var me:User = new User("Gary"); this.deleteUser_btn.onRelease = function() { trace("Goodbye, "+me.
setProperty() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage setProperty(target:Object, property:Object, value/expression:Object) : Void Parameters The path to the instance name of the movie clip whose property is to be set. target property value The property to be set. The new literal value of the property. expression An equation that evaluates to the new value of the property. Returns Nothing.
SharedObject class CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Description Shared objects are powerful: They offer real-time data sharing between objects that are persistent on the user’s computer. You can consider local shared objects as cookies. You can use local shared objects to maintain local persistence. For example, you can call SharedObject.getLocal() to create a shared object, such as a calculator with memory, in the player.
• If the user selects None (moves the slider all the way to the left), all SharedObject.flush() commands issued for the object return "pending", and the player asks the user if additional disk space can be allotted to make room for the object. • If the user selects 10K, 100K, 1 MB, or 10 MB, objects are saved locally and SharedObject.flush() returns true if the object fits within the specified amount of space. If more space is needed, SharedObject.
SharedObject.clear() Availability Flash Player 7. Usage my_so.clear() : Void Parameters None. Returns Nothing. Description Method; purges all the data from the shared object and deletes the shared object from the disk. The reference to my_so is still active, and my_so is now empty. Example The following example sets data in the shared object, and then empties all of the data from the shared object. var my_so:SharedObject = SharedObject.getLocal("superfoo"); my_so.data.
SharedObject.data Availability Flash Player 6. Usage myLocalSharedObject.data:Object Description Property; the collection of attributes assigned to the data property of the object; these attributes can be shared and/or stored. Each attribute can be an object of any basic ActionScript or JavaScript type—Array, Number, Boolean, and so on.
The shared object contains the following data: favoriteSong: My World is Blue favoriteNightClub: The Bluenote Tavern favoriteColor: blue data: [object Object] Example The following example saves text from a TextInput component instance to a shared object named my_so (for the complete example, see SharedObject.getLocal()): // create listener object and function for event var textListener:Object = new Object(); textListener.enter = function(eventObj:Object) { my_so.data.myTextSaved = eventObj.target.
SharedObject.flush() Availability Flash Player 6. Usage myLocalSharedObject.flush([minimumDiskSpace:Number]) : Boolean Parameters An optional integer specifying the number of bytes that must be allotted for this object. The default value is 0.
Example The following function gets a shared object, my_so, and fills writable properties with userprovided settings. Finally, flush() is called to save the settings and allot a minimum of 1000 bytes of disk space. this.syncSettingsCore = function(soName:String, override:Boolean, settings:Object) { var my_so:SharedObject = SharedObject.getLocal(soName, "http:// www.mydomain.
SharedObject.getLocal() Availability Flash Player 6. Usage SharedObject.getLocal(objectName:String [, localPath:String]) : SharedObject Note: The correct syntax is SharedObject.getLocal. To assign the object to a variable, use syntax like myLocal_so = SharedObject.getLocal. Parameters objectName A string that represents the name of the object. The name can include forward slashes (/); for example, work/addresses is a legal name.
Although the localPath parameter is optional, developers should give some thought to its use, especially if other SWF files will need to access the shared object. If the data in the shared object are specific to one SWF file that will not be moved to another location, then use of the default value makes sense.
// Get the user of the kookie and go to the frame number saved for this user. if (my_so.data.user != undefined) { this.user = my_so.data.user; this.gotoAndStop(my_so.data.frame); } The following code block is placed on each SWF file frame: // On each frame, call the rememberme function to save the frame number. function rememberme() { my_so.data.frame=this._currentframe; my_so.data.
SharedObject.getSize() Availability Flash Player 6. Usage myLocalSharedObject.getSize() : Number Parameters None. Returns A numeric value specifying the size of the shared object, in bytes. Description Method; gets the current size of the shared object, in bytes. Flash calculates the size of a shared object by stepping through each of its data properties; the more data properties the object has, the longer it takes to estimate its size.
SharedObject.onStatus Availability Flash Player 6. Usage myLocalSharedObject.onStatus = function(infoObject:Object) { // your statements here } Parameters infoObject A parameter defined according to the status message. Returns Nothing. Description Event handler; invoked every time an error, warning, or informational note is posted for a shared object. If you want to respond to this event handler, you must create a function to process the information object generated by the shared object.
this.createTextField("status_txt", this.getNextHighestDepth(), 10, 30, 300, 100); status_txt.multiline = true; status_txt.html = true; var items_array:Array = new Array(101, 346, 483); var currentUserIsAdmin:Boolean = true; var currentUserName:String = "Ramona"; var my_so:SharedObject = SharedObject.getLocal("superfoo"); my_so.data.itemNumbers = items_array; my_so.data.adminPrivileges = currentUserIsAdmin; my_so.data.userName = currentUserName; my_so.onStatus = function(infoObject:Object) { status_txt.
CHAPTER 2 ActionScript Language Reference Sound class Availability Flash Player 5. Description The Sound class lets you control sound in a movie. You can add sounds to a movie clip from the library while the movie is playing and control those sounds. If you do not specify a target when you create a new Sound object, you can use the methods to control sound for the whole movie. You must use the constructor new Sound to create a Sound object before calling the methods of the Sound class.
Event handler summary for the Sound class Event handler Description Sound.onID3 Invoked each time new ID3 data is available. Sound.onLoad Invoked when a sound loads. Sound.onSoundComplete Invoked when a sound stops playing. Constructor for the Sound class Availability Flash Player 5. Usage new Sound([target:Object]) : Sound Parameters target The movie clip instance on which the Sound object operates. This parameter is optional. Returns A reference to a Sound object.
Sound.attachSound() Availability Flash Player 5. Usage my_sound.attachSound("idName":String) : Void Parameters The identifier of an exported sound in the library. The identifier is located in the Linkage Properties dialog box. idName Returns Nothing. Description Method; attaches the sound specified in the idName parameter to the specified Sound object. The sound must be in the library of the current SWF file and specified for export in the Linkage Properties dialog box. You must call Sound.
Sound.duration Availability Flash Player 6. Usage my_sound.duration:Number Description Read-only property; the duration of a sound, in milliseconds. Example The following example loads a sound and displays the duration of the sound file in the Output panel. Add the following ActionScript to your FLA or AS file. var my_sound:Sound = new Sound(); my_sound.onLoad = function(success:Boolean) { var totalSeconds:Number = this.duration/1000; trace(this.duration+" ms ("+Math.
_xscale = 0; } with (pb.vBar_mc) { lineStyle(1, 0x000000); moveTo(0, 0); lineTo(0, pb_height); } with (pb.stroke_mc) { lineStyle(3, 0x000000); moveTo(0, 0); lineTo(pb_width, 0); lineTo(pb_width, pb_height); lineTo(0, pb_height); lineTo(0, 0); } var my_interval:Number; var my_sound:Sound = new Sound(); my_sound.onLoad = function(success:Boolean) { if (success) { trace("sound loaded"); } }; my_sound.onSoundComplete = function() { clearInterval(my_interval); trace("Cleared interval"); } my_sound.
Sound.getBytesLoaded() Availability Flash Player 6. Usage my_sound.getBytesLoaded() : Number Parameters None. Returns An integer indicating the number of bytes loaded. Description Method; returns the number of bytes loaded (streamed) for the specified Sound object. You can compare the value of getBytesLoaded() with the value of getBytesTotal() to determine what percentage of a sound has loaded.
status_txt.text = the_sound.getBytesLoaded()+" of "+the_sound.getBytesTotal()+" bytes ("+pct+"%)"+newline; status_txt.text += the_sound.position+" of "+the_sound.duration+" milliseconds ("+pos+"%)"+newline; } See also Sound.
Sound.getBytesTotal() Availability Flash Player 6. Usage my_sound.getBytesTotal() : Number Parameters None. Returns An integer indicating the total size, in bytes, of the specified Sound object. Description Method; returns the size, in bytes, of the specified Sound object. Example See Sound.getBytesLoaded() for a sample usage of this method. See also Sound.getBytesLoaded() Sound.
Sound.getPan() Availability Flash Player 5. Usage my_sound.getPan() : Number Parameters None. Returns An integer. Description Method; returns the pan level set in the last setPan() call as an integer from -100 (left) to 100 (right). (0 sets the left and right channels equally.) The pan setting controls the left-right balance of the current and future sounds in a SWF file. This method is cumulative with setVolume() or setTransform().
knob_mc.left = knob_mc._x-(bar_width/2); knob_mc.right = knob_mc._x+(bar_width/2); knob_mc.top = knob_mc._y; knob_mc.bottom = knob_mc._y; knob_mc.onPress = function() { this.startDrag(false, this.left, this.top, this.right, this.bottom); }; knob_mc.onRelease = function() { this.stopDrag(); var multiplier:Number = 100/(this.right-this.left)*2; var pan:Number = (this._x-this.left-(bar_width/2))*multiplier; my_sound.setPan(pan); pan_txt.text = my_sound.getPan(); }; var my_sound:Sound = new Sound(); my_sound.
Sound.getTransform() Availability Flash Player 5. Usage my_sound.getTransform() : Object Parameters None. Returns An object with properties that contain the channel percentage values for the specified sound object. Description Method; returns the sound transform information for the specified Sound object set with the last Sound.setTransform() call.
knob_ll.onReleaseOutside = releaseKnob; knob_lr.top = knob_lr._y; knob_lr.bottom = knob_lr._y+100; knob_lr.left = knob_lr._x; knob_lr.right = knob_lr._x; knob_lr._y = knob_lr._y+(100-transform_obj['lr']); knob_lr.onPress = pressKnob; knob_lr.onRelease = releaseKnob; knob_lr.onReleaseOutside = releaseKnob; knob_rl.top = knob_rl._y; knob_rl.bottom = knob_rl._y+100; knob_rl.left = knob_rl._x; knob_rl.right = knob_rl._x; knob_rl._y = knob_rl._y+(100-transform_obj['rl']); knob_rl.onPress = pressKnob; knob_rl.
Sound.getVolume() Availability Flash Player 5. Usage my_sound.getVolume() : Number Parameters None. Returns An integer. Description Method; returns the sound volume level as an integer from 0 to 100, where 0 is off and 100 is full volume. The default setting is 100. Example The following example creates a slider using the Drawing API and a movie clip that is created at runtime. A dynamically created text field displays the current volume level of the sound playing in the SWF file.
this.isDragging = true; }; knob_mc.onMouseMove = function() { if (this.isDragging) { this.volume_txt.text = this._x; } } knob_mc.onRelease = function() { this.stopDrag(); this.isDragging = false; my_sound.setVolume(this._x); }; See also Sound.setVolume() Sound.
Sound.id3 Availability Flash Player 6; behavior updated in Flash Player 7. Usage my_sound.id3:Object Description Read-only property; provides access to the metadata that is part of an MP3 file. MP3 sound files can contain ID3 tags, which provide metadata about the file. If an MP3 sound that you load using Sound.attachSound() or Sound.loadSound() contains ID3 tags, you can query these properties. Only ID3 tags that use the UTF-8 character set are supported. Flash Player 6 (6.0.40.
Property Description TMED Media type TOAL Original album/movie/show title TOFN Original filename TOLY Original lyricists/text writers TOPE Original artists/performers TORY Original release year TOWN File owner/licensee TPE1 Lead performers/soloists TPE2 Band/orchestra/accompaniment TPE3 Conductor/performer refinement TPE4 Interpreted, remixed, or otherwise modified by TPOS Part of a set TPUB Publisher TRCK Track number/position in set TRDA Recording dates TRSN Internet radio
ID3 2.0 tag Corresponding ID3 1.0 property TRCK Sound.id3.track TYER Sound.id3.year Example The following example traces the ID3 properties of song.mp3 to the Output panel: var my_sound:Sound = new Sound(); my_sound.onID3 = function(){ for( var prop in my_sound.id3 ){ trace( prop + " : "+ my_sound.id3[prop] ); } } my_sound.loadSound("song.mp3", false); See also Sound.attachSound(), Sound.
Sound.loadSound() Availability Flash Player 6. Usage my_sound.loadSound(url:String, isStreaming:Boolean) : Void Parameters url The location on a server of an MP3 sound file. isStreaming A Boolean value that indicates whether the sound is a streaming sound (true) or an event sound (false). Returns Nothing. Description Method; loads an MP3 file into a Sound object. You can use the isStreaming parameter to indicate whether the sound is an event or a streaming sound.
Sound.onID3 Availability Flash Player 7. Usage my_sound.onID3 = function(){ // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked each time new ID3 data is available for an MP3 file that you load using Sound.attachSound() or Sound.loadSound(). This handler provides access to ID3 data without polling. If both ID3 1.0 and ID3 2.0 tags are present in a file, this handler is called twice. Example The following example displays the ID3 properties of song1.
Sound.onLoad Availability Flash Player 6. Usage my_sound.onLoad = function(success:Boolean){ // your statements here } Parameters success A Boolean value of true if my_sound has been loaded successfully, false otherwise. Returns Nothing. Description Event handler; invoked automatically when a sound loads. You must create a function that executes when the this handler is invoked. You can use either an anonymous function or a named function (for an example of each, see Sound.onSoundComplete).
Sound.onSoundComplete Availability Flash Player 6. Usage my_sound.onSoundComplete = function(){ // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked automatically when a sound finishes playing. You can use this handler to trigger events in a SWF file when a sound finishes playing. You must create a function that executes when this handler is invoked. You can use either an anonymous function or a named function.
Sound.position Availability Flash Player 6. Usage my_sound.position:Number Description Read-only property; the number of milliseconds a sound has been playing. If the sound is looped, the position is reset to 0 at the beginning of each loop. Example See Sound.duration for a sample usage of this property. See Also Sound.duration Sound.
Sound.setPan() Availability Flash Player 5. Usage my_sound.setPan(pan:Number) : Number Parameters An integer specifying the left-right balance for a sound. The range of valid values is -100 to 100, where -100 uses only the left channel, 100 uses only the right channel, and 0 balances the sound evenly between the two channels. pan Returns An integer. Description Method; determines how the sound is played in the left and right channels (speakers).
Sound.setTransform() Availability Flash Player 5. Usage my_sound.setTransform(soundTransformObject:Object) : Void Parameters soundTransformObject An object created with the constructor for the generic Object class. Returns Nothing. Description Method; sets the sound transform (or balance) information, for a Sound object.
Mono sounds play all sound input in the left speaker and have the following transform settings by default: ll lr rr rl = = = = 100 100 0 0 Example The following example illustrates a setting that can be achieved by using setTransform(), but cannot be achieved by using setVolume() or setPan(), even if they are combined. The following code creates a new soundTransformObject object and sets its properties so that sound from both channels will play only in the left channel.
Sound.setVolume() Availability Flash Player 5. Usage my_sound.setVolume(volume:Number) : Void Parameters A number from 0 to 100 representing a volume level. 100 is full volume and 0 is no volume. The default setting is 100. volume Returns Nothing. Description Method; sets the volume for the Sound object. Example See Sound.getVolume() for a sample usage of this method. See also Sound.setPan(), Sound.setTransform() Sound.
Sound.start() Availability Flash Player 5. Usage my_sound.start([secondOffset:Number, loop:Number]) : Void Parameters secondOffset An optional parameter that lets you start playing the sound at a specific point. For example, if you have a 30-second sound and want the sound to start playing in the middle, specify 15 for the secondOffset parameter. The sound is not delayed 15 seconds, but rather starts playing at the 15-second mark.
Sound.stop() Availability Flash Player 5. Usage my_sound.stop(["idName":String]) : Void Parameters An optional parameter specifying a specific sound to stop playing. The idName parameter must be enclosed in quotation marks (" "). idName Returns Nothing. Description Method; stops all sounds currently playing if no parameter is specified, or just the sound specified in the idName parameter.
_soundbuftime CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage _soundbuftime:Number = integer Parameters integer The number of seconds before the SWF file starts to stream. Description Property (global); establishes the number of seconds of streaming sound to buffer. The default value is 5 seconds. Example The following example streams an MP3 file and buffers the sound before it plays for the user.
CHAPTER 2 ActionScript Language Reference Stage class Availability Flash Player 6. Description The Stage class is a top-level class whose methods, properties, and handlers you can access without using a constructor. Use the methods and properties of this class to access and manipulate information about the boundaries of a SWF file. Method summary for the Stage class Method Description Stage.addListener() Adds a listener object that detects when a SWF file is resized. Stage.
Stage.addListener() Availability Flash Player 6. Usage Stage.addListener(myListener:Object) : Void Parameters myListener An object that listens for a callback notification from the Stage.onResize event. Returns Nothing. Description Method; detects when a SWF file is resized (but only if Stage.scaleMode = "noScale"). The addListener() method doesn’t work with the default movie clip scaling setting (showAll) or other scaling settings (exactFit and noBorder).
Stage.align Availability Flash Player 6. Usage Stage.align:String Description Property; indicates the current alignment of the SWF file in the player or browser. The following table lists the values for the align property. Any value not listed here centers the SWF file in Flash player or browser area, which is the default setting.
Stage.height Availability Flash Player 6. Usage Stage.height:Number Description Property (read-only); indicates the current height, in pixels, of the Stage. When the value of Stage.scaleMode is noScale, the height property represents the height of Flash Player. When the value of Stage.scaleMode is not noScale, height represents the height of the SWF file. Example This example creates a new listener object called stageListener.
Stage.onResize Availability Flash Player 6. Usage myListener.onResize = function(){ // your statements here } Parameters None. Returns Nothing. Description Listener; invoked when Stage.scaleMode is set to noScale and the SWF file is resized. You can use this event handler to write a function that lays out the objects on the Stage when a SWF file is resized. Example The following example displays a message in the Output panel when the Stage is resized: Stage.
Stage.removeListener() Availability Flash Player 6. Usage Stage.removeListener(myListener:Object) : Boolean Parameters myListener An object added to an object’s callback list with addListener(). Returns A Boolean value. Description Method; removes a listener object created with addListener(). Example The following example displays the Stage dimensions in a dynamically created text field. When you resize the Stage, the values in the text field update. Create a button with an instance name remove_btn.
Stage.scaleMode Availability Flash Player 6. Usage Stage.scaleMode:String Description Property; indicates the current scaling of the SWF file within Flash Player. The scaleMode property forces the SWF file into a specific scaling mode. By default, the SWF file uses the HTML parameters set in the Publish Settings dialog box. The scaleMode property can use the values "exactFit", "showAll", "noBorder", and "noScale". Any other value sets the scaleMode property to the default "showAll".
Stage.showMenu Availability Flash Player 6. Usage Stage.showMenu:Boolean Description Property; specifies whether to show or hide the default items in the Flash Player context menu. If showMenu is set to true (the default), all context menu items appear. If showMenu is set to false, only Settings and About Macromedia Flash Player items appear. Example The following example creates a clickable text link that lets the user enable and disable the Flash Player context menu. this.
Stage.width Availability Flash Player 6. Usage Stage.width:Number Description Property (read-only); indicates the current width, in pixels, of the Stage. When the value of Stage.scaleMode is "noScale", the width property represents the width of Flash Player. This means that Stage.width will vary as you resize the player window. When the value of Stage.scaleMode is not "noScale", width represents the width of the SWF file as set at authortime in the Document Properties dialog box.
startDrag() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage startDrag(target:Object,[lock:Boolean, left:Number, top:Number, right:Number, bottom:Number]) : Void Parameters target The target path of the movie clip to drag. A Boolean value specifying whether the draggable movie clip is locked to the center of the mouse position (true) or locked to the point where the user first clicked the movie clip (false). This parameter is optional.
CHAPTER 2 ActionScript Language Reference static Availability Flash Player 6. Usage class someClassName{ static var name; static function name() { // your statements here } } Note: To use this keyword, you must specify ActionScript 2.0 and Flash Player 6 or later in the Flash tab of your FLA file’s Publish Settings dialog box. This keyword is supported only when used in external script files, not in scripts written in the Actions panel.
See also private, public 788 Chapter 2: ActionScript Language Reference
stop() CHAPTER 2 ActionScript Language Reference Availability Flash 2. Usage stop() Parameters None. Returns Nothing. Description Function; stops the SWF file that is currently playing. The most common use of this action is to control movie clips with buttons. See also gotoAndStop(), MovieClip.
stopAllSounds() CHAPTER 2 ActionScript Language Reference Availability Flash Player 3. Usage stopAllSounds() : Void Parameters None. Returns Nothing. Description Function; stops all sounds currently playing in a SWF file without stopping the playhead. Sounds set to stream will resume playing as the playhead moves over the frames in which they are located. Example The following code creates a text field, in which the song’s ID3 information appears.
stopDrag() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage stopDrag() : Void Parameters None. Returns Nothing. Description Function; stops the current drag operation. Example The following code, placed in the main Timeline, stops the drag action on the movie clip instance my_mc when the user releases the mouse button: my_mc.onPress = function () { startDrag(this); } my_mc.onRelease = function() { stopDrag(); } See also MovieClip._droptarget, MovieClip.
CHAPTER 2 ActionScript Language Reference String() Availability Flash Player 4; behavior changed in Flash Player 7. Usage String(expression) Parameters expression An expression to convert to a string. Returns A string. Description Function; returns a string representation of the specified parameter, as described in the following list: • If expression is a number, the return string is a text representation of the number. • If expression is a string, the return string is expression.
CHAPTER 2 ActionScript Language Reference String class Availability Flash Player 5 (became a native object in Flash Player 6, which improved performance significantly). Description The String class is a wrapper for the string primitive data type, and provides methods and properties that let you manipulate primitive string value types. You can convert the value of any object into a string using the String() function.
Method Description String.substring() Returns the characters between two indexes in a string. String.toLowerCase() Converts the string to lowercase and returns the result; does not change the contents of the original object. String.toUpperCase() Converts the string to uppercase and returns the result; does not change the contents of the original object. Property summary for the String class Property Description String.
String.charAt() Availability Flash Player 5. Usage my_str.charAt(index:Number) : String Parameters A number; an integer specifying the position of a character in the string. The first character is indicated by 0, and the last character is indicated by my_str.length-1. index Returns A character. Description Method; returns the character in the position specified by the parameter index. If index is not a number from 0 to string.length - 1, an empty string is returned. This method is similar to String.
String.charCodeAt() Availability Flash Player 5. Usage my_str.charCodeAt(index:Number) : Number Parameters A number; an integer that specifies the position of a character in the string. The first character is indicated by 0, and the last character is indicated by my_str.length - 1. index Returns A number; an integer. Description Method; returns a 16-bit integer from 0 to 65535 that represents the character specified by index. If index is not a number from 0 to string.length - 1, NaN is returned.
String.concat() Availability Flash Player 5. Usage my_str.concat(value1,...valueN) : String Parameters value1,...valueN Zero or more values to be concatenated. Returns A string. Description Method; combines the value of the String object with the parameters and returns the newly formed string; the original value, my_str, is unchanged. Example The following example creates two strings and combines them using String.
String.fromCharCode() Availability Flash Player 5. Usage String.fromCharCode(c1:Number,c2,...cN) : String Parameters c1,c2,...cN A number; decimal integers that represent ASCII values. Returns A string. Description Method; returns a string comprising the characters represented by the ASCII values in the parameters. Example The following example uses fromCharCode() to insert an @ character in the e-mail address: var address_str:String = "dog"+String.fromCharCode(64)+"house.
String.indexOf() Availability Flash Player 5. Usage my_str.indexOf(substring:String, [startIndex:Number]) Parameters substring startIndex A string; the substring to be searched for within my_str. A number; an optional integer specifying the starting point in my_str to search for the substring. Returns A number; the position of the first occurrence of the specified substring or -1.
String.lastIndexOf() Availability Flash Player 5. Usage my_str.lastIndexOf(substring:String, [startIndex:Number]) : Number Parameters substring startIndex String; the string for which to search. Number; an optional integer specifying the starting point from which to search for substring. Returns A number; the position of the last occurrence of the specified substring or -1.
String.length Availability Flash Player 5. Usage my_str.length:Number Description Property; an integer specifying the number of characters in the specified String object. Because all string indexes are zero-based, the index of the last character for any string x is x.length - 1. Example The following example creates a new String object and uses String.length to count the number of characters: var my_str:String = "Hello world!"; trace(my_str.
String.slice() Availability Flash Player 5. Usage my_str.slice(start:Number, [end:Number]) : String Parameters A number; the zero-based index of the starting point for the slice. If start is a negative number, the starting point is determined from the end of the string, where -1 is the last character. start end A number; an integer that is 1+ the index of the ending point for the slice. The character indexed by the end parameter is not included in the extracted string.
// slices that omit the end parameter use String.length, which equals 5 trace("slice(0): "+my_str.slice(0)); // slice(0): Lorem trace("slice(3): "+my_str.slice(3)); // slice(3): em An example is also in the Strings.fla file in the HelpExamples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ • See also String.substr(), String.
String.split() Availability Flash Player 5. Usage my_str.split("delimiter":String, [limit:Number]) : Number Parameters delimiter limit A string; the character or string at which my_str splits. A number; the number of items to place into the array. This parameter is optional. Returns An array; an array containing the substrings of my_str. Description Method; splits a String object into substrings by breaking it wherever the specified delimiter parameter occurs and returns the substrings in an array.
/* output: J o e */ An example is also in the Strings.fla file in the HelpExamples folder. The following list gives typical paths to this folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ • See Also Array.join() String.
String.substr() Availability Flash Player 5. Usage my_str.substr(start:Number, [length:Number]) : String Parameters A number; an integer that indicates the position of the first character in my_str to be used to create the substring. If start is a negative number, the starting position is determined from the end of the string, where the -1 is the last character. start length A number; the number of characters in the substring being created.
String.substring() Availability Flash Player 5. Usage my_str.substring(start:Number, [end:Number]) : String Parameters A number; an integer that indicates the position of the first character of my_str used to create the substring. Valid values for start are 0 through String.length - 1. If start is a negative value, 0 is used. start A number; an integer that is 1+ the index of the last character in my_str to be extracted. Valid values for end are 1 through String.length.
String.toLowerCase() Availability Flash Player 5. Usage my_str.toLowerCase() : String Parameters None. Returns A string. Description Method; returns a copy of the String object, with all uppercase characters converted to lowercase. The original value is unchanged.
String.toUpperCase() Availability Flash Player 5. Usage my_str.toUpperCase() : String Parameters None. Returns A string. Description Method; returns a copy of the String object, with all lowercase characters converted to uppercase. The original value is unchanged. Example The following example creates a string with all lowercase characters and then creates a copy of that string using toUpperCase(): var lowerCase:String = "lorem ipsum dolor"; var upperCase:String = lowerCase.
" " (string delimiter) CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage "text" Parameters text A sequence of zero or more characters. Returns Nothing. Description String delimiter; when used before and after characters, quotation marks ("") indicate that the characters have a literal value and are considered a string, not a variable, numerical value, or other ActionScript element.
CHAPTER 2 ActionScript Language Reference super Availability Flash Player 6. Usage super.method([arg1, ..., argN]) super([arg1, ..., argN]) Parameters method The method to invoke in the superclass. Optional parameters that are passed to the superclass version of the method (syntax 1) or to the constructor function of the superclass (syntax 2). arg1 Returns Both forms invoke a function. The function can return any value.
Then create a new class called Socks that extends the Clothes class, as shown in the following example: class Socks extends Clothes { private var color:String; function Socks(param_color:String) { this.color = param_color; trace("[Socks] I am the constructor"); } function getColor():String { trace("[Socks] I am getColor"); return super.getColor(); } function setColor(param_color:String):Void { this.
CHAPTER 2 ActionScript Language Reference switch Availability Flash Player 4. Usage switch (expression){ caseClause: [defaultClause:] } Parameters expression Any expression. caseClause A case keyword followed by an expression, a colon, and a group of statements to execute if the expression matches the switch expression parameter using strict equality (===). A default keyword followed by statements to execute if none of the case expressions match the switch expression parameter strict equality (===).
case "i" : trace("you pressed I or i"); break; default : trace("you pressed some other key"); } }; Key.
System.capabilities object CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Description You can use the System.capabilities object to determine the abilities of the system and player hosting a SWF file, which lets you tailor content for different formats. For example, the screen of a cell phone (black and white, 100 square pixels) is different than the 1000-square-pixel color PC screen. To provide appropriate content to as many users as possible, you can use the System.
Property Description Server string System.capabilities.hasScreenBroadcast Indicates whether the player supports the development of screen broadcast applications to be run through the Flash Communication Server. SB System.capabilities.hasScreenPlayback Indicates whether the player supports the playback of screen broadcast applications that are being run through the Flash Communication Server. SP System.capabilities.hasStreamingAudio Indicates whether the player can play streaming audio.
System.capabilities.avHardwareDisable Availability Flash Player 7. Usage System.capabilities.avHardwareDisable:Boolean Description Read-only property; a Boolean value that specifies whether access to the user’s camera and microphone has been administratively prohibited (true) or allowed (false). The server string is AVD. Example The following example traces the value of this read-only property: trace(System.capabilities.avHardwareDisable); See also Camera.get(), Microphone.get(), System.
System.capabilities.hasAccessibility Availability Flash Player 6. Usage System.capabilities.hasAccessibility:Boolean Description Read-only property: a Boolean value that is true if the player is running in an environment that supports communication between Flash Player and accessibility aids; false otherwise. The server string is ACC. Example The following example traces the value of this read-only property: trace(System.capabilities.hasAccessibility); See also Accessibility.isActive(), Accessibility.
System.capabilities.hasAudio Availability Flash Player 6. Usage System.capabilities.hasAudio:Boolean Description Read-only property: a Boolean value that is true if the player is running on a system that has audio capabilities; false otherwise. The server string is A. Example The following example traces the value of this read-only property: trace(System.capabilities.hasAudio); System.capabilities.
System.capabilities.hasAudioEncoder Availability Flash Player 6. Usage System.capabilities.hasAudioEncoder:Boolean Description Read-only property: a Boolean value that is true if the player can encode an audio stream, such as that coming from a microphone; false otherwise. The server string is AE. Example The following example traces the value of this read-only property: trace(System.capabilities.
System.capabilities.hasEmbeddedVideo Availability Flash Player 6 r65. Usage System.capabilities.hasEmbeddedVideo:Boolean Description Read-only property: a Boolean value that is true if the player is running on a system that supports embedded video; false otherwise. The server string is EV. Example The following example traces the value of this read-only property: trace(System.capabilities.hasEmbeddedVideo); System.capabilities.
System.capabilities.hasMP3 Availability Flash Player 6. Usage System.capabilities.hasMP3:Boolean Description Read-only property: a Boolean value that is true if the player is running on a system that has an MP3 decoder; false otherwise. The server string is MP3. Example The following example traces the value of this read-only property: trace(System.capabilities.
System.capabilities.hasPrinting Availability Flash Player 6 r65. Usage System.capabilities.hasPrinting:Boolean Description Read-only property: a Boolean value that is true if the player is running on a system that supports printing; false otherwise. The server string is PR. Example The following example traces the value of this read-only property: trace(System.capabilities.hasPrinting); System.capabilities.
System.capabilities.hasScreenBroadcast Availability Flash Player 6 r79. Usage System.capabilities.hasScreenBroadcast:Boolean Description Read-only property: a Boolean value that is true if the player supports the development of screen broadcast applications to be run through the Flash Communication Server; false otherwise. The server string is SB. Example The following example traces the value of this read-only property: trace(System.capabilities.
System.capabilities.hasScreenPlayback Availability Flash Player 6 r79. Usage System.capabilities.hasScreenPlayback:Boolean Description Read-only property: a Boolean value that is true if the player supports the playback of screen broadcast applications that are being run through the Flash Communication Server; false otherwise. The server string is SP. Example The following example traces the value of this read-only property: trace(System.capabilities.hasScreenPlayback); System.capabilities.
System.capabilities.hasStreamingAudio Availability Flash Player 6 r65. Usage System.capabilities.hasStreamingAudio:Boolean Description Read-only property: a Boolean value that is true if the player can play streaming audio; false otherwise. The server string is SA. Example The following example traces the value of this read-only property: trace(System.capabilities.
System.capabilities.hasStreamingVideo Availability Flash Player 6 r65. Usage System.capabilities.hasStreamingVideo:Boolean Description Read-only property: a Boolean value that is true if the player can play streaming video; false otherwise. The server string is SV. Example The following example traces the value of this read-only property: trace(System.capabilities.hasStreamingVideo); System.capabilities.
System.capabilities.hasVideoEncoder Availability Flash Player 6. Usage System.capabilities.hasVideoEncoder:Boolean Description Read-only property: a Boolean value that is true if the player can encode a video stream, such as that coming from a web camera; false otherwise. The server string is VE. Example The following example traces the value of this read-only property: trace(System.capabilities.
System.capabilities.isDebugger Availability Flash Player 6. Usage System.capabilities.isDebugger:Boolean Description Read-only property; a Boolean value that indicates whether the player is an officially released version (false) or a special debugging version (true). The server string is DEB. Example The following example traces the value of this read-only property: trace(System.capabilities.isDebugger); System.capabilities.
System.capabilities.language Availability Flash Player 6. Behavior changed in Flash Player 7. Usage System.capabilities.language:String Description Read-only property; indicates the language of the system on which the player is running. This property is specified as a lowercase two-letter language code from ISO 639-1. For Chinese, an additional uppercase two-letter country code subtag from ISO 3166 distinguishes between Simplified and Traditional Chinese.
Language Tag Russian ru Simplified Chinese zh-CN Spanish es Swedish sv Traditional Chinese zh-TW Turkish tr Example The following example traces the value of this read-only property: trace(System.capabilities.language); System.capabilities.
System.capabilities.localFileReadDisable Availability Flash Player 7. Usage System.capabilities.localFileReadDisable:Boolean Description Read-only property; a Boolean value that indicates whether read access to the user’s hard disk has been administratively prohibited (true) or allowed (false). If set to true, Flash Player will be unable to read files (including the first SWF file that Flash Player launches with) from the user’s hard disk.
System.capabilities.manufacturer Availability Flash Player 6. Usage System.capabilities.manufacturer:String Description Read-only property; a string that indicates the manufacturer of Flash Player, in the format "Macromedia OSName" (OSName could be "Windows", "Macintosh", "Linux", or "Other OS Name"). The server string is M. Example The following example traces the value of this read-only property: trace(System.capabilities.manufacturer); System.capabilities.
System.capabilities.os Availability Flash Player 6. Usage System.capabilities.os:String Description Read-only property; a string that indicates the current operating system. The os property can return the following strings: "Windows XP", "Windows 2000", "Windows NT", "Windows 98/ME", "Windows 95", "Windows CE" (available only in Flash Player SDK, not in the desktop version), "Linux", and "MacOS". The server string is OS.
System.capabilities.pixelAspectRatio Availability Flash Player 6. Usage System.capabilities.pixelAspectRatio:Number Description Read-only property; an integer that indicates the pixel aspect ratio of the screen. The server string is AR. Example The following example traces the value of this read-only property: trace(System.capabilities.pixelAspectRatio); System.capabilities.
System.capabilities.playerType Availability Flash Player 7. Usage System.capabilities.playerType;String Description Read-only property; a string that indicates the type of player.
System.capabilities.screenColor Availability Flash Player 6. Usage System.capabilities.screenColor:String Description Read-only property; a string that indicates the screen color. This property can have the value "color", "gray" or "bw", which represents color, grayscale, and black and white, respectively. The server string is COL. Example The following example traces the value of this read-only property: trace(System.capabilities.screenColor); System.capabilities.
System.capabilities.screenDPI Availability Flash Player 6. Usage System.capabilities.screenDPI:Number Description Read-only property; a number that indicates the dots-per-inch (dpi) resolution of the screen, in pixels. The server string is DP. Example The following example traces the value of this read-only property: trace(System.capabilities.
System.capabilities.screenResolutionX Availability Flash Player 6. Usage System.capabilities.screenResolutionX:Number Description Read-only property; an integer that indicates the maximum horizontal resolution of the screen. The server string is R (which returns both the width and height of the screen). Example The following example traces the value of this read-only property: trace(System.capabilities.screenResolutionX); System.capabilities.
System.capabilities.screenResolutionY Availability Flash Player 6. Usage System.capabilities.screenResolutionY:Number Description Read-only property; an integer that indicates the maximum vertical resolution of the screen. The server string is R (which returns both the width and height of the screen). Example The following example traces the value of this read-only property: trace(System.capabilities.
System.capabilities.serverString Availability Flash Player 6. Usage System.capabilities.serverString:String Description Read-only property; a URL-encoded string that specifies values for each System.capabilities property, as shown in the following example: A=t&SA=t&SV=t&EV=t&MP3=t&AE=t&VE=t&ACC=f&PR=t&SP=t&SB=f&DEB=t&V=WIN%207%2C0%2C 19%2C0&M=Macromedia%20Windows&R=1600x1200&DP=72&COL=color&AR=1.
System.capabilities.version Availability Flash Player 6. Usage System.capabilities.version:String Description Read-only property; a string containing the Flash Player platform and version information (for example, "WIN 7,0,19,0"). The server string is V. Example The following example traces the value of this read-only property: trace(System.capabilities.
System.security object CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Description This object contains methods that specify how SWF files in different domains can communicate with each other. Method summary for the System.security object Method Description System.security.allowDomain() Lets SWF files in the identified domains access objects and variables in the calling SWF file or in any other SWF file from the same domain as the calling SWF file. System.security.
System.security.allowDomain() Availability Flash Player 6; behavior changed in Flash Player 7. Usage System.security.allowDomain("domain1":String, "domain2", ... "domainN") : Void Parameters domain1, domain2, ... domainN Strings that specify domains that can access objects and variables in the file containing the System.Security.allowDomain() call. The domains can be formatted in the following ways: • • • "domain.com" "http://domain.
The opposite situation can also occur; that is, you might create a child SWF file that wants to allow its parent to script it, but doesn’t know what the domain of its parent will be. In this situation, call System.security.allowDomain(_parent._url) from the child SWF. In this situation, you don’t have to wait for the parent SWF file to load; the parent will already be loaded by the time the child loads. Example The SWF file located at www.macromedia.com/MovieA.swf contains the following lines: System.
System.security.allowInsecureDomain() Availability Flash Player 7. Usage System.security.allowInsecureDomain("domain":String) : Void Parameters A string; an exact domain name, such as www.myDomainName.com or store.myDomainName.com. domain Returns Nothing. Description Method; lets SWF files and HTML files in the identified domains access objects and variables in the calling SWF file, which is hosted using the HTTPS protocol.
See also System.security.allowDomain(), System.exactSettings System.security.
System.security.loadPolicyFile() Availability Flash Player 7 (7.0.19.0) Usage System.security.loadPolicyFile(url:String) : Void Parameters url A string; the URL where the cross-domain policy file to be loaded is located. Returns Nothing. Description Method; loads a cross-domain policy file from a location specified by the url parameter. Flash Player uses policy files as a permission mechanism to permit Flash movies to load data from servers other than their own. Flash Player 7.0.14.
This causes Flash Player to attempt to retrieve a policy file from the specified host and port. Any port can be used, not only ports 1024 and higher. Upon establishing a connection with the specified port, Flash Player transmits , terminated by a null byte. An XMLSocket server can be configured to serve both policy files and normal XMLSocket connections over the same port, in which case the server should wait for before transmitting a policy file.
CHAPTER 2 ActionScript Language Reference System class Availability Flash Player 6. Description This is a top-level class that contains the capabilities object (see System.capabilities object), the security object (see System.security object), and the methods, properties, and event handlers listed in the following table. Method summary for the System class Method Description System.setClipboard() Replaces the contents of the system Clipboard with a text string. System.
System.exactSettings Availability Flash Player 7 or later. Usage System.exactSettings:Boolean Description Property; a Boolean value that specifies whether to use superdomain (false) or exact domain (true) matching rules when accessing local settings (such as camera or microphone access permissions) or locally persistent data (shared objects). The default value is true for files published for Flash Player 7 or later, and false for files published for Flash Player 6.
Usually you should find that the default value of System.exactSettings is fine. Often your only requirement is that when a SWF file saves a shared object in one session, the same SWF file can retrieve the same shared object in a later session. This situation will always be true, regardless of the value of System.exactSettings. But you might want to change System.
System.onStatus Availability Flash Player 6. Usage System.onStatus = function(InfoObject:Object) { // your statements } Description Event handler: provides a super event handler for certain objects. The LocalConnection, NetStream, and SharedObject classes provide an onStatus event handler that uses an information object for providing information, status, or error messages.
System.setClipboard() Availability SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later. Usage System.setClipboard(string:String) : Boolean Parameters string A plain-text string of characters to place on the system Clipboard, replacing its current contents (if any). Returns A Boolean value: true if the text is successfully placed on the Clipboard; false otherwise. Description Method; replaces the contents of the Clipboard with a specified text string.
System.showSettings() Availability Flash Player 6. Usage System.showSettings([panel:Number]) : Void Parameters A number; an optional number that specifies which Flash Player Settings panel to display, as shown in the following table: panel Value passed for panel Settings panel displayed None (parameter is omitted) or an unsupported value The panel that was open the last time the user closed the Player Settings panel. 0 Privacy 1 Local Storage 2 Microphone 3 Camera Returns Nothing.
System.useCodepage Availability Flash Player 6. Usage System.useCodepage:Boolean Description Property; a Boolean value that tells Flash Player whether to use Unicode or the traditional code page of the operating system running the player to interpret external text files. The default value of System.useCodepage is false. • When the property is set to false, Flash Player interprets external text files as Unicode. (These files must be encoded as Unicode when you save them.
targetPath() CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage targetpath(movieClipObject:MovieClip) : String Parameters movieClipObject Reference (for example, _root or _parent) to the movie clip for which the target path is being retrieved. Returns A string containing the target path of the specified movie clip. Description Function; returns a string containing the target path of movieClipObject. The target path is returned in dot (.) notation.
TextField.StyleSheet class CHAPTER 2 ActionScript Language Reference Availability Flash Player 7. Description The TextField.StyleSheet class lets you create a style sheet object that contains text formatting rules such as font size, color, and other formatting styles. You can then apply styles defined by a style sheet to a TextField object that contains HTML- or XML-formatted text.
Constructor for the TextField.StyleSheet class Availability Flash Player 7. Usage new TextField.StyleSheet() : TextField.StyleSheet Returns A reference to a TextField.StyleSheet object. Description Constructor; creates a TextField.StyleSheet object. Example The following example loads in a style sheet and outputs the styles that load into the document. Add the following ActionScript to your AS or FLA file: var my_styleSheet:TextField.StyleSheet = new TextField.StyleSheet(); my_styleSheet.
TextField.StyleSheet.clear() Availability Flash Player 7. Usage styleSheet.clear() : Void Parameters None. Returns Nothing. Description Method; removes all styles from the specified style sheet object. Example The following example loads a style sheet called styles.css into a SWF file, and displays the styles that are loaded in the Output panel. When you click clear_btn, all styles from the my_styleSheet object are removed. // Create a new style sheet object var my_styleSheet:TextField.
TextField.StyleSheet.getStyle() Availability Flash Player 7. Usage styleSheet.getStyle(styleName:String) : Object Parameters styleName A string that specifies the name of the style to retrieve. Returns An object. Description Method; returns a copy of the style object associated with the style named styleName. If there is no style object associated with styleName, null is returned.
var styleObject:Object = my_styleSheet.getStyle(styleName); for (var propName in styleObject) { var propValue = styleObject[propName]; trace("\t"+propName+": "+propValue); } trace(""); } } } } Create a new CSS document called styles.css, which has two styles called heading and mainBody that define properties for font-family, font-size and font-weight. Enter the following code: /* In styles.css */ .heading { font-family: Arial, Helvetica, sans-serif; font-size: 24px; font-weight: bold; } .
TextField.StyleSheet.getStyleNames() Availability Flash Player 7. Usage styleSheet.getStyleNames() : Array Parameters None. Returns An array. Description Method; returns an array that contains the names (as strings) of all of the styles registered in this style sheet. Example This example creates a style sheet object named styleSheet that contains two styles, heading and bodyText.
TextField.StyleSheet.load() Availability Flash Player 7. Usage styleSheet.load(url:String) : Void Parameters The URL of a CSS file to load. The URL must be in the same domain as the URL where the SWF file currently resides. url Returns Nothing. Description Method; starts loading the CSS file into styleSheet. The load operation is asynchronous; use the TextField.StyleSheet.onLoad callback handler to determine when the file has finished loading.
TextField.StyleSheet.onLoad Availability Flash Player 7. Usage styleSheet.onLoad = function (success:Boolean) {} Parameters success A Boolean value indicating whether the CSS file was successfully loaded. Returns Nothing. Description Callback handler; invoked when a TextField.StyleSheet.load() operation has completed. If the style sheet loaded successfully, the success parameter is true.
TextField.StyleSheet.parseCSS() Availability Flash Player 7. Usage styleSheet.parseCSS(cssText:String) : Boolean Parameters cssText The CSS text to parse (a string). Returns A Boolean value indicating if the text was parsed successfully (true) or not (false). Description Method; parses the CSS in cssText and loads the style sheet with it. If a style in cssText is already in styleSheet, the properties in styleSheet are retained, and only the ones in cssText are added or changed in styleSheet.
TextField.StyleSheet.setStyle() Availability Flash Player 7. Usage styleSheet.setStyle(name:String, style:Object) : Void Parameters name style A string that specifies the name of the style to add to the style sheet. An object that describes the style, or null. Returns Nothing. Description Method; adds a new style with the specified name to the style sheet object. If the named style does not already exist in the style sheet, it is added.
This displays the following information in the Output panel: emphasized fontWeight: bold color: #000000 Note: The line of code delete styleObj deletes the original style object passed to setStyle(). While not necessary, this step reduces memory usage, because Flash Player creates a copy of the style object you pass to setStyle().
TextField.StyleSheet.transform() Availability Flash Player 7. Usage styleSheet.transform(style:Object) : TextFormat Parameters style An object that describes the style, containing style rules as properties of the object, or null. Returns A TextFormat object containing the result of the mapping of CSS rules to text format properties. Description Method; extends the CSS parsing capability. Advanced developers can override this method by extending the TextField.StyleSheet class.
TextField class CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Description All dynamic and input text fields in a SWF file are instances of the TextField class. You can give a text field an instance name in the Property inspector and use the methods and properties of the TextField class to manipulate it with ActionScript. TextField instance names are displayed in the Movie Explorer and in the Insert Target Path dialog box in the Actions panel.
Property Description TextField.border Indicates if the text field has a border. TextField.borderColor Indicates the color of the border. TextField.bottomScroll Read-only; the bottommost visible line in a text field. TextField.embedFonts Indicates whether the text field uses embedded font outlines or device fonts. TextField._height The height of a text field instance in pixels. This affects only the bounding box of the text field; it does not affect the border thickness or text font size.
Property Description TextField.textHeight The height of the text field’s bounding box. TextField.textWidth The width of the text field’s bounding box. TextField.type Indicates whether a text field is an input text field or dynamic text field. TextField._url Read-only; the URL of the SWF file that created the text field instance. TextField.variable The variable name associated with the text field. TextField.
TextField.addListener() Availability Flash Player 6. Usage my_txt.addListener(listener:Object) : Void Parameters listener An object with an onChanged or onScroller event handler. Returns Nothing. Description Method; registers an object to receive notification when the onChanged and onScroller event handlers have been invoked. When a text field changes or is scrolled, the TextField.onChanged and TextField.
}; my_txt.addListener(txtListener); See also TextField.onChanged, TextField.onScroller, TextField.
TextField._alpha Availability Flash Player 6. Usage my_txt._alpha:Number Description Property; sets or retrieves the alpha transparency value of the text field specified by my_txt. Valid values are 0 (fully transparent) to 100 (fully opaque). The default value is 100. Transparency values are not supported for text files that use device fonts. You must use embedded fonts to use the _alpha transparency property with a text field.
TextField.autoSize Availability Flash Player 6. Usage my_txt.autoSize:String my_txt.autoSize:Boolean Description Property; controls automatic sizing and alignment of text fields. Acceptable values for autoSize are "none" (the default), "left", "right", and "center". When you set the autoSize property, true is a synonym for "left" and false is a synonym for "none". The values of autoSize and TextField.wordWrap determine whether a text field expands or contracts to the left side, right side, or bottom side.
center_txt.text = "short text"; center_txt.border = true; right_txt.text = "short text"; right_txt.border = true; true_txt.text = "short text"; true_txt.border = true; false_txt.text = "short text"; false_txt.border = true; // create a mouse listener object to detect mouse clicks var myMouseListener:Object = new Object(); // define a function that executes when a user clicks the mouse myMouseListener.onMouseDown = function() { left_txt.autoSize = "left"; left_txt.
TextField.background Availability Flash Player 6. Usage my_txt.background:Boolean Description Property; if true, the text field has a background fill. If false, the text field has no background fill. Example The following example creates a text field with a button that toggles the background color of the field. this.createTextField("my_txt", this.getNextHighestDepth(), 10, 10, 320, 240); my_txt.border = true; my_txt.text = "Lorum ipsum"; my_txt.backgroundColor = 0xFF0000; toggle_btn.
TextField.backgroundColor Availability Flash Player 6. Usage my_txt.backgroundColor:Number Description Property; the color of the text field background. Default is 0xFFFFFF (white). This property may be retrieved or set, even if there currently is no background, but the color is only visible if the text field has a border. Example See the example for TextField.background. See also TextField.background TextField.
TextField.border Availability Flash Player 6. Usage my_txt.border:Boolean Description Property; if true, the text field has a border. If false, the text field has no border. Example The following example creates a text field called my_txt, sets the border property to true, and displays some text in the field. this.createTextField("my_txt", this.getNextHighestDepth(), 10, 10, 320, 240); my_txt.border = true; my_txt.
TextField.borderColor Availability Flash Player 6. Usage my_txt.borderColor:Number Description Property; the color of the text field border, the Default is 0x000000 (black). This property may be retrieved or set, even if there is currently no border. Example The following example creates a text field called my_txt, sets the border property to true, and displays some text in the field. this.createTextField("my_txt", this.getNextHighestDepth(), 10, 10, 320, 240); my_txt.border = true; my_txt.
TextField.bottomScroll Availability Flash Player 6. Usage my_txt.bottomScroll:Number Description Read-only property; an integer (one-based index) that indicates the bottommost line that is currently visible in my_txt. Think of the text field as a “window” onto a block of text. The property TextField.scroll is the one-based index of the topmost visible line in the window. All the text between lines TextField.scroll and TextField.bottomScroll is currently visible in the text field.
TextField.condenseWhite Availability Flash Player 6. Usage my_txt.condenseWhite:Boolean Description Property; a Boolean value that specifies whether extra white space (spaces, line breaks, and so on) in an HTML text field should be removed when the field is rendered in a browser. The default value is false. If you set this value to true, you must use standard HTML commands such as
and
to place line breaks in the text field. If my_txt.html is false, this property is ignored.
TextField.embedFonts Availability Flash Player 6. Usage my_txt.embedFonts:Boolean Description Property; a Boolean value that, when true, renders the text field using embedded font outlines. If false, it renders the text field using device fonts. Example In this example, you need to create a dynamic text field called my_txt, and then use the following ActionScript to embed fonts and rotate the text field. The reference to my font refers to a Font symbol in the library, with linkage set to my font.
TextField.getDepth() Availability Flash Player 6. Usage my_txt.getDepth() : Number Parameters None. Returns An integer. Description Method; returns the depth of a text field. Example The following example demonstrates text fields residing at different depths. Create a dynamic text field on the Stage. Add the following ActionScript to your FLA or AS file, which dynamically creates two text fields at runtime and outputs their depths. this.createTextField("first_mc", this.
TextField.getFontList() Availability Flash Player 6. Usage TextField.getFontList() : Array Parameters None. Returns An array. Description Method; a static method of the global TextField class. You don’t specify a specific text field (such as my_txt) when you call this method. This method returns names of fonts on the player’s host system as an array. (It does not return names of all fonts in currently loaded SWF files.) The names are of type String.
TextField.getNewTextFormat() Availability Flash Player 6. Usage my_txt.getNewTextFormat() : TextFormat Parameters None. Returns A TextFormat object. Description Method; returns a TextFormat object containing a copy of the text field’s text format object. The text format object is the format that newly inserted text, such as text inserted with the replaceSel() method or text entered by a user, receives. When getNewTextFormat() is invoked, the TextFormat object returned has all of its properties defined.
TextField.getTextFormat() Availability Flash Player 6. Usage my_txt.getTextFormat() : Object my_txt.getTextFormat(index:Number) : Object my_txt.getTextFormat(beginIndex:Number, endIndex:Number) : Object Parameters index An integer that specifies a character in a string. beginIndex, endIndex Integers that specify the starting and ending locations of a span of text within my_txt. Returns An object. Description Method; returns a TextFormat object containing a particular kind of information.
TextField._height Availability Flash Player 6. Usage my_txt._height:Number Description Property; the height of the text field, in pixels. Example The following code example sets the height and width of a text field: my_txt._width = 200; my_txt._height = 200; TextField.
TextField.hscroll Availability Flash Player 6. Usage my_txt.hscroll:Number Returns An integer. Description Property; indicates the current horizontal scrolling position. If the hscroll property is 0, the text is not horizontally scrolled. For more information on scrolling text, see “Creating scrolling text” in Using ActionScript in Flash. The units of horizontal scrolling are pixels, while the units of vertical scrolling are lines.
TextField.html Availability Flash Player 6. Usage my_txt.html:Boolean Description Property; a flag that indicates whether the text field contains an HTML representation. If the html property is true, the text field is an HTML text field. If html is false, the text field is a non-HTML text field. Example The following example creates a text field that sets the html property to true. HTML-formatted text displays in the text field. this.createTextField("my_txt", this.
TextField.htmlText Availability Flash Player 6. Usage my_txt.htmlText:String Description Property; if the text field is an HTML text field, this property contains the HTML representation of the text field’s contents. If the text field is not an HTML text field, it behaves identically to the text property. You can indicate that a text field is an HTML text field in the Property inspector, or by setting the text field’s html property to true.
TextField.length Availability Flash Player 6. Usage my_txt.length:Number Returns A number. Description Read-only property; indicates the number of characters in a text field. This property returns the same value as text.length, but is faster. A character such as tab (\t) counts as one character. Example The following example outputs the number of characters in the date_txt text field, which displays the current date. var today:Date = new Date(); this.createTextField("date_txt", this.
TextField.maxChars Availability Flash Player 6. Usage my_txt.maxChars:Number Description Property; indicates the maximum number of characters that the text field can contain. A script may insert more text than maxChars allows; the maxChars property indicates only how much text a user can enter. If the value of this property is null, there is no limit on the amount of text a user can enter.
TextField.maxhscroll Availability Flash Player 6. Usage my_txt.maxhscroll:Number Description Read-only property; indicates the maximum value of TextField.hscroll. Example See the example for TextField.hscroll. TextField.
TextField.maxscroll Availability Flash Player 6. Usage TextField.maxscroll:Number Description Read-only property; indicates the maximum value of TextField.scroll. For more information on scrolling text, see “Creating scrolling text” in Using ActionScript in Flash. Example The following example sets the maximum value for the scrolling text field my_txt. Create two buttons, scrollUp_btn and scrollDown_btn, to scroll the text field. Add the following ActionScript to your FLA or AS file. this.
TextField.menu Availability Flash Player 7. Usage my_txt.menu = contextMenu Parameters contextMenu A ContextMenu object. Description Property; associates the ContextMenu object contextMenu with the text field my_txt. The ContextMenu class lets you modify the context menu that appears when the user right-clicks (Windows) or Control-clicks (Macintosh) in Flash Player. This property works only with selectable (editable) text fields; it has no effect on nonselectable text fields.
TextField.mouseWheelEnabled Availability Flash Player 7. Usage my_txt.mouseWheelEnabled:Boolean Description Property; a Boolean value that indicates whether Flash Player should automatically scroll multiline text fields when the mouse pointer clicks a text field and the user rolls the mouse wheel. By default, this value is true. This property is useful if you want to prevent mouse wheel scrolling of text fields, or implement your own text field scrolling.
TextField.multiline Availability Flash Player 6. Usage my_txt.multiline:Boolean Description Property; indicates whether the text field is a multiline text field. If the value is true, the text field is multiline; if the value is false, the text field is a single-line text field. Example The following example creates a multiline text field called fontList_txt that displays a long, multiline list of fonts. var font_array:Array = TextField.getFontList().sort(); this.createTextField("fontList_txt", this.
TextField._name Availability Flash Player 6. Usage my_txt._name:String Description Property; the instance name of the text field specified by my_txt. Example The following example demonstrates text fields residing at different depths. Create a dynamic text field on the Stage. Add the following ActionScript to your FLA or AS file, which dynamically creates two text fields at runtime and displays their depths in the Output panel. this.createTextField("first_mc", this.
TextField.onChanged Availability Flash Player 6. Usage my_txt.onChanged = function(){ // your statements here } myListenerObj.onChanged = function(){ // your statements here } Parameters None. Returns The instance name of the text field. Description Event handler/listener; invoked when the content of a text field changes. By default, it is undefined; you can define it in a script. A reference to the text field instance is passed as a parameter to the onChanged handler.
TextField.onKillFocus Availability Flash Player 6. Usage my_txt.onKillFocus = function(newFocus:Object){ // your statements here } Parameters newFocus The object that is receiving the focus. Returns Nothing. Description Event handler; invoked when a text field loses keyboard focus. The onKillFocus method receives one parameter, newFocus, which is an object representing the new object receiving the focus. If no object receives the focus, newFocus contains the value null.
TextField.onScroller Availability Flash Player 6. Usage my_txt.onScroller = function(textFieldInstance:TextField){ // your statements here } myListenerObj.onScroller = function(textFieldInstance:TextField){ // your statements here } Parameters textFieldInstance A reference to the TextField object whose scroll position was changed. Returns Nothing. Description Event handler/listener; invoked when one of the text field scroll properties changes.
Example The following example creates a text field called my_txt, and uses two buttons called scrollUp_btn and scrollDown_btn to scroll the contents of the text field. When the onScroller event handler is called, a trace statement is used to display information in the Output panel. Create two buttons with instance names scrollUp_btn and scrollDown_btn, and add the following ActionScript to your FLA or AS file: this.createTextField("scroll_txt", this.getNextHighestDepth(), 10, 10, 160, 20); this.
TextField.onSetFocus Availability Flash Player 6. Usage my_txt.onSetFocus = function(oldFocus:Object){ // your statements here } Parameters oldFocus The object to lose focus. Returns Nothing. Description Event handler; invoked when a text field receives keyboard focus. The oldFocus parameter is the object that loses the focus. For example, if the user presses the Tab key to move the input focus from a button to a text field, oldFocus contains the text field instance.
TextField._parent Availability Flash Player 6. Usage my_txt._parent.property _parent.property Description Property; a reference to the movie clip or object that contains the current text field or object. The current object is the one containing the ActionScript code that references _parent. Use _parent to specify a relative path to movie clips or objects that are above the current text field. You can use _parent to climb up multiple levels in the display list as in the following: _parent._parent.
TextField.password Availability Flash Player 6. Usage my_txt.password:Boolean Description Property; if the value of password is true, the text field is a password text field and hides the input characters using asterisks instead of the actual characters. If false, the text field is not a password text field. When password mode is enabled, the Cut and Copy commands and their corresponding keyboard accelerators will not function.
TextField._quality Availability Flash Player 6. Usage my_txt._quality:String Description Property (global); sets or retrieves the rendering quality used for a SWF file. Device fonts are always aliased and, therefore, are unaffected by the _quality property. Note: Although you can specify this property for a TextField object, it is actually a global property, and you can specify its value simply as _quality. For more information, see the _quality property.
TextField.removeListener() Availability Flash Player 6. Usage my_txt.removeListener(listener:Object) Parameters The object that will no longer receive notifications from TextField.onChanged or TextField.onScroller. listener Returns If listener was successfully removed, the method returns a true value. If listener was not successfully removed (for example, if listener was not on the TextField object’s listener list), the method returns a value of false.
TextField.removeTextField() Availability Flash Player 6. Usage my_txt.removeTextField() : Void Description Method; removes the text field specified by my_txt. This operation can only be performed on a text field that was created with MovieClip.createTextField(). When you call this method, the text field is removed. This method is similar to MovieClip.removeMovieClip(). Example The following example creates a text field that you can remove from the Stage when you click the remove_btn instance.
TextField.replaceSel() Availability Flash Player 6. Usage my_txt.replaceSel(text:String) : Void Parameters text A string. Returns Nothing. Description Method; replaces the current selection with the contents of the text parameter. The text is inserted at the position of the current selection, using the current default character format and default paragraph format. The text is not treated as HTML, even if the text field is an HTML text field.
TextField.replaceText() Availability Flash Player 7. Usage my_txt.replaceText(beginIndex:Number, endIndex:Number, text:String) : Void Description Method; replaces a range of characters, specified by the beginIndex and endIndex parameters, in the specified text field with the contents of the text parameter. Example The following example creates a text field called my_txt and assigns the text dog@house.net to the field. The indexOf() method is used to find the first occurrence of the specified symbol (@).
TextField.restrict Availability Flash Player 6. Usage my_txt.restrict:String Description Property; indicates the set of characters that a user may enter into the text field. If the value of the restrict property is null, you can enter any character. If the value of the restrict property is an empty string, you can’t enter any character. If the value of the restrict property is a string of characters, you can enter only characters in the string into the text field. The string is scanned from left to right.
TextField._rotation Availability Flash Player 6. Usage my_txt._rotation:Number Description Property; the rotation of the text field, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement my_txt._rotation = 450 is the same as my_txt._rotation = 90.
TextField.scroll Availability Flash Player 6. Usage my_txt.scroll Description Property; defines the vertical position of text in a text field. The scroll property is useful for directing users to a specific paragraph in a long passage, or creating scrolling text fields. This property can be retrieved and modified. The units of horizontal scrolling are pixels, while the units of vertical scrolling are lines.
TextField.selectable Availability Flash Player 6. Usage my_txt.selectable:Boolean Description Property; a Boolean value that indicates whether the text field is selectable. The value true indicates that the text is selectable. The selectable property controls whether a text field is selectable, and not whether a text field is editable. A dynamic text field can be selectable even if it's not editable. If a dynamic text field is not selectable, that means you cannot select its text.
TextField.setNewTextFormat() Availability Flash Player 6. Usage my_txt.setNewTextFormat(textFormat:TextFormat) : Void Parameters textFormat A TextFormat object. Returns Nothing. Description Method; sets the default new text format of a text field; that is, the text format to be used for newly inserted text, such as text inserted with the replaceSel() method or text entered by a user. When text is inserted, the newly inserted text is assigned the default new text format.
TextField.setTextFormat() Availability Flash Player 6. Usage my_txt.setTextFormat (textFormat:TextFormat) : Void my_txt.setTextFormat (index:Number, textFormat:TextFormat) : Void my_txt.setTextFormat (beginIndex:Number, endIndex:Number, textFormat:TextFormat) : Void Parameters A TextFormat object, which contains character and paragraph formatting textFormat information. index An integer that specifies a character within my_txt. beginIndex endIndex An integer.
Notice that any text inserted manually by the user, or replaced by means of TextField.replaceSel(), receives the text field's default formatting for new text, and not the formatting specified for the text insertion point. To set a text field’s default formatting for new text, use TextField.setNewTextFormat(). Example The following example sets the text format for two different strings of text. The setTextFormat() method is called and applied to the my_txt text field.
TextField.styleSheet Availability Flash Player 7. Usage my_txt.styleSheet = TextField StyleSheet Description Property; attaches a style sheet to the text field specified by my_txt. For information on creating style sheets, see the TextField.StyleSheet class entry and “Formatting text with Cascading Style Sheets” in Using ActionScript in Flash. The style sheet associated with a text field may be changed at any time. If the style sheet in use is changed, the text field is redrawn using the new style sheet.
if (success) { news_txt.styleSheet = styleObj; news_txt.htmlText = newsText; } }; styleObj.load("styles2.css"); }; clearCss_btn.onRelease = function() { news_txt.styleSheet = undefined; news_txt.htmlText = newsText; }; The following styles are applied to the text field. Save the following two CSS files in the same directory as the FLA or AS file you created previously: /* in styles.css */ .important { color: #FF0000; } .bold { font-weight: bold; } .
TextField.tabEnabled Availability Flash Player 6. Usage my_txt.tabEnabled:Boolean Description Property; specifies whether my_txt is included in automatic tab ordering. It is undefined by default. If the tabEnabled property is undefined or true, the object is included in automatic tab ordering. If the tabIndex property is also set to a value, the object is included in custom tab ordering as well.
TextField.tabIndex Availability Flash Player 6. Usage my_txt.tabIndex:Number Parameters None. Returns Nothing. Description Property; lets you customize the tab ordering of objects in a SWF file. You can set the tabIndex property on a button, movie clip, or text field instance; it is undefined by default.
one_txt.tabIndex = 3; two_txt.tabIndex = 1; three_txt.tabIndex = 2; four_txt.tabIndex = 4; See also Button.tabIndex, MovieClip.
TextField._target Availability Flash Player 6. Usage my_txt._target:String Description Read-only property; the target path of the text field instance specified by my_txt. The _self target specifies the current frame in the current window, _blank specifies a new window, _parent specifies the parent of the current frame, and _top specifies the top-level frame in the current window.
TextField.text Availability Flash Player 6. Usage my_txt.text:String Description Property; indicates the current text in the text field. Lines are separated by the carriage return character ('\r', ASCII 13). This property contains the normal, unformatted text in the text field, without HTML tags, even if the text field is HTML. Example The following example creates an HTML text field called my_txt, and assigns an HTMLformatted string of text to the field.
TextField.textColor Availability Flash Player 6. Usage my_txt.textColor:Number Description Property; indicates the color of the text in a text field. The hexadecimal color system uses six digits to represent color values. Each digit has sixteen possible values or characters. The characters range from 0 to 9 and then A to F. Black is represented by (#000000) and white, at the opposite end of the color system, is (#FFFFFF).
TextField.textHeight Availability Flash Player 6. Usage my_txt.textHeight:Number Description Property; indicates the height of the text. Example The following example creates a text field, and assigns a string of text to the field. A trace statement is used to display the text height and width in the Output panel. The autoSize property is then used to resize the text field, and the new height and width will also be displayed in the Output panel. this.
TextField.textWidth Availability Flash Player 6. Usage my_txt.textWidth:Number Description Property; indicates the width of the text. Example See the example for TextField.textHeight. See Also TextField.textHeight TextField.
TextField.type Availability Flash Player 6. Usage my_txt.type:String Description Property; Specifies the type of text field. There are two values: "dynamic", which specifies a dynamic text field that cannot be edited by the user, and "input", which specifies an input text field. Example The following example creates two text fields: username_txt and password_txt. Text is entered into both text fields; however, password_txt has the password property set to true.
TextField._url Availability Flash Player 6. Usage my_txt._url:String Description Read-only property; retrieves the URL of the SWF file that created the text field. Example The following example retrieves the URL of the SWF file that created the text field, and a SWF file that loads into it. this.createTextField("my_txt", 1, 10, 10, 100, 22); trace(my_txt._url); var mclListener:Object = new Object(); mclListener.onLoadInit = function(target_mc:MovieClip) { trace(target_mc.
TextField.variable Availability Flash Player 6. Usage my_txt.variable:String Description Property; The name of the variable that the text field is associated with. The type of this property is String. Example The following example creates a text field called my_txt and associates the variable today_date with the text field. When you change the variable today_date, then the text that displays in my_txt updates. this.createTextField("my_txt", 1, 10, 10, 200, 22); my_txt.
TextField._visible Availability Flash Player 6. Usage my_txt._visible:Boolean Description Property; a Boolean value that indicates whether the text field my_txt is visible. Text fields that are not visible (_visible property set to false) are disabled. Example The following example creates a text field called my_txt. A button called visible_btn toggles the visibility of my_txt. this.createTextField("my_txt", 1, 10, 10, 200, 22); my_txt.background = true; my_txt.backgroundColor = 0xDFDFDF; my_txt.
TextField._width Availability Flash Player 6. Usage my_txt._width:Number Description Property; the width of the text field, in pixels. Example The following example creates two text fields that you can use to change the width and height of a third text field on the Stage. Add the following ActionScript to a FLA or AS file. this.createTextField("my_txt", this.getNextHighestDepth(), 10, 40, 160, 120); my_txt.background = true; my_txt.backgroundColor = 0xFF0000; my_txt.border = true; my_txt.
TextField.wordWrap Availability Flash Player 6. Usage my_txt.wordWrap:Boolean Description Property; a Boolean value that indicates if the text field has word wrap. If the value of wordWrap is true, the text field has word wrap; if the value is false, the text field does not have word wrap. Example The following example demonstrates how wordWrap affects long text in a text field that’s created at runtime. this.createTextField("my_txt", 99, 10, 10, 100, 200); my_txt.
TextField._x Availability Flash Player 6. Usage my_txt._x:Number Description Property; an integer that sets the x coordinate of a text field relative to the local coordinates of the parent movie clip. If a text field is on the main Timeline, then its coordinate system refers to the upper left corner of the Stage as (0, 0). If the text field is inside a movie clip that has transformations, the text field is in the local coordinate system of the enclosing movie clip.
TextField._xmouse Availability Flash Player 6. Usage my_txt._xmouse:Number Description Read-only property; returns the x coordinate of the mouse position relative to the text field. Example The following example creates three text fields on the Stage. The mouse_txt instance displays the current position of the mouse in relation to the Stage. The textfield_txt instance displays the current position of the mouse pointer in relation to the my_txt instance.
TextField._xscale Availability Flash Player 6. Usage my_txt._xscale:Number Description Property; determines the horizontal scale of the text field as applied from the registration point of the text field, expressed as a percentage. The default registration point is (0,0). Example The following example scales the my_txt instance when you click the scaleUp_btn and scaleDown_btn instances. this.createTextField("my_txt", 99, 10, 40, 100, 22); my_txt.autoSize = true; my_txt.border = true; my_txt.
TextField._y Availability Flash Player 6. Usage my_txt._y:Number Description Property; the y coordinate of a text field relative to the local coordinates of the parent movie clip. If a text field is in the main Timeline, then its coordinate system refers to the upper left corner of the Stage as (0, 0). If the text field is inside another movie clip that has transformations, the text field is in the local coordinate system of the enclosing movie clip.
TextField._ymouse Availability Flash Player 6. Usage my_txt._ymouse:Number Description Read-only property; indicates the y coordinate of the mouse position relative to the text field. Example See the example for TextField._xmouse. See also TextField.
TextField._yscale Availability Flash Player 6. Usage my_txt._yscale:Number Description Property; the vertical scale of the text field as applied from the registration point of the text field, expressed as a percentage. The default registration point is (0,0). Example See the example for TextField._xscale. See also TextField._x, TextField._xscale, TextField._y TextField.
TextFormat class CHAPTER 2 ActionScript Language Reference Availability Flash Player 6. Description The TextFormat class represents character formatting information. You must use the constructor new TextFormat() to create a TextFormat object before calling its methods. You can set TextFormat parameters to null to indicate that they are undefined. When you apply a TextFormat object to a text field using TextField.setTextFormat(), only its defined properties are applied, as in the following example: this.
Property Description TextFormat.indent Indicates the indentation from the left margin to the first character in the paragraph. TextFormat.italic Indicates whether text is italicized. TextFormat.leading Indicates the amount of vertical space (called leading) between lines. TextFormat.leftMargin Indicates the left margin of the paragraph, in points. TextFormat.rightMargin Indicates the right margin of the paragraph, in points. TextFormat.size Indicates the point size of text. TextFormat.
leftMargin rightMargin Indicates the left margin of the paragraph, in points. Indicates the right margin of the paragraph, in points. indent An integer that indicates the indentation from the left margin to the first character in the paragraph. leading A number that indicates the amount of leading vertical space between lines. Returns A reference to a TextFormat object. Description Constructor; creates a TextFormat object with the specified properties.
TextFormat.align Availability Flash Player 6. Usage my_fmt.align:String Description Property; indicates the alignment of the paragraph, represented as a string. The alignment of the paragraph, represented as a string. If "left", the paragraph is left-aligned. If "center", the paragraph is centered. If "right", the paragraph is right-aligned. The default value is null which indicates that the property is undefined. Example The following example creates a text field with a border and uses TextFormat.
TextFormat.blockIndent Availability Flash Player 6. Usage my_fmt.blockIndent:Number Description Property; a number that indicates the block indentation in points. Block indentation is applied to an entire block of text; that is, to all lines of the text. In contrast, normal indentation (TextFormat.indent) affects only the first line of each paragraph. If this property is null, the TextFormat object does not specify block indentation.
TextFormat.bold Availability Flash Player 6. Usage my_fmt.bold:Boolean Description Property; a Boolean value that specifies whether the text is boldface. The default value is null, which indicates that the property is undefined. If the value is true, then the text is boldface. Example The following example creates a text field that includes characters in boldface. var my_fmt:TextFormat = new TextFormat(); my_fmt.bold = true; this.createTextField("my_txt", 1, 100, 100, 300, 100); my_txt.
TextFormat.bullet Availability Flash Player 6. Usage my_fmt.bullet:Boolean Description Property; a Boolean value that indicates that the text is part of a bulleted list. In a bulleted list, each paragraph of text is indented. To the left of the first line of each paragraph, a bullet symbol is displayed. The default value is null. Example The following example creates a new text field at runtime, and enters a string with a line break into the field.
TextFormat.color Availability Flash Player 6. Usage my_fmt.color:Number Description Property; indicates the color of text. A number containing three 8-bit RGB components; for example, 0xFF0000 is red, and 0x00FF00 is green. Example The following example creates a text field and sets the text color to red. var my_fmt:TextFormat = new TextFormat(); my_fmt.blockIndent = 20; this.createTextField("my_txt", 1, 100, 100, 300, 100); my_txt.multiline = true; my_txt.wordWrap = true; my_txt.border = true; my_txt.
TextFormat.font Availability Flash Player 6. Usage my_fmt.font:String Description Property; the name of the font for text in this text format, as a string. The default value is null, which indicates that the property is undefined. Example The following example creates a text field and sets the font to Courier. this.createTextField("mytext",1,100,100,100,100); mytext.multiline = true; mytext.wordWrap = true; mytext.border = true; var myformat:TextFormat = new TextFormat(); myformat.
TextFormat.getTextExtent() Availability Flash Player 6. The optional width parameter is supported in Flash Player 7. Usage my_fmt.getTextExtent(text:String, [width:Number]) : Object Parameters text A string. An optional number that represents the width, in pixels, at which the specified text should wrap. width Returns An object with the properties width, height, ascent, descent, textFieldHeight, textFieldWidth.
The following figure illustrates these measurements. When setting up your TextFormat object, set all the attributes exactly as they will be set for the creation of the text field, including font name, font size, and leading. The default value for leading is 2. Example This example creates a single-line text field that’s just big enough to display a text string using the specified formatting. var my_str:String = "Small string"; // Create a TextFormat object, // and apply its properties.
// Create a TextFormat object. var my_fmt:TextFormat = new TextFormat(); // Specify formatting properties for the TextFormat object: my_fmt.font = "Arial"; my_fmt.bold = true; my_fmt.leading = 4; // The string of text to be displayed var textToDisplay:String = "Macromedia Flash Player 7, now with improved text metrics."; // Obtain text measurement information for the string, // wrapped at 100 pixels. var metrics:Object = my_fmt.
TextFormat.indent Availability Flash Player 6. Usage my_fmt.indent:Number Description Property; an integer that indicates the indentation from the left margin to the first character in the paragraph. The default value is null, which indicates that the property is undefined. Example The following example creates a text field and sets the indentation to 10. this.createTextField("mytext",1,100,100,100,100); mytext.multiline = true; mytext.wordWrap = true; mytext.
TextFormat.italic Availability Flash Player 6. Usage my_fmt.italic:Boolean Description Property; a Boolean value that indicates whether text in this text format is italicized. The default value is null, which indicates that the property is undefined. Example The following example creates a text field and sets the text style to italic. this.createTextField("mytext",1,100,100,100,100); mytext.multiline = true; mytext.wordWrap = true; mytext.
TextFormat.leading Availability Flash Player 6. Usage my_fmt.leading:Number Description Property; the amount of vertical space (called leading) between lines. The default value is null, which indicates that the property is undefined. Example The following example creates a text field and sets the leading to 10. var my_fmt:TextFormat = new TextFormat(); my_fmt.leading = 10; this.createTextField("my_txt", 1, 100, 100, 100, 100); my_txt.multiline = true; my_txt.wordWrap = true; my_txt.border = true; my_txt.
TextFormat.leftMargin Availability Flash Player 6. Usage my_fmt.leftMargin:Number Description Property; the left margin of the paragraph, in points. The default value is null, which indicates that the property is undefined. Example The following example creates a text field and sets the left margin to 20 points. this.createTextField("mytext",1,100,100,100,100); mytext.multiline = true; mytext.wordWrap = true; mytext.border = true; var myformat:TextFormat = new TextFormat(); myformat.
TextFormat.rightMargin Availability Flash Player 6. Usage my_fmt.rightMargin:Number Description Property; the right margin of the paragraph, in points. The default value is null, which indicates that the property is undefined. Example The following example creates a text field and sets the right margin to 20 points. this.createTextField("mytext",1,100,100,100,100); mytext.multiline = true; mytext.wordWrap = true; mytext.border = true; var myformat:TextFormat = new TextFormat(); myformat.
TextFormat.size Availability Flash Player 6. Usage my_fmt.size:Number Description Property; the point size of text in this text format. The default value is null, which indicates that the property is undefined. Example The following example creates a text field and sets the text size to 20 points. this.createTextField("mytext",1,100,100,100,100); mytext.multiline = true; mytext.wordWrap = true; mytext.border = true; var myformat:TextFormat = new TextFormat(); myformat.size = 20; mytext.
TextFormat.tabStops Availability Flash Player 6. Usage my_fmt.tabStops:Array Description Property; specifies custom tab stops as an array of non-negative integers. Each tab stop is specified in pixels. If custom tab stops are not specified (null), the default tab stop is 4 (average character width). Example The following example creates two text fields, one with tab stops every 20 pixels, and the other with tab stops every 40 pixels. this.createTextField("mytext",1,100,100,200,100); mytext.
TextFormat.target Availability Flash Player 6. Usage my_fmt.target:String Description Property; indicates the target window where the hyperlink is displayed. If the target window is an empty string, the text is displayed in the default target window _self.
TextFormat.underline Availability Flash Player 6. Usage my_fmt.underline:Boolean Description Property; a Boolean value that indicates whether the text that uses this text format is underlined (true) or not (false). This underlining is similar to that produced by the tag, but the latter is not “true” underlining, because it does not skip descenders correctly. The default value is null, which indicates that the property is undefined.
TextFormat.url Availability Flash Player 6. Usage my_fmt.url:String Description Property; indicates the URL that text in this text format hyperlinks to. If the url property is an empty string, the text does not have a hyperlink. The default value is null, which indicates that the property is undefined. Example This example creates a text field that is a hyperlink to the Macromedia website. var myformat:TextFormat = new TextFormat(); myformat.url = "http://www.macromedia.com"; this.
TextSnapshot object CHAPTER 2 ActionScript Language Reference Availability Authoring: Flash MX 2004. Playback: SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later. Description TextSnapshot objects let you work with static text in a movie clip. You can use them, for example, to lay out text with greater precision than that allowed by dynamic text, but still access the text in a read-only way.
TextSnapshot.findText() Availability Authoring: Flash MX 2004. Playback: SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later. Usage my_snap.findText( startIndex:Number, textToFind:String, caseSensitive:Boolean ) : Number Parameters startIndex An integer specifying the starting point in my_snap to search for the specified text. textToFind A string specifying the text to search for.
TextSnapshot.getCount() Availability Authoring: Flash MX 2004. Playback: SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later. Usage my_snap.getCount() : Number Parameters None. Returns An integer representing the number of characters in the specified TextSnapshot object. Description Method; returns the number of characters in a TextSnapshot object. Example The following example illustrates how you can output the number of characters in a specified TextSnapshot object.
TextSnapshot.getSelected() Availability Authoring: Flash MX 2004. Playback: SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later. Usage my_snap.getSelected(from:Number, to:Number) : Boolean Parameters An integer that indicates the position of the first character of my_snap to be examined. Valid values for from are 0 through TextSnapshot.getCount() - 1. If from is a negative value, 0 is used.
TextSnapshot.getSelectedText() Availability Authoring: Flash MX 2004. Playback: SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later. Usage my_snap.getSelectedText( [ includeLineEndings:Boolean ] ) : String Parameters An optional Boolean value that specifies whether newline characters are inserted into the returned string where appropriate. The default value is false.
When you test the SWF file, you see a colored rectangle around the specified characters. See also TextSnapshot.getSelected() TextSnapshot.
TextSnapshot.getText() Availability Authoring: Flash MX 2004. Playback: SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later. Usage my_snap.getText(from:Number, to:Number [, includeLineEndings:Boolean ] ) : String Parameters An integer that indicates the position of the first character of my_snap to be included in the returned string. Valid values for from are 0 through TextSnapshot.getCount() - 1. If from is a negative value, 0 is used.
trace(count); // output: 20 trace(theText); // output: TextSnapshot Example See also TextSnapshot.getSelectedText() TextSnapshot.
TextSnapshot.hitTestTextNearPos() Availability Authoring: Flash MX 2004. Playback: SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later. Usage my_snap.hitTestTextNearPos(x:Number, y:Number [, maxDistance:Number] ) : Number Parameters x A number that represents the x coordinate of the movie clip containing the text in my_snap. y A number that represents the x coordinate of the movie clip containing the text in my_snap.
var my_mc:MovieClip = this; var my_ts:TextSnapshot = my_mc.getTextSnapshot(); my_mc.onMouseMove = function() { // find which character the mouse pointer is over (if any) var hitIndex:Number = my_ts.hitTestTextNearPos(_xmouse, _ymouse, 0); // deselect everything my_ts.setSelected(0, my_ts.getCount(), false); if (hitIndex>=0) { // select the single character the mouse pointer is over my_ts.setSelected(hitIndex, hitIndex+1, true); } }; See also MovieClip.getTextSnapshot(), MovieClip._x, MovieClip.
TextSnapshot.setSelectColor() Availability Authoring: Flash MX 2004. Playback: SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later. Usage my_snap.setSelectColor(hexColor:Number); Parameters The color used for the border placed around characters that have been selected by the corresponding TextSnapshot.setSelected() command, expressed in 0xRRGGBB format. hexColor Returns Nothing.
trace(theText); // output: Txt trace(firstCharIsSelected); // output: true trace(secondCharIsSelected); // output: false When you test the SWF file, you see a colored rectangle around the specified characters. TextSnapshot.
TextSnapshot.setSelected() Availability Authoring: Flash MX 2004. Playback: SWF files published for Flash Player 6 or later, playing in Flash Player 7 or later. Usage my_snap.setSelected(from:Number, to:Number, select:Boolean) : Void Parameters An integer that indicates the position of the first character of my_snap to select. Valid values for from are 0 through TextSnapshot.getCount() - 1. If from is a negative value, 0 is used.
Note: If characters don’t appear to be selected when you run the code, you must also place a dynamic text field on the Stage. See “Description” in this entry. // This example assumes that the movie clip contains // the static text "TextSnapshot Example" var my_snap:TextSnapshot = this.getTextSnapshot(); var count:Number = my_snap.getCount(); my_snap.setSelectColor(0xFF0000); // Set the selection color to red. my_snap.setSelected(0, 4, true); // Select the first four characters. my_snap.
CHAPTER 2 ActionScript Language Reference this Availability Flash Player 5. Usage this Description Identifier; references an object or movie clip instance. When a script executes, this references the movie clip instance that contains the script. When a method is called, this contains a reference to the object that contains the called method. Inside an on() event handler attached to a button, this refers to the Timeline that contains the button.
} } Inside the FLA or AS file, add the following ActionScript: var obj:Simple = new Simple(); obj.num = 0; obj.func = function() { return true; }; obj.callfunc(); // output: true You get a syntax error when you use the incorrect version of Simple.as. Example In the following example, the keyword this references the Circle object: function Circle(radius:Number):Void { this.radius = radius; this.area = Math.PI*Math.pow(radius, 2); } var myCircle = new Circle(4); trace(myCircle.
CHAPTER 2 ActionScript Language Reference throw Availability Flash Player 7. Usage throw expression Description Statement; generates, or throws, an error that can be handled, or caught, by a catch{} code block. If an exception is not caught by a catch block, the string representation of the thrown value is sent to the Output panel. Typically, you throw instances of the Error class or its subclasses (see the Example section). Parameters expression An ActionScript expression or object.
if (email.indexOf("@") == -1) { throw new InvalidEmailAddress(); } } try { checkEmail("Joe Smith"); } catch (e) { this.createTextField("error_txt", this.getNextHighestDepth(), 0, 0, 100, 22); error_txt.autoSize = true; error_txt.text = e.toString(); } See also Error class, try..catch..
trace() CHAPTER 2 ActionScript Language Reference Availability Flash Player 4. Usage trace(expression) Parameters expression An expression to evaluate. When a SWF file is opened in the Flash authoring tool (using the Test Movie command), the value of the expression parameter is displayed in the Output panel. Returns Nothing. Description Statement; evaluates the expression and displays the result in the Output panel in test mode.
true CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage true Description Constant; a unique Boolean value that represents the opposite of false. When automatic data typing converts true to a number, it becomes 1; when it converts true to a string, it becomes "true". Example The following example shows the use of true in an if statement: var shouldExecute:Boolean; /* ...
try..catch..finally CHAPTER 2 ActionScript Language Reference Availability Flash Player 7. Usage try { // ... try block ... } finally { // ... finally block ... } try { // ... try block ... } catch(error[:ErrorType1]) { // ... catch block ... } [catch(error[:ErrorTypeN]) { // ... catch block ... }] [finally { // ... finally block ... }] Parameters The expression thrown from a throw statement, typically an instance of the Error class or one of its subclasses.
If an error is thrown within a function, and the function does not include a catch handler, then the ActionScript interpreter exits that function, as well as any caller functions, until a catch block is found. During this process, finally handlers are called at all levels. Example The following example shows how to create a try..finally statement. Because code in the finally block is guaranteed to execute, it is typically used to perform any necessary clean-up after a try block executes.
The following example demonstrates a try..catch statement. The code within the try block is executed. If an exception is thrown by any code within the try block, control passes to the catch block, which shows the error message in a text field using the Error.toString() method. In the same directory as Account.as, create a new FLA document and enter the following ActionScript in Frame 1 of the Timeline: import Account; var account:Account = new Account(); try { var returnVal = account.
} } Finally, in another AS file or FLA script, the following code invokes the sortRows() method on an instance of the RecordSet class. It defines catch blocks for each type of error that is thrown by sortRows(). import RecordSet; var myRecordSet:RecordSet = new RecordSet(); try { myRecordSet.sortRows(); trace("everything is fine"); } catch (e:RecordSetException) { trace(e.toString()); } catch (e:MalformedRecord) { trace(e.toString()); } See also Error class, throw, class, extends try..catch..
CHAPTER 2 ActionScript Language Reference typeof Availability Flash Player 5. Usage typeof(expression) : String Parameters expression A string, movie clip, button, object, or function. Description Operator; a unary operator placed before a single parameter. The typeof operator causes the Flash interpreter to evaluate expression; the result is a string specifying whether the expression is a string, movie clip, object, function, number, or Boolean value.
undefined CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage undefined Parameters None. Returns Nothing. Description A special value, usually used to indicate that a variable has not yet been assigned a value. A reference to an undefined value returns the special value undefined. The ActionScript code typeof(undefined) returns the string "undefined". The only value of type undefined is undefined. In files published for Flash Player 6 or earlier, the value of undefined.
The following result is displayed in the Output panel.
unescape() CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage unescape(x:String) : String Parameters x A string with hexadecimal sequences to escape. Returns A string decoded from a URL-encoded parameter. Description Function; evaluates the parameter x as a string, decodes the string from URL-encoded format (converting all hexadecimal sequences to ASCII characters), and returns the string.
unloadMovie() CHAPTER 2 ActionScript Language Reference Availability Flash Player 3. Usage unloadMovie(target:MovieClip) : Void unloadMovie(target:String) : Void Parameters target The target path of a movie clip. Returns None. Description Function; removes a movie clip that was loaded by means of loadMovie() from Flash Player. To unload a movie clip that was loaded by means of loadMovieNum(), use unloadMovieNum() instead of unloadMovie().
unloadMovieNum() CHAPTER 2 ActionScript Language Reference Availability Flash Player 3. Usage unloadMovieNum(level:Number) : Void Parameters level The level (_levelN) of a loaded movie. Returns Nothing. Description Function; removes a SWF or image that was loaded by means of loadMovieNum() from Flash Player. To unload a SWF or image that was loaded with MovieClip.loadMovie(), use unloadMovie() instead of unloadMovieNum(). Example The following example loads an image into a SWF file.
updateAfterEvent() CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Usage updateAfterEvent() : Void Parameters None. Returns Nothing. Description Function; updates the display (independent of the frames per second set for the movie) when you call it within an onClipEvent() handler or as part of a function or method that you pass to setInterval().
CHAPTER 2 ActionScript Language Reference var Availability Flash Player 5. Usage var variableName [= value1] [...,variableNameN [=valueN]] Parameters variableName value An identifier. The value assigned to the variable. Returns Nothing. Description Statement; used to declare local or Timeline variables. If you declare variables inside a function, the variables are local. They are defined for the function and expire at the end of the function call.
CHAPTER 2 ActionScript Language Reference Video class Availability Flash Player 6; the ability to play Flash Video (FLV) files was added in Flash Player 7. Description The Video class lets you display live streaming video on the Stage without embedding it in your SWF file. You capture the video by using Camera.get(). In files published for Flash Player 7 and later, you can also use the Video class to play back Flash Video (FLV) files over HTTP or from the local file system.
Video.attachVideo() Availability Flash Player 6; the ability to work with Flash Video (FLV) files was added in Flash Player 7. Usage my_video.attachVideo(source:Object) : Void Parameters A Camera object that is capturing video data or a NetStream object. To drop the connection to the Video object, pass null for source. source Returns Nothing. Description Method; specifies a video stream (source) to be displayed within the boundaries of the Video object on the Stage.
Video.clear() Availability Flash Player 6. Usage my_video.clear() : Void Parameters None. Returns Nothing. Description Method; clears the image currently displayed in the Video object. This is useful when, for example, you want to display standby information without having to hide the Video object. Example The following example pauses and clears video1.flv that is playing in a Video object (called my_video) when the user clicks the pause_btn instance.
Video.deblocking Availability Flash Player 6. Usage my_video.deblocking:Number Description Property; a number that specifies the behavior for the deblocking filter that the video compressor applies as needed when streaming the video. The following are acceptable values: • 0 (the default): Let the video compressor apply the deblocking filter as needed. • 1: Never use the deblocking filter. • 2: Always use the deblocking filter.
Video.height Availability Flash Player 6. Usage my_video.height:Number Description Property (read-only); an integer specifying the height of the video stream, in pixels. For live streams, this value is the same as the Camera.height property of the Camera object that is capturing the video stream. For FLV files, this value is the height of the file that was exported as FLV.
my_mc._height = my_mc.my_video.height; }; See also MovieClip._height, Video.width Video.
Video.smoothing Availability Flash Player 6. Usage my_video.smoothing:Boolean Description Property; a Boolean value that specifies whether the video should be smoothed (interpolated) when it is scaled. For smoothing to work, the player must be in high-quality mode. The default value is false (no smoothing). Example The following example uses a button (called smoothing_btn) to toggle the smoothing property that is applied to the video my_video when it plays in a SWF file.
Video.width Availability Flash Player 6. Usage my_video.width:Number Description Property (read-only); an integer specifying the width of the video stream, in pixels. For live streams, this value is the same as the Camera.width property of the Camera object that is capturing the video stream. For FLV files, this value is the width of the file that was exported as an FLV file.
CHAPTER 2 ActionScript Language Reference void Availability Flash Player 5. Usage void (expression) function functionName():Void {} Description Usage 1: Operator; a unary operator that discards the expression value and returns an undefined value. The void operator is often used in comparisons using the equality (==) operator to test for undefined values. Usage 2: Data type; used in function definitions to indicate that a function will not return a value.
CHAPTER 2 ActionScript Language Reference while Availability Flash Player 4. Usage while(condition) { statement(s); } Parameters condition An expression that evaluates to true or false. statement(s) The instructions to execute if the condition evaluates to true. Returns Nothing. Description Statement; evaluates a condition and if the condition evaluates to true, runs a statement or series of statements before looping back to evaluate the condition again.
i += 3; } The following result is displayed in the Output panel. 0 3 6 9 12 15 18 See also do while, continue, for, for..
CHAPTER 2 ActionScript Language Reference with Availability Flash Player 5. Usage with (object:Object) { statement(s); } Parameters object An instance of an ActionScript object or movie clip. statement(s) An action or group of actions enclosed in curly braces ({}). Returns Nothing. Description Statement; lets you specify an object (such as a movie clip) with the object parameter and evaluate expressions and actions inside that object with the statement(s) parameter.
Instead of using with(), you can use direct paths. If you find that paths are long and cumbersome to type, you can create a local variable and store the path in the variable, which you can then reuse in your code, as shown in the following ActionScript: var shortcut = this._parent._parent.name_txt; shortcut.text = "Hank"; shortcut.
CHAPTER 2 ActionScript Language Reference XML class Availability Flash Player 5 (became a native object in Flash Player 6, which improved performance significantly). Description Use the methods and properties of the XML class to load, parse, send, build, and manipulate XML document trees. You must use the constructor new XML() to create an XML object before calling any method of the XML class. An XML document is represented in Flash by the XML class.
Property summary for the XML class Property Description XML.contentType The MIME type transmitted to the server. XML.docTypeDecl Sets and returns information about an XML document’s DOCTYPE declaration. XML.firstChild Read-only; references the first child in the list for the specified node. XML.ignoreWhite When set to true, discards, during the parsing process, text nodes that contain only white space. XML.lastChild Read-only; references the last child in the list for the specified node. XML.
Constructor for the XML class Availability Flash Player 5. Usage new XML([source:String]) : XML Parameters source A string; the XML text parsed to create the new XML object. Returns A reference to an XML object. Description Constructor; creates a new XML object. You must use the constructor to create an XML object before you call any of the methods of the XML class. Note: Use the createElement() and createTextNode() methods to add elements and text nodes to an XML document tree.
XML.addRequestHeader() Availability Flash Player 6. Usage my_xml.addRequestHeader(headerName:String, headerValue:String) : Void my_xml.addRequestHeader(["headerName_1":String, "headerValue_1":String ... "headerName_n":String, "headerValue_n":String]) : Void Parameters headerName headerValue A string that represents an HTTP request header name. A string that represents the value associated with headerName. Returns Nothing.
XML.appendChild() Availability Flash Player 5. Usage my_xml.appendChild(childNode:XMLNode) : Void Parameters An XMLNode that represents the node to be moved from its current location to the child list of the my_xml object. childNode Returns Nothing. Description Method; appends the specified node to the XML object’s child list. This method operates directly on the node referenced by the childNode parameter; it does not append a copy of the node.
var clone:XMLNode = doc2.firstChild.cloneNode(true); doc1.appendChild(clone); trace ("doc1: " + doc1); // output: doc1: trace ("doc2: " + doc2); // output: doc2: // create a new node to append to root node (named clone) of doc1 var newNode:XMLNode = doc1.createElement("newbie"); clone.
XML.attributes Availability Flash Player 5. Usage my_xml.attributes:Array Description Property; an associative array that contains all the attributes of the specified XML object. Associative arrays use keys as indexes, instead of the simple ordinal integer indexes used by regular arrays. In the XML.attributes associative array, the key index is a string representing the name of the attribute. The value associated with that key index is the string value associated with that attribute.
XML.childNodes Availability Flash Player 5. Usage my_xml.childNodes:Array Description Read-only property; an array of the specified XML object’s children. Each element in the array is a reference to an XML object that represents a child node. This is a read-only property and cannot be used to manipulate child nodes. Use the XML.appendChild(), XML.insertBefore(), and XML.removeNode() methods to manipulate child nodes. This property is undefined for text nodes (nodeType == 3).
XML.cloneNode() Availability Flash Player 5. Usage my_xml.cloneNode(deep:Boolean) : XMLNode Parameters A Boolean value; if set to true, the children of the specified XML object will be recursively cloned. deep Returns An XMLNode object. Description Method; constructs and returns a new XML node of the same type, name, value, and attributes as the specified XML object. If deep is set to true, all child nodes are recursively cloned, resulting in an exact copy of the original object’s document tree.
// insert the clone node into rootNode between the middle and youngest nodes rootNode.insertBefore(middle2, youngest); trace(rootNode); // output (with line breaks added): // // // // // // // create a copy of rootNode using cloneNode() to demonstrate a deep copy var rootClone:XMLNode = rootNode.cloneNode(true); // insert the clone, which contains all child nodes, rootNode.
XML.contentType Availability Flash Player 6. Usage my_xml.contentType:String Description Property; the MIME content type that is sent to the server when you call the XML.send() or XML.sendAndLoad() method. The default is application/x-www-form-urlencoded, which is the standard MIME content type used for most HTML forms.
XML.createElement() Availability Flash Player 5. Usage my_xml.createElement(name:String) : XMLNode Parameters name The tag name of the XML element being created. Returns An XMLNode; an XML element. Description Method; creates a new XML element with the name specified in the parameter. The new element initially has no parent, no children, and no siblings. The method returns a reference to the newly created XML object that represents the element. This method and the XML.
XML.createTextNode() Availability Flash Player 5. Usage my_xml.createTextNode(text:String) : XMLNode Parameters text A string; the text used to create the new text node. Returns An XMLNode. Description Method; creates a new XML text node with the specified text. The new node initially has no parent, and text nodes cannot have children or siblings. This method returns a reference to the XML object that represents the new text node. This method and the XML.
See also XML.
XML.docTypeDecl Availability Flash Player 5. Usage my_xml.docTypeDecl:String Description Property; specifies information about the XML document’s DOCTYPE declaration. After the XML text has been parsed into an XML object, the XML.docTypeDecl property of the XML object is set to the text of the XML document’s DOCTYPE declaration (for example, ). This property is set using a string representation of the DOCTYPE declaration, not an XML node object.
XML.firstChild Availability Flash Player 5. Usage my_xml.firstChild:XMLNode Description Read-only property; evaluates the specified XML object and references the first child in the parent node’s child list. This property is null if the node does not have children. This property is undefined if the node is a text node. This is a read-only property and cannot be used to manipulate child nodes; use the appendChild(), insertBefore(), and removeNode() methods to manipulate child nodes.
for (var stringNode:XMLNode = childNode.firstChild; stringNode != null; stringNode = stringNode.nextSibling, j++) { masterArray[i][j] = stringNode.firstChild.nodeValue; } To view the entire script, see XML_languagePicker.fla in the HelpExamples folder: • Windows: \Program Files\Macromedia\Flash MX 2004\Samples\HelpExamples\ • Macintosh: HD/Applications/Macromedia Flash MX 2004/Samples/HelpExamples/ See also XML.appendChild(), XML.insertBefore(), XML.removeNode() XML.
XML.getBytesLoaded() Availability Flash Player 6. Usage my_xml.getBytesLoaded() : Number Parameters None. Returns An integer that indicates the number of bytes loaded. Description Method; returns the number of bytes loaded (streamed) for the XML document. You can compare the value of getBytesLoaded() with the value of getBytesTotal() to determine what percentage of an XML document has loaded. Example The following example shows how to use the XML.getBytesLoaded() method with the XML.
XML.getBytesTotal() Availability Flash Player 6. Usage my_xml.getBytesTotal() : Number Parameters None. Returns An integer. Description Method; returns the size, in bytes, of the XML document. Example See example for XML.getBytesLoaded(). See also XML.getBytesLoaded() XML.
XML.hasChildNodes() Availability Flash Player 5. Usage my_xml.hasChildNodes() : Boolean Parameters None. Returns A Boolean value. Description Method; returns true if the specified XML object has child nodes; otherwise, returns false. Example The following example creates a new XML packet. If the root node has child nodes, the code loops over each child node to display the name and value of the node.
XML.ignoreWhite Availability Flash Player 5. Usage my_xml.ignoreWhite:boolean XML.prototype.ignoreWhite:boolean Parameters boolean A Boolean (true or false) value. Description Property; default setting is false. When set to true, text nodes that contain only white space are discarded during the parsing process. Text nodes with leading or trailing white space are unaffected. Usage 1: You can set the ignoreWhite property for individual XML objects, as the following code shows: my_xml.
/* output (line breaks added for clarity): ceramic tile linoleum */ If you then change the setting of flooring.ignoreWhite to false, or simply remove that line of code entirely, the fourteen space characters in the foyer tag will be preserved: ... // set the ignoreWhite property to false (default value) flooring.ignoreWhite = false; ...
XML.insertBefore() Availability Flash Player 5. Usage my_xml.insertBefore(childNode:XMLNode, beforeNode:XMLNode) : Void Parameters childNode beforeNode The XMLNode object to be inserted. The XMLNode object before the insertion point for the childNode. Returns Nothing. Description Method; inserts a new child node into the XML object’s child list, before the beforeNode node. If the beforeNode parameter is undefined or null, the node is added using the appendChild() method.
XML.lastChild Availability Flash Player 5. Usage my_xml.lastChild:XMLNode Description Read-only property; an XMLNode value that references the last child in the node’s child list. The XML.lastChild property is null if the node does not have children. This property cannot be used to manipulate child nodes; use the appendChild(), insertBefore(), and removeNode() methods to manipulate child nodes. Example The following example uses the XML.
The following example creates a new XML packet and uses the XML.lastChild property to iterate through the child nodes of the root node: // create a new XML document var doc:XML = new XML(""); var rootNode:XMLNode = doc.firstChild; // use lastChild to iterate through the child nodes of rootNode for (var aNode:XMLNode = rootNode.lastChild; aNode != null; aNode=aNode.
XML.load() Availability Flash Player 5; behavior changed in Flash Player 7. Usage my_xml.load(url:String) : Void Parameters A string that represents the URL where the XML document to be loaded is located. If the SWF file that issues this call is running in a web browser, url must be in the same domain as the SWF file; for details, see the Description section. url Returns Nothing.
flooring.ignoreWhite = true; // After loading is complete, trace the XML object flooring.onLoad = function(success) { trace(flooring); }; // load the XML into the flooring object flooring.load("flooring.xml"); For the contents of the flooring.xml file, and the output that this example produces, see the example for XML.ignoreWhite. See also XML.loaded, XML.onLoad XML.
XML.loaded Availability Flash Player 5. Usage my_xml.loaded:Boolean Description Read-only property; a Boolean value that is true if the document-loading process initiated by the XML.load() call has completed successfully; otherwise, it is false. Example The following example uses the XML.loaded property in a simple script: var my_xml:XML = new XML(); my_xml.ignoreWhite = true; my_xml.onLoad = function(success:Boolean) { trace("success: "+success); trace("loaded: "+my_xml.loaded); trace("status: "+my_xml.
XML.nextSibling Availability Flash Player 5. Usage my_xml.nextSibling:XMLNode Description Read-only property; an XMLNode value that references the next sibling in the parent node’s child list. This property is null if the node does not have a next sibling node. This property cannot be used to manipulate child nodes; use the appendChild(), insertBefore(), and removeNode() methods to manipulate child nodes. Example The following example is an excerpt from the example for the XML.
XML.nodeName Availability Flash Player 5. Usage my_xml.nodeName:String Description Property; a string representing the node name of the XML object. If the XML object is an XML element (nodeType == 1), nodeName is the name of the tag that represents the node in the XML file. For example, TITLE is the nodeName of an HTML TITLE tag. If the XML object is a text node (nodeType == 3), nodeName is null.
trace(aNode.nodeName+":\t"+aNode.firstChild.nodeValue); } } } The following node names are displayed in the Output panel: output: username:hank password:rudolph See also XML.nodeType XML.
XML.nodeType Availability Flash Player 5. Usage my_xml.nodeType:Number Description Read-only property; a nodeType value, either 1 for an XML element or 3 for a text node. The nodeType is a numeric value from the NodeType enumeration in the W3C DOM Level 1 recommendation: www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html.
var myTextNode:XMLNode = doc.createTextNode("textNode"); // place the new node into the XML tree myNode.appendChild(myTextNode); trace(myNode.nodeType); trace(myTextNode.nodeType); /* output: 1 3 */ See also XML.nodeValue XML.
XML.nodeValue Availability Flash Player 5. Usage my_xml.nodeValue:Node Description Property; the node value of the XML object. If the XML object is a text node, the nodeType is 3, and the nodeValue is the text of the node. If the XML object is an XML element (nodeType is 1), nodeValue is null and read-only.
trace("using firstChild.nodeValue:"); for (var i = 0; i
XML.onData Availability Flash Player 5. Usage my_xml.onData = function(src:String) { // your statements here } Parameters src A string or undefined; the raw data, usually in XML format, that is sent by the server. Returns Nothing. Description Event handler; invoked when XML text has been completely downloaded from the server, or when an error occurs downloading XML text from a server.
XML.onLoad Availability Flash Player 5. Usage my_xml.onLoad = function (success:Boolean) { //your statements here } Parameters success A Boolean value that evaluates to true if the XML object is successfully loaded with a XML.load() or XML.sendAndLoad() operation; otherwise, it is false. Returns Nothing. Description Event handler; invoked by Flash Player when an XML document is received from the server. If the XML document is received successfully, the success parameter is true.
XML.parentNode Availability Flash Player 5. Usage my_xml.parentNode:XMLNode Description Read-only property; an XMLNode value that references the parent node of the specified XML object, or returns null if the node has no parent. This is a read-only property and cannot be used to manipulate child nodes; use the appendChild(), insertBefore(), and removeNode() methods to manipulate child nodes.
XML.parseXML() Availability Flash Player 5. Usage my_xml.parseXML(source:String) : Void Parameters source A string that represents the XML text to be parsed and passed to the specified XML object. Returns Nothing. Description Method; parses the XML text specified in the source parameter, and populates the specified XML object with the resulting XML tree. Any existing trees in the XML object are discarded.
XML.previousSibling Availability Flash Player 5. Usage my_xml.previousSibling:XMLNode Description Read-only property; an XMLNode value that references the previous sibling in the parent node’s child list. The property has a value of null if the node does not have a previous sibling node. This property cannot be used to manipulate child nodes; use the XML.appendChild(), XML.insertBefore(), and XML.removeNode() methods to manipulate child nodes.
XML.removeNode() Availability Flash Player 5. Usage my_xml.removeNode() : Void Parameters None. Returns Nothing. Description Method; removes the specified XML object from its parent. Also deletes all descendants of the node. Example The following example creates an XML packet, and then deletes the specified XML object and its descendant nodes: var xml_str:String = " San Francisco"; var my_xml:XML = new XML(xml_str); var cityNode:XMLNode = my_xml.
XML.send() Availability Flash Player 5. Usage my_xml.send(url:String, [window:String]) : Void Parameters url String; the destination URL for the specified XML object. window String; the browser window to show data that the server returns: • • • • specifies the current frame in the current window. _self _blank specifies a new window. _parent _top specifies the parent of the current frame. specifies the top-level frame in the current window.
XML.sendAndLoad() Availability Flash Player 5; behavior changed in Flash Player 7. Usage my_xml.sendAndLoad(url:String, targetXMLobject:XML) : Void Parameters url A string; the destination URL for the specified XML object. If the SWF file issuing this call is running in a web browser, url must be in the same domain as the SWF file; for details, see the Description section. targetXMLobject An XML object created with the XML constructor method that will receive the return information from the server.
var login_str:String = ""; var my_xml:XML = new XML(login_str); var myLoginReply_xml:XML = new XML(); myLoginReply_xml.ignoreWhite = true; myLoginReply_xml.onLoad = myOnLoad; my_xml.sendAndLoad("http://www.flash-mx.com/mm/login_xml.cfm", myLoginReply_xml); function myOnLoad(success:Boolean) { if (success) { if ((myLoginReply_xml.firstChild.nodeName == "packet") && (myLoginReply_xml.firstChild.attributes.
XML.status Availability Flash Player 5. Usage my_xml.status:Number Description Property; automatically sets and returns a numeric value that indicates whether an XML document was successfully parsed into an XML object. The following are the numeric status codes, with descriptions: • • • • • • • • • • 0 No error; parse was completed successfully. -2 A CDATA section was not properly terminated. -3 The XML declaration was not properly terminated. -4 The DOCTYPE declaration was not properly terminated.
case -4 : errorMessage = "The DOCTYPE declaration was not properly terminated."; break; case -5 : errorMessage = "A comment was not properly terminated."; break; case -6 : errorMessage = "An XML element was malformed."; break; case -7 : errorMessage = "Out of memory."; break; case -8 : errorMessage = "An attribute value was not properly terminated."; break; case -9 : errorMessage = "A start-tag was not matched with an end-tag.
XML.toString() Availability Flash Player 5. Usage my_xml.toString() : String Parameters None. Returns A string. Description Method; evaluates the specified XML object, constructs a textual representation of the XML structure, including the node, children, and attributes, and returns the result as a string. For top-level XML objects (those created with the constructor), the XML.toString() method outputs the document’s XML declaration (stored in the XML.
XML.xmlDecl Availability Flash Player 5. Usage my_xml.xmlDecl:String Description Property; a string that specifies information about a document’s XML declaration. After the XML document is parsed into an XML object, this property is set to the text of the document’s XML declaration. This property is set using a string representation of the XML declaration, not an XML node object. If no XML declaration is encountered during a parse operation, the property is set to undefined.XML. The XML.
See also XML.docTypeDecl, XML.toString() XML.
XMLNode class CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Description An XML document is represented in Flash by the XML class. Each element of the hierarchical document is represented by an XMLNode object. The XMLNode class supports the following properties, methods, and collections; for information on their usage, see the corresponding XML class entries. Property, method, or collection Corresponding XML class entry appendChild() XML.appendChild() attributes XML.
XMLSocket class CHAPTER 2 ActionScript Language Reference Availability Flash Player 5. Description The XMLSocket class implements client sockets that let the computer running Flash Player communicate with a server computer identified by an IP address or domain name. The XMLSocket class is useful for client-server applications that require low latency, such as real-time chat systems. A traditional HTTP-based chat solution frequently polls the server and downloads new messages using an HTTP request.
Method summary for the XMLSocket class Method Description XMLSocket.close() Closes an open socket connection. XMLSocket.connect() Establishes a connection to the specified server. XMLSocket.send() Sends an XML object to the server. Event handler summary for the XMLSocket class Event handler Description XMLSocket.onClose Invoked when an XMLSocket connection is closed. XMLSocket.onConnect Invoked by Flash Player when a connection request initiated through XMLSocket.
XMLSocket.close() Availability Flash Player 5. Usage myXMLSocket.close() : Void Parameters None. Returns Nothing. Description Method; closes the connection specified by XMLSocket object. Example The following simple example creates an XMLSocket object, attempts to connect to the server, and then closes the connection. var socket:XMLSocket = new XMLSocket(); socket.connect(null, 2000); socket.close(); See also XMLSocket.connect() XMLSocket.
XMLSocket.connect() Availability Flash Player 5; behavior changed in Flash Player 7. Usage myXMLSocket.connect(host:String, port:Number) : Boolean Parameters host String; a fully qualified DNS domain name or an IP address in the form aaa.bbb.ccc.ddd. You can also specify null to connect to the host server on which the SWF file resides. If the SWF file issuing this call is running in a web browser, host must be in the same domain as the SWF file; for details, see “Description”.
If XMLSocket.connect() returns a value of true, the initial stage of the connection process is successful; later, the XMLSocket.onConnect method is invoked to determine whether the final connection succeeded or failed. If XMLSocket.connect() returns false, a connection could not be established. Example The following example uses XMLSocket.
XMLSocket.onClose Availability Flash Player 5. Usage myXMLSocket.onClose = function() { // your statements here } Parameters None. Returns Nothing. Description Event handler; invoked only when an open connection is closed by the server. The default implementation of this method performs no actions. To override the default implementation, you must assign a function containing custom actions.
XMLSocket.onConnect Availability Flash Player 5. Usage myXMLSocket.onConnect = function(success:Boolean) { // your statements here } Parameters A Boolean value indicating whether a socket connection is successfully established (true or false). success Returns Nothing. Description Event handler; invoked by Flash Player when a connection request initiated through XMLSocket.connect() has succeeded or failed.
if (!socket.connect(null, 2000)) { gotoAndStop("connectionFailed"); } else { gotoAndStop("waitForConnection"); } See also function, XMLSocket.
XMLSocket.onData Availability Flash Player 5. Usage XMLSocket.onData = function(src:String) { // your statements here } Parameters src A string containing the data sent by the server. Returns Nothing. Description Event handler; invoked when a message has been downloaded from the server, terminated by a zero (0) byte. You can override XMLSocket.onData to intercept the data sent by the server without parsing it as XML.
XMLSocket.onXML Availability Flash Player 5. Usage myXMLSocket.onXML = function(object:XML) { // your statements here } Parameter object An XML object that contains a parsed XML document received from a server. Returns Nothing. Description Event handler; invoked by Flash Player when the specified XML object containing an XML document arrives over an open XMLSocket connection. An XMLSocket connection can be used to transfer an unlimited number of XML documents between the client and the server.
XMLSocket.send() Availability Flash Player 5. Usage myXMLSocket.send(object:XML) : Void Parameters object An XML object or other data to transmit to the server. Returns Nothing. Description Method; converts the XML object or data specified in the object parameter to a string and transmits it to the server, followed by a zero (0) byte. If object is an XML object, the string is the XML textual representation of the XML object.
Chapter 2: ActionScript Language Reference
APPENDIX Deprecated Language Elements The evolution of ActionScript has deprecated many elements of the language. This appendix lists the deprecated items in alphabetical order and suggests alternatives.
add Availability Flash Player 4. This function was deprecated in Flash 5; Macromedia recommends you use the add (+) operator when creating content for Flash Player 5 or later. Usage string1 add string2 Parameters string1, string2 A string. Returns Nothing. Description Operator; concatenates two or more strings.
and Availability Flash Player 4. This function was deprecated in Flash 5; Macromedia recommends that you use the logical AND (&&) operator. Usage condition1 and condition2 Parameters condition1,condition2 Conditions or expressions that evaluate to true or false. Returns Nothing. Description Operator; performs a logical AND (&&) operation in Flash Player 4. If both expressions evaluate to true, the entire expression is true.
Button._highquality Availability Flash Player 6. The global version of this function was deprecated in Flash 5 in favor of _quality. Usage my_btn._highquality:Number Description Property (global); specifies the level of anti-aliasing applied to the current SWF file. Specify 2 (best quality) to apply high quality with bitmap smoothing always on. Specify 1 (high quality) to apply anti-aliasing; this smooths bitmaps if the SWF file does not contain animation and is the default value.
call() Availability Flash Player 4. This action was deprecated in Flash 5 in favor of the function statement. Usage call(frame) Parameters frame The label or number of a frame in the Timeline. Returns Nothing. Description Action; executes the script in the called frame without moving the playhead to that frame. Local variables do not exist after the script executes.
chr Availability Flash Player 4. This function was deprecated in Flash 5 in favor of String.fromCharCode(). Usage chr(number) Parameters number An ASCII code number. Returns Nothing. Description String function; converts ASCII code numbers to characters. Example The following example converts the number 65 to the letter A and assigns it to the variable myVar: myVar = chr(65); See also String.
eq (equal — string specific) Availability Flash Player 4. This operator was deprecated in Flash 5 in favor of the == (equality) operator. Usage expression1 eq expression2 Parameters expression1, expression2 Numbers, strings, or variables. Returns Nothing. Description Operator (comparison); compares two expressions for equality and returns a value of true if the string representation of expression1 is equal to the string representation of expression2, false otherwise.
ge (greater than or equal to — string specific) Availability Flash Player 4. This operator was deprecated in Flash 5 in favor of the >= (greater than or equal to) operator. Usage expression1 ge expression2 Parameters expression1, expression2 Numbers, strings, or variables. Returns Nothing.
gt (greater than — string specific) Availability Flash Player 4. This operator was deprecated in Flash 5 in favor of the > (greater than) operator. Usage expression1 gt expression2 Parameters expression1, expression2 Numbers, strings, or variables. Description Operator (comparison); compares the string representation of expression1 with the string representation of expression2 and returns true if expression1 is greater than expression2, false otherwise.
_highquality Availability Flash Player 4. This function was deprecated in Flash 5 in favor of _quality. Usage _highquality Description Property (global); specifies the level of anti-aliasing applied to the current SWF file. Specify 2 (best quality) to apply high quality with bitmap smoothing always on. Specify 1 (high quality) to apply anti-aliasing; this will smooth bitmaps if the SWF file does not contain animation. Specify 0 (low quality) to prevent anti-aliasing.
<> (inequality) Availability Flash 2 . This operator was deprecated in Flash 5; Macromedia recommends that you use the != (inequality) operator. Usage expression1 <> expression2 Parameters expression1,expression2 A number, string, Boolean value, variable, object, array, or function. Returns A Boolean value. Description Operator (inequality); tests for the exact opposite of the equality (==) operator. If expression1 is equal to expression2, the result is false.
ifFrameLoaded Availability Flash Player 3. This action was deprecated in Flash 5; Macromedia recommends that you use the MovieClip._framesloaded property. Usage ifFrameLoaded([scene,] frame) { statement(s); } Parameters scene An optional string that specifies the name of the scene that must be loaded. The frame number or frame label that must be loaded before the next statement is executed. frame statement(s) The instructions to execute if the specified scene, or scene and frame, are loaded.
int Availability Flash Player 4. This function was deprecated in Flash 5 in favor of Math.round(). Usage int(value) Parameters value A number to be rounded to an integer. Returns Nothing. Description Function; converts a decimal number to an integer value by truncating the decimal value. This function is equivalent to Math.floor() if the value parameter is positive and Math.ceil() if the value parameter is negative. See also Math.floor(), Math.
le (less than or equal to — string specific) Availability Flash Player 4. This operator was deprecated in Flash 5 in favor of the <= (less than or equal to) operator. Usage expression1 le expression2 Parameters expression1,expression2 Numbers, strings, or variables. Returns Nothing. Description Operator (comparison); compares expression1 to expression2 and returns a value of true if expression1 is less than or equal to expression2, false otherwise.
length Availability Flash Player 4. This function, along with all the string functions, was deprecated in Flash 5. Macromedia recommends that you use the methods of the String class and the String.length property to perform the same operations. Usage length(expression) length(variable) Parameters A string. expression variable The name of a variable. Returns The length of the specified string or variable. Description String function; returns the length of the specified string or variable.
lt (less than — string specific) Availability Flash Player 4. This operator was deprecated in Flash 5 in favor of the < (less than) operator. Usage expression1 lt expression2 Parameters expression1, expression2 Numbers, strings, or variables. Description Operator (comparison); compares expression1 to expression2 and returns true if expression1 is less than expression2, false otherwise.
maxscroll Availability Flash Player 4. This function was deprecated in favor of the TextField.maxscroll property. Usage variable_name.maxscroll Description Read-only property; indicates the line number of the top line of visible text in a text field when the bottom line in the field is also visible. The maxscroll property works with the scroll property to control how information appears in a text field. This property can be retrieved, but not modified. See also TextField.maxscroll, TextField.
mbchr Availability Flash Player 4. This function was deprecated in favor of the String.fromCharCode() method. Usage mbchr(number) Parameters number The number to convert to a multibyte character. Returns A string. Description String function; converts an ASCII code number to a multibyte character. See also String.
mblength Availability Flash Player 4. This function was deprecated in favor of the String class. Usage mblength(string) Parameters string A string. Returns A number. Description String function; returns the length of the multibyte character string.
mbord Availability Flash Player 4. This function was deprecated in Flash 5 in favor of String.charCodeAt(). Usage mbord(character) Parameters character The character to convert to a multibyte number. Returns A number. Description String function; converts the specified character to a multibyte number. See also String.
mbsubstring Availability Flash Player 4. This function was deprecated in Flash 5 in favor of String.substr(). Usage mbsubstring(value, index, count) Parameters value The multibyte string from which to extract a new multibyte string. index The number of the first character to extract. count The number of characters to include in the extracted string, not including the index character. Returns A string.
MovieClip._highquality Availability Flash Player 6. This function was deprecated in favor of _quality. Usage my_mc._highquality:Number Description Property; specifies the level of anti-aliasing applied to the current SWF file. Specify 2 (best quality) to apply high quality with bitmap smoothing always on. Specify 1 (high quality) to apply anti-aliasing; this will smooth bitmaps if the SWF file does not contain animation. Specify 0 (low quality) to prevent anti-aliasing.
ne (not equal — string specific) Availability Flash Player 4. This operator was deprecated in favor of the != (inequality) operator. Usage expression1 ne expression2 Parameters expression1, expression2 Numbers, strings, or variables. Returns A Boolean value. Description Operator (comparison); compares expression1 to expression2 and returns true if expression1 is not equal to expression2; false otherwise.
not Availability Flash Player 4. This operator was deprecated in favor of the ! (logical NOT) operator. Usage not expression Parameters expression A variable or other expression that converts to a Boolean value. Description Operator; performs a logical NOT (!) operation in Flash Player 4.
or Availability Flash 4 . This operator was deprecated in favor of the || (logical OR) operator. Usage condition1 or condition2 Parameters condition1,2 An expression that evaluates to true or false. Returns Nothing. Description Operator; evaluates condition1 and condition2, and if either expression is true, the whole expression is true.
ord Availability Flash Player 4. This function was deprecated in favor of the methods and properties of the String class. Usage ord(character) Parameters character The character to convert to an ASCII code number. Returns Nothing. Description String function; converts characters to ASCII code numbers.
random Availability Flash Player 4. This function was deprecated in Flash 5 in favor of Math.random(). Usage random(value) Parameters value An integer. Returns An integer. Description Function; returns a random integer between 0 and one less than the integer specified in the value parameter. Example The following use of random() returns a value of 0, 1, 2, 3, or 4: random(5); See also Math.
scroll Availability Flash Player 4. This property was deprecated in favor of the scroll property of the TextField class. Usage textFieldVariableName.scroll = x Description Property; controls the display of information in a text field associated with a variable. The scroll property defines where the text field begins displaying content; after you set it, Flash Player updates it as the user scrolls through the text field.
substring Availability Flash Player 4. This function was deprecated in favor of String.substr(). Usage substring("string", index, count) Parameters The string from which to extract the new string. string index The number of the first character to extract. count The number of characters to include in the extracted string, not including the index character. Returns Nothing. Description String function; extracts part of a string.
tellTarget Availability Flash Player 3. This function was deprecated in Flash 5; Macromedia recommends that you use dot (.) notation and the with statement. Usage tellTarget("target") { statement(s); } Parameters target A string that specifies the target path of the Timeline to be controlled. statement(s) The instructions to execute if the condition is true. Returns Nothing.
If you need to issue multiple commands to the ball instance, you can use the with action, as shown in the following statement: on(release) { with(_parent.
TextField._highquality Availability Flash Player 6. This function was deprecated in favor of _quality. Usage my_txt._highquality Description Property (global); specifies the level of anti-aliasing applied to the current SWF file. Specify 2 (best quality) to apply high quality with bitmap smoothing always on. Specify 1 (high quality) to apply anti-aliasing; this will smooth bitmaps if the SWF file does not contain animation. Specify 0 (low quality) to prevent anti-aliasing.
toggleHighQuality() Availability Flash 2. This function was deprecated in Flash 5 in favor of _quality. Usage toggleHighQuality() Parameters None. Returns Nothing. Description Function; turns anti-aliasing on and off in Flash Player. Anti-aliasing smooths the edges of objects and slows down SWF playback. This action affects all SWF files in Flash Player.
Appendix: Deprecated Language Elements