MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference

Summary of FLEX-FLEX ACTIONSCRIPT LANGUAGE

  • Page 1

    Flex actionscript language reference.

  • Page 2

    Trademarks activeedit, activetest, add life to the web, afterburner, aftershock, andromedia, allaire, animation powerpack, aria, attain, authorware, authorware star, backstage, blue sky software, blue sky, breeze, bright tiger, clustercats, coldfusion, contents tab composer, contribute, design in mo...

  • Page 3: Contents

    3 contents introduction: getting started with actionscript . . . . . . . . . . . . . . . . . . . . . . . 5 intended audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 using the documentation . . . . . . . . . . . . . . . . . . . . . . . . ....

  • Page 4

    4 contents chapter 3: working with external data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 sending and loading variables to and from a remote source . . . . . . . . . . . . . . . . . . 67 sending messages to and from flash player . . . . . . . . . . . . . . . . . . . . . . . ....

  • Page 5: Introduction

    5 introduction getting started with actionscript macromedia flex developers can use actionscript to extend the functionality of their flex applications. Actionscript is an ecmascript-based language that provides support for object- oriented development. You are not required to use actionscript to us...

  • Page 6

    6 introduction: getting started with actionscript • chapter 7, “actionscript for flash,” on page 490 describe functions, properties, and classes of macromedia flash player that you can use in a macromedia flex application, if appropriate. • appendix a, “deprecated flash 4 operators,” on page 809 lis...

  • Page 7: Part I

    Part i welcome to actionscript this part includes information on using the actionscript language. For information on the classes and language elements you can use in your scripts, see part ii, “reference.” chapter 1: actionscript basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

  • Page 9: Chapter 1

    9 chapter 1 actionscript basics actionscript has rules of grammar and punctuation that determine which characters and words are used to create meaning and in which order they can be written. For example, in english, a period ends a sentence; in actionscript, a semicolon ends a statement. The general...

  • Page 10

    10 chapter 1: actionscript basics differences between actionscript and javascript actionscript is similar to the core javascript programming language. You don’t need to know javascript to use and learn actionscript; however, if you know javascript, actionscript will seem familiar. This manual does n...

  • Page 11

    Terminology 11 terminology as with all scripting languages, actionscript uses its own terminology. The following list provides an introduction to important actionscript terms: boolean is a true or false value. Classes are data types that you can create to define a new type of object. To define a cla...

  • Page 12

    12 chapter 1: actionscript basics identifiers are names used to indicate a variable, property, object, function, or method. The first character must be a letter, underscore ( _ ), or dollar sign ( $ ). Each subsequent character must be a letter, number, underscore, or dollar sign. For example, first...

  • Page 13

    Syntax 13 parameters (also called arguments) are placeholders that let you pass values to functions. For example, the following welcome() function uses two values it receives in the parameters firstname and hobby : function welcome(firstname:string, hobby:string):string { var welcometext:string = "h...

  • Page 14

    14 chapter 1: actionscript basics • “keywords and reserved words” on page 17 • “constants” on page 18 case sensitivity in a case-sensitive programming language, variable names that differ only in case ( book and book ) are considered different from each other. Therefore, it’s good practice to follow...

  • Page 15

    Syntax 15 curly braces actionscript event handlers, class definitions, and functions are grouped together into blocks with curly braces ( {} ). You can put the opening brace on the same line as your declaration or on the next line, as shown in the following examples. To make your code easier to read...

  • Page 16

    16 chapter 1: actionscript basics semicolons are required within for loops, as shown in the following example: //for loop that adds numbers 1-10 var sum:number = 0; for (var i=1; i sum += i; } parentheses when you define a function, place any parameters inside parentheses [()]: function myfunction (...

  • Page 17

    Syntax 17 comments can be any length without affecting the size of the exported file, and they do not need to follow rules for actionscript syntax or keywords. To create a comment block, place /* at the beginning of the commented lines and */ at the end. This technique lets you create lengthy commen...

  • Page 18

    18 chapter 1: actionscript basics constants a constant is a property whose value never changes. Actionscript contains predefined constants. For example, the constants backspace , enter , space , and tab are properties of the key object and refer to keyboard keys. To test whether the user is pressing...

  • Page 19

    About data types 19 string data type a string is a sequence of characters such as letters, numbers, and punctuation marks. You enter strings in an actionscript statement by enclosing them in single (') or double (") quotation marks. A common way that you use the string type is to assign a string to ...

  • Page 20

    20 chapter 1: actionscript basics you can also use methods of the built-in math and number classes to manipulate numbers. For more information on the methods and properties of these classes, see the “math class” and “number class” entries. The following example uses the sqrt() (square root) method o...

  • Page 21

    About data types 21 object data type an object is a collection of properties. Each property has a name and a value. The value of a property can be any flash data type—even the object data type. This lets you arrange objects inside each other, or nest them. To specify objects and their properties, yo...

  • Page 22

    22 chapter 1: actionscript basics creating movie clips dynamically using actionscript to create movie clips dynamically is useful when you want to avoid manually creating movie clips on the stage or attaching them from the library. For example, you might create an image gallery with a large number o...

  • Page 23

    Assigning data types to elements 23 several methods and functions return null if no value has been set. The following example demonstrates how you can use null to test if form fields currently have form focus: if (selection.Getfocus() == null) { trace("no selection"); } undefined data type the undef...

  • Page 24

    24 chapter 1: actionscript basics • “casting objects” on page 25 • “determining an item’s data type” on page 26 automatic data typing if you do not explicitly define an item as holding either a number, a string, or another data type, flash player will, at runtime, try to determine the data type of a...

  • Page 25

    Assigning data types to elements 25 function welcome(firstname:string, age:number){ } // strict typing of parameter and return value function square(x:number):number { var squared:number = x*x; return squared; } because you must use the var keyword when strictly typing variable, you can’t strictly t...

  • Page 26

    26 chapter 1: actionscript basics the syntax for casting is type(item) , where you want the compiler to behave as if the data type of item is type . Casting is essentially a function call, and the function call returns null if the cast fails at runtime. If the cast succeeds, the function call return...

  • Page 27

    About variables 27 the following example shows how you can use these operators and the difference between them: //create a new instance of loadvars class var mylv:loadvars = new loadvars(); //instanceof operator specifies instance of what class if (mylv instanceof loadvars) { trace("yes, it's a load...

  • Page 28

    28 chapter 1: actionscript basics you should not use any element in the actionscript language as a variable name because it can cause syntax errors or unexpected results. In the following example, if you name a variable string and then try to create a string object using new string() , the new objec...

  • Page 29

    About variables 29 you can assign a data type to a local variable when you define it, which helps prevent you from assigning the wrong type of data to an existing variable. For more information, see “strict data typing” on page 24 . Global variables global variables and functions are visible to ever...

  • Page 30

    30 chapter 1: actionscript basics var mywebsite = "http://www.Macromedia.Com"; geturl(mywebsite); // browser displays www.Macromedia.Com you can change the value of a variable in a script as many times as you want. The type of data that a variable contains affects how and when the variable’s value c...

  • Page 31

    Using operators to manipulate values in expressions 31 in the following example, myarray contains an array object, so it is passed to function zeroarray() by reference. The function zeroarray() accepts an array object as a parameter and sets all the elements of that array to 0. It can modify the arr...

  • Page 32

    32 chapter 1: actionscript basics operator precedence and associativity when two or more operators are used in the same statement, some operators take precedence over others. Actionscript follows a precise hierarchy to determine which operators to execute first. For example, multiplication is always...

  • Page 33

    Using operators to manipulate values in expressions 33 numeric operators numeric operators add, subtract, multiply, divide, and perform other arithmetic operations. The most common use of the increment operator is i++ instead of the more verbose i = i+1 . You can use the increment operator before or...

  • Page 34

    34 chapter 1: actionscript basics this process is also known as a preincrement. In the following example, age is incremented after the test is performed: if (age++ >= 30) this process is also known as a postincrement. The following table lists the actionscript numeric operators: comparison operators...

  • Page 35

    Using operators to manipulate values in expressions 35 the following table lists the actionscript comparison operators: string operators the addition (+) operator has a special effect when it operates on strings: it concatenates the two string operands. For example, the following statement adds "con...

  • Page 36

    36 chapter 1: actionscript basics logical operators logical operators compare boolean values ( true and false ) and return a third boolean value. For example, if both operands evaluate to true , the logical and ( && ) operator returns true . If one or both of the operands evaluate to true , the logi...

  • Page 37

    Using operators to manipulate values in expressions 37 equality operators you can use the equality ( == ) operator to determine whether the values or references of two operands are equal. This comparison returns a boolean ( true or false ) value. If the operands are strings, numbers, or boolean valu...

  • Page 38

    38 chapter 1: actionscript basics this code is equivalent to the following code, which is slightly easier to read: flavor = geticecreamflavor(); if (flavor != "vanilla") { trace ("flavor was " + flavor + ", not vanilla."); } the following table lists the actionscript assignment operators: dot and ar...

  • Page 39

    Using condition statements 39 array access operator. You can use the array access operator to dynamically set and retrieve instance names and variables. For example, in the following code, the expression inside the array access operator is evaluated, and the result of the evaluation is used as the n...

  • Page 40

    40 chapter 1: actionscript basics checking conditions statements that check whether a condition is true or false begin with the term if . If the condition evaluates to true , actionscript executes the next statement. If the condition doesn’t exist, actionscript skips to the next statement outside th...

  • Page 41

    Creating functions 41 children include other functions, objects, and variables. The following example uses the trace statement to print its results in the output panel: var myobject:object = { name:'joe', age:25, city:'san francisco' }; for (propertyname in myobject) { trace("myobject has the proper...

  • Page 42

    42 chapter 1: actionscript basics a well-written function can be thought of as a “black box.” if it has carefully placed comments about its input, output, and purpose, a user of the function does not need to understand exactly how the function works internally. For more information, see the followin...

  • Page 43

    Creating functions 43 the parameter initials in the function filloutscorecard() is similar to a local variable; it exists while the function is called and ceases to exist when the function exits. If you omit parameters during a function call, the omitted parameters are passed as undefined . If you p...

  • Page 44

    44 chapter 1: actionscript basics calling a user-defined function to call a function, enter the target path to the name of the function, if necessary, and pass any required parameters inside parentheses. For example, the following statement invokes the function sqr() in the object mathlib , passes t...

  • Page 45: Chapter 2

    45 chapter 2 creating custom classes with actionscript 2.0 actionscript 2.0 provides several powerful programming features found in other programming languages, such as java. Actionscript 2.0 encourages program structures that are reusable, scalable, robust, and maintainable. It also decreases devel...

  • Page 46

    46 chapter 2: creating custom classes with actionscript 2.0 • “encapsulation” on page 47 • “polymorphism” on page 47 objects think of a real-world object, such as a cat. A cat could be said to have properties (or states), such as name, age, and color; a cat also has behaviors such as sleeping, eatin...

  • Page 47

    Principles of object-oriented programming 47 interfaces interfaces in object-oriented programming can be described as classes whose methods are not implemented (defined). Another class can implement the methods declared by the interface. An interface can also be thought of as a “programming contract...

  • Page 48

    48 chapter 2: creating custom classes with actionscript 2.0 for example, you might start with a class called mammal that has play() and sleep() methods. You then create cat, monkey, and dog subclasses to extend the mammal class. The subclasses override the play() method from the mammal class, to ref...

  • Page 49

    Using classes: a simple example 49 4. In your text editor, enter the following code (in this procedure, new code you type in each step is bold ): class person { } this is called the class declaration. In its most basic form, a class declaration consists of the class keyword, followed by the class na...

  • Page 50

    50 chapter 2: creating custom classes with actionscript 2.0 the person() constructor function takes two parameters, myname and myage , and assigns those parameters to the name and age properties. The two function parameters are strictly typed as string and number, respectively. Unlike other function...

  • Page 51

    Creating and using classes 51 this code invokes the person class’s constructor function, passing as parameters the values "nate" and 32. The newperson variable is typed as a person object. Typing your objects in this way enables the compiler to ensure that you don’t try to access properties or metho...

  • Page 52

    52 chapter 2: creating custom classes with actionscript 2.0 if you are creating multiple custom classes, use packages to organize your class files. A package is a directory that contains one or more class files and resides in a designated classpath directory. Class names must be fully qualified with...

  • Page 53

    Creating and using classes 53 creating properties and methods a class’s members consist of properties (variable declarations) and methods (function definitions). You must declare and define all properties and methods inside the class body (the curly braces [{}]); otherwise, an error will occur durin...

  • Page 54

    54 chapter 2: creating custom classes with actionscript 2.0 private members (properties and methods) are accessible only to the class that defines those members and to subclasses of that original class. Instances of the original class, or instances of subclasses of that class, cannot access privatel...

  • Page 55

    Creating and using classes 55 return "hello world"; } } this rule applies only to instance variables (variables that are copied into each instance of a class), not class variables (variables that belong to the class). For more information about these kinds of variables, see “instance and class membe...

  • Page 56

    56 chapter 2: creating custom classes with actionscript 2.0 multiple inheritance, or inheriting from more than one class, is not allowed in actionscript 2.0. However, classes can effectively inherit from multiple classes if you use individual extends statements, as shown in the following example: //...

  • Page 57

    Using packages 57 subclasses of dynamic classes are also dynamic, with one exception. Subclasses of the built-in movieclip class are not dynamic by default, even though the movieclip class itself is dynamic. This implementation provides you with more control over subclasses of the movieclip class, b...

  • Page 58

    58 chapter 2: creating custom classes with actionscript 2.0 to reference a class that resides in a package directory, you can either specify its fully qualified class name or import the package by using the import statement (see the following section). Creating and using interfaces an interface in o...

  • Page 59

    Creating and using interfaces 59 interfaces cannot contain any variable declarations or assignments. Functions declared in an interface cannot contain curly braces. For example, the following interface won’t compile: interface badinterface{ // compiler error. Variable declarations not allowed in int...

  • Page 60

    60 chapter 2: creating custom classes with actionscript 2.0 for example, the following code first checks if the object name newbox implements the movable interface before calling the moveup() method on the object: if (movable(newbox) != null) { newbox.Moveup(); } for more information about casting, ...

  • Page 61

    Instance and class members 61 class members are declared with the static modifier. For example, you could declare the species class member with the following code: class person { static var species:string = "homo sapiens"; ... } you can also declare methods of a class to be static, as shown in the f...

  • Page 62

    62 chapter 2: creating custom classes with actionscript 2.0 the singleton object can then be accessed using singleton.Getinstance(); this also means that the singleton object is not created until it is actually needed—that is, until some other code asks for it by calling the getinstance method. This...

  • Page 63

    Implicit getter/setter methods 63 trace("creating subwidget # "+widget.Widgetcount); } } the actionscript 2.0 compiler can resolve static member references within class definitions. In the previous example, if you don't specify the class name for the widget.Widgetcount property, but instead refer on...

  • Page 64

    64 chapter 2: creating custom classes with actionscript 2.0 however, if you want to use a more concise syntax, use implicit getter/setter methods. Implicit getter/setter methods let you access class properties in a direct manner, while maintaining good oop practice. To define these methods, use the ...

  • Page 65

    Importing classes 65 importing classes to reference a class in another script, you must prefix the class name with the class’s package path. The combination of a class’s name and its package path is the class’s fully qualified class name. If a class resides in a top-level classpath directory—not in ...

  • Page 66

    66 chapter 2: creating custom classes with actionscript 2.0

  • Page 67: Chapter 3

    67 chapter 3 working with external data in macromedia flex, you can use actionscript to load data from external sources into a swf file. You can also send data from a swf file for processing by an application server (such as macromedia coldfusion mx or macromedia jrun) or another type of server-side...

  • Page 68

    68 chapter 3: working with external data • the functions and movieclip methods that use the http or https protocol to send information in url-encoded format are geturl() , loadvariables() , loadvariablesnum() , loadmovie() , and loadmovienum() . • the loadvars methods that use the http or https prot...

  • Page 69

    Sending and loading variables to and from a remote source 69 using http to connect to server-side scripts the geturl() function and the movieclip.Loadvariables() , movieclip.Loadmovie() , and movieclip.Geturl() methods can communicate with server-side scripts using http or https protocols. When used...

  • Page 70

    70 chapter 3: working with external data the loadvars class was introduced in flash player 6 to provide a cleaner, more object-oriented interface for the common task of exchanging cgi data with a web server. Advantages of the loadvars class include the following: • you don’t need to create container...

  • Page 71

    Sending and loading variables to and from a remote source 71 in the following example, is the parent node; it has no attributes and contains the child node , which has the attributes symbol , qty , price , and value : qty="75" price="245.50" value="18412.50" /> for more information on xml, see www.W...

  • Page 72

    72 chapter 3: working with external data when you invoke the connect() method, flash player opens a tcp/ip connection to the server and keeps that connection open until one of the following events happens: • the close() method of the xmlsocket class is called. • no more references to the xmlsocket o...

  • Page 73

    Sending messages to and from flash player 73 to control a swf file in flash player from web browser scripting languages such as javascript, vbscript, and microsoft jscript, you can use flash player methods—functions that send messages from a host environment to the swf file. For more information, se...

  • Page 74

    74 chapter 3: working with external data an fscommand() function invokes the javascript function moviename_dofscommand in the html page that embeds the swf file, where moviename is the name of flash player as assigned by the name attribute of the embed tag or the id attribute of the object tag. If f...

  • Page 75: Part II

    Part ii reference this part provides syntax and usage information for every element in the actionscript language. It also contains appendixes that provide reference material you may want to review as you write your scripts. For an overview of how to use actionscript, see “ part i, “welcome to action...

  • Page 77: Chapter 4

    77 chapter 4 about the actionscript language reference the next three chapters of this manual describe the syntax and use of actionscript elements in macromedia flex. The chapters list all actionscript elements that are common to macromedia flash and to flex—operators, keywords, statements, actions,...

  • Page 78

    78 chapter 4: about the actionscript language reference usage this section provides correct syntax for using the actionscript element in your code. The required portion of the syntax is in code font , and the code that you provide is in italicized code font . Brackets ( [] ) indicate optional parame...

  • Page 79

    Sample entry for classes 79 method, property, and event handler listings the methods, properties, and event handlers of a class are listed alphabetically after the class entry..

  • Page 80: Chapter 5

    80 chapter 5 actionscript core language elements this chapter documents all the elements of the actionscript language that are not related to a particular class or to a particular macromedia product. That is, all products that support actionscript have access to any language element in this chapter....

  • Page 81: Chapter 5

    –– (decrement) 81 –– (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 expr...

  • Page 82

    82 chapter 5: actionscript core language elements ++ (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 operato...

  • Page 83

    ! (logical not) 83 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 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...

  • Page 84

    84 chapter 5: actionscript core language elements 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 conv...

  • Page 85

    != (inequality) 85 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...

  • Page 86

    86 chapter 5: actionscript core language elements true foo foo false the following example illustrates comparison by reference with two arrays: var a:array = [ 1, 2, 3 ]; var b:array = [ 1, 2, 3 ]; trace(a); // 1, 2, 3 trace(b); // 1, 2, 3 trace(a!=b); // true a = b; trace(a); // 1, 2, 3 trace(b); /...

  • Page 87

    % (modulo) 87 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” on page 24 . If expression...

  • Page 88

    88 chapter 5: actionscript core language elements 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 numbe...

  • Page 89

    & (bitwise and) 89 example the following example assigns the value 4 to the variable x : var x:number = 14; var y:number = 5; trace(x%=y); // output: 4 see also % (modulo) & (bitwise and) availability flash player 5. Usage expression1 & expression2 parameters none. Returns a 32-bit integer. Descript...

  • Page 90

    90 chapter 5: actionscript core language elements in the numbers 13 and 11 the result is 9 because only the first and last positions in both numbers have the number 1. The following examples show the behavior of the return value conversion: trace(0xffffffff); // 4294967295 trace(0xffffffff & 0xfffff...

  • Page 91

    &= (bitwise and assignment) 91 example the following example uses the logical and ( && ) operator to perform a test to determine if a player has won the game. The turns variable and the score variable are updated when a player takes a turn or scores points during the game. The script writes “you win...

  • Page 93

    – (minus) 93 usage 2: the following example evaluates the function foo() , and then the function bar() , and returns the result of the expression a + b : var a:number = 1; var b:number = 2; function foo() { a += b; } function bar() { b *= 10; } trace((foo(), bar(), a+b)); // outputs 23 usage 3: the ...

  • Page 94

    94 chapter 5: actionscript core language elements example usage 1: the following statement reverses the sign of the expression 2 + 3: trace(-(2+3));// output: -5 usage 2: the following statement subtracts the integer 2 from the integer 5: trace(5-2);// output: 3 the result, 3, is an integer. Usage 3...

  • Page 95

    , (comma) 95 *= (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 compoun...

  • Page 96

    96 chapter 5: actionscript core language elements 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 parenthese...

  • Page 97

    . (dot) 97 var z:number = 0; v = (v + 4, z++, v + 6); trace(v); // output: 6 trace(z); // output: 1 see also () (parentheses) . (dot) availability flash player 4. Usage object.Property_or_method instancename.Childinstance parameters object an instance of a class. The object can be an instance of any...

  • Page 98

    98 chapter 5: actionscript core language elements 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 f...

  • Page 99

    ?: (conditional) 99 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.Random()*integer); } trace(randomint(8)...

  • Page 100

    100 chapter 5: actionscript core language elements the following example shows a conditional statement written in shorthand: var timecode:string = (new date().Gethours() trace(timecode); the same conditional statement could also be written in longhand, as shown in the following example: if (new date...

  • Page 101

    /* (comment delimiter) 101 // (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 ...

  • Page 102

    102 chapter 5: actionscript core language elements 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 ...

  • Page 103

    [] (array access) 103 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” on page 32 . Example ...

  • Page 104

    104 chapter 5: actionscript core language elements description operator; initializes a new array or multidimensional array with the specified elements ( a0 , and so on), or accesses elements in an array. The array access operator lets you dynamically set and retrieve instance, variable, and object n...

  • Page 105

    ^ (bitwise xor) 105 the following example creates an array called employee_array and uses the trace() statement to send the elements to the log file. In the fourth line, an element in the array is changed, and the fifth line sends the newly modified array to the log file: var employee_array = ["barb...

  • Page 106

    106 chapter 5: actionscript core language elements positive integers are converted to an unsigned hex value with a maximum value of 4294967295 or 0xffffffff; values larger than the maximum have their most significant digits discarded when they are converted so the value is still 32-bit. Negative num...

  • Page 107

    {} (object initializer) 107 example the following example shows a bitwise xor assignment (^=) operation: // 15 decimal = 1111 binary var x:number = 15; // 9 decimal = 1001 binary var y:number = 9; trace(x ^= y); // returns 6 decimal (0110 binary) see also & (bitwise and) , &= (bitwise and assignment...

  • Page 108

    108 chapter 5: actionscript core language elements example the first line of the following code creates an empty object using the object initializer ({}) operator; the second line creates a new object using a constructor function: var object:object = {}; var object:object = new object(); the followi...

  • Page 109

    (logical or) 109 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 intege...

  • Page 110

    110 chapter 5: actionscript core language elements 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 o...

  • Page 112

    112 chapter 5: actionscript core language elements 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 ...

  • Page 113

    + (addition) 113 /* 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 read- only flag. The following code constructs the mask an...

  • Page 114

    114 chapter 5: actionscript core language elements this statement adds the floating-point numbers 2.5 and 3.25 and writes the resulting floating- point number, 5.75, to the log file: trace(2.5+3.25); // output: 5.75 the following example shows how numeric sums to the right of a string expression are...

  • Page 115

    115 see also + (addition) availability flash player 5. Usage expression1 expression2 parameters expression1,expression2 a number or string. Returns a boolean value. Description operator (comparison); compares two expressions and determines whether expression1 is less than expression2 ; if so, the op...

  • Page 116

    116 chapter 5: actionscript core language elements 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 e...

  • Page 117

    117 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 pe...

  • Page 118

    118 chapter 5: actionscript core language elements parameters expression1,expression2 a number or string. Returns a boolean value. Description operator (comparison); compares two expressions and determines whether expression1 is less than or equal to expression2 ; if it is, the operator returns true...

  • Page 119

    = (assignment) 119 description operator; assigns the value of expression2 (the parameter on the right) to the variable, array element, or property in expression1 . Assignment can be either by value or by reference. Assignment by value copies the actual value of expression2 and stores it in expressio...

  • Page 120

    120 chapter 5: actionscript core language elements -= (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); ...

  • Page 121

    == (equality) 121 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 o...

  • Page 122

    122 chapter 5: actionscript core language elements 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 re...

  • Page 123

    === (strict equality) 123 example the comments in the following code show the returned value of operations that use the equality and strict equality operators: // both return true because no conversion is done var string1:string = "5"; var string2:string = "5"; trace(string1 == string2); // true tra...

  • Page 124

    124 chapter 5: actionscript core language elements > (greater than) availability flash player 4. Usage expression1 >expression2 parameters expression1,expression2 a number or string. Returns a boolean value. Description operator (comparison); compares two expressions and determines whether expressio...

  • Page 125

    >> (bitwise right shift) 125 for more information, see “operator precedence and associativity” on page 32 . Example in the following example, the greater than or equal to (>=) operator is used to determine whether the current hour is greater than or equal to 12: if (new date().Gethours()>=12) { trac...

  • Page 126

    126 chapter 5: actionscript core language elements example the following example converts 65535 to a 32-bit integer and shifts it 8 bits to the right: var x:number = 65535 >> 8; trace(x); // outputs 255 the following example shows the result of the previous example: var x:number = 255 this is becaus...

  • Page 127

    >>> (bitwise unsigned right shift) 127 the following two expressions are equivalent: a >>= b a = (a >> b) for more information, see “operator precedence and associativity” on page 32 . Example the following commented code uses the bitwise right shift and assignment ( >>= ) operator. Function convert...

  • Page 128

    128 chapter 5: actionscript core language elements floating-point numbers are converted to integers by discarding any digits after the decimal point. Positive integers are converted to an unsigned hex value with a maximum value of 4294967295 or 0xffffffff; values larger than the maximum have their m...

  • Page 129: Chapter 5

    Boolean() 129 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 retu...

  • Page 130

    130 chapter 5: actionscript core language elements // variables representing boolean values are compared by value var a:boolean = boolean("a"); // a is true var b:boolean = boolean(1); // b is true trace(a==b); // true // variables representing boolean objects are compared by reference var a:boolean...

  • Page 131: Chapter 5

    Array() 131 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...

  • Page 132: Chapter 5

    132 chapter 5: actionscript core language elements break 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 sta...

  • Page 133

    Break 133 see also for , for..In , do while , while , switch , case , continue , throw , try..Catch..Finally.

  • Page 134: Chapter 5

    134 chapter 5: actionscript core language elements case availability flash player 4. Usage case expression: statement(s) parameters expression any expression. Statement(s) any statement or sequence of statements. Returns nothing. Description statement; defines a condition for the switch statement. I...

  • Page 135

    Case 135 see also break , default , === (strict equality) , switch.

  • Page 136: Chapter 5

    136 chapter 5: actionscript core language elements class availability flash player 6. Usage [dynamic] class classname [ extends superclass ] [ implements interfacename [, interfacename... ] ] { // class definition here } parameters classname the fully qualified name of the class. Superclass the name...

  • Page 137

    Class 137 class c implements interface_i, interface_j // ok class c extends class_d implements interface_i, interface_j // ok class c extends class_d, class_e // not ok for more information, see “creating and using classes” in using actionscript in flash.For more information, see “creating and using...

  • Page 138

    138 chapter 5: actionscript core language elements in your script, 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/...

  • Page 139: Chapter 5

    Clearinterval() 139 clearinterval() 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() ...

  • Page 140: Chapter 5

    140 chapter 5: actionscript core language elements continue 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...

  • Page 141

    Continue 141 if (i%3 == 0) { continue; } trace(i); } in the following for..In loop, continue causes the flash interpreter to skip the rest of the loop body and jump back to the top of the loop, where the next value in the enumeration is processed: for (i in _root) { if (i == "$version") { continue; ...

  • Page 142: Chapter 5

    142 chapter 5: actionscript core language elements 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 s...

  • Page 143: Chapter 5

    Delete 143 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 successf...

  • Page 144

    144 chapter 5: actionscript core language elements 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 del...

  • Page 145: Chapter 5

    Do while 145 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 lo...

  • Page 146

    146 chapter 5: actionscript core language elements see also break , continue , while.

  • Page 147: Chapter 5

    Dynamic 147 dynamic availability flash player 6. Usage dynamic class classname [ extends superclass ] [ implements interfacename [, interfacename... ] ] { // class definition here } description keyword; specifies that objects based on the specified class can add and access dynamic properties at runt...

  • Page 148

    148 chapter 5: actionscript core language elements 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:l...

  • Page 149: Chapter 5

    Else 149 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 nothi...

  • Page 150: Chapter 5

    150 chapter 5: actionscript core language elements 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 condi...

  • Page 151: Chapter 5

    Escape() 151 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-e...

  • Page 152: Chapter 5

    152 chapter 5: actionscript core language elements eval() availability flash player 5. 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 undef...

  • Page 153: Chapter 5

    Extends 153 extends availability flash player 6. Usage class classname extends otherclassname {} interface interfacename extends otherinterfacename {} parameters classname the name of the class you are defining. Otherclassname the name of the class on which classname is based. Interfacename the name...

  • Page 154

    154 chapter 5: actionscript core language elements 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 ...

  • Page 155

    Extends 155 the following example instantiates a truck object, calls a method overridden by the truck class ( reverse() ), then calls a method defined in the vehicle class ( stop() ): var mytruck:truck = new truck(2, "white", 18); mytruck.Reverse(); // output: [truck] make beeping sound [vehicle] re...

  • Page 156: Chapter 5

    156 chapter 5: actionscript core language elements false 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 "f...

  • Page 157: Chapter 5

    For 157 for availability flash player 5. Usage for(init; condition; next) { statement(s); } parameters init an expression to evaluate before beginning the looping sequence; usually an assignment expression. A var statement is also permitted for this parameter. Condition an expression that evaluates ...

  • Page 158

    158 chapter 5: actionscript core language elements the following example uses for to perform the same action repeatedly. In the code, the for loop adds the numbers from 1 to 100. Var sum:number = 0; for (var i:number = 1; i sum += i; } trace(sum); // output: 5050 the following example shows that cur...

  • Page 159: Chapter 5

    For..In 159 for..In availability flash player 5. Usage for(variableiterant in object){ statement(s); } parameters variableiterant the name of a variable to act as the iterant, referencing each property of an object or element in an array. Object the name of an object to be iterated. Statement(s) an ...

  • Page 160

    160 chapter 5: actionscript core language elements 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 myarr...

  • Page 161: Chapter 5

    Fscommand() 161 fscommand() availability flash player 3. Usage fscommand("command", "parameters") parameters command a string passed to the host application for any use, or a command passed to flash player. Parameters a string passed to the host application for any use, or a value passed to flash pl...

  • Page 162

    162 chapter 5: actionscript core language elements 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 m...

  • Page 163: Chapter 5

    Function 163 function availability flash player 5. Usage function functionname ([parameter0, parameter1,...Parametern]){ statement(s) } function ([parameter0, parameter1,...Parametern]){ statement(s) } parameters functionname the name of the new function. This parameter is optional. Parameter an ide...

  • Page 164

    164 chapter 5: actionscript core language elements example the following example defines the function sqr , which accepts one parameter and returns the math.Pow(x, 2) of the parameter: function sqr(x:number) { return math.Pow(x, 2); } var y:number = sqr(3); trace(y); // output: 9 if the function is ...

  • Page 165: Chapter 5

    Get 165 get availability flash player 6. Usage function get property() { // your statements here } parameters property the word you use to refer to the property that get accesses; this value must be the same as the value used in the corresponding set command. Returns nothing. Description keyword; pe...

  • Page 166

    166 chapter 5: actionscript core language elements san fran san francisco */ when you trace giants.Name, you use the get method to return the value of the property. See also object.Addproperty() , set.

  • Page 167: Chapter 5

    Gettimer() 167 gettimer() 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. Ex...

  • Page 168: Chapter 5

    168 chapter 5: actionscript core language elements 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. Windo...

  • Page 169

    Geturl() 169 you can also use get or post for sending variables. The following example uses get to append variables to a url: var firstname:string = "gus"; var lastname:string = "richardson"; var age:number = 92; mybtn_btn.Onrelease = function() { geturl("http://www.Macromedia.Com", "_blank", "get")...

  • Page 170: Chapter 5

    170 chapter 5: actionscript core language elements getversion() 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 inf...

  • Page 171: Chapter 5

    _global object 171 _global object 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. ...

  • Page 172: Chapter 5

    172 chapter 5: actionscript core language elements 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. Descrip...

  • Page 173: Chapter 5

    Implements 173 implements availability flash player 6. Usage myclass implements interface01 [, interface02, ...] description keyword; specifies that a class must define all the methods declared in the interface (or interfaces) being implemented. For more information, see “interfaces as data types” o...

  • Page 174: Chapter 5

    174 chapter 5: actionscript core language elements import availability flash player 6. Usage import classname import packagename.* parameters classname the fully qualified name of a class you have defined in an external class file. Packagename a directory in which you have stored related class files...

  • Page 175: Chapter 5

    #include 175 #include 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 current script; .As is the ...

  • Page 176

    176 chapter 5: actionscript core language elements // as file is in a directory at the same level as the directory // that contains the script file // the directory is named "all_includes" #include "../all_includes/init_script.As" // as file is specified by an absolute path in windows // note use of...

  • Page 177: Chapter 5

    Infinity 177 infinity 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 . Chapter 5 actionscript core language elements.

  • Page 178: Chapter 5

    178 chapter 5: actionscript core language elements -infinity 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 5 actionscript core language eleme...

  • Page 179: Chapter 5

    Instanceof 179 instanceof availability flash player 6. Usage object instanceof class parameters object an actionscript 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. Als...

  • Page 180: Chapter 5

    180 chapter 5: actionscript core language elements interface availability flash player 6. Usage interface interfacename [extends interfacename ] {} description keyword; defines an interface. An interface is similar to a class, with the following important differences: • interfaces contain only decla...

  • Page 181

    Interface 181 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");} } // script file mvar = new d(); trace(mvar.K()); // 15 trace(mvar.N(7)); // 49 trace(mvar.O()); // "o" interface ic extends ia { ...

  • Page 182: Chapter 5

    182 chapter 5: actionscript core language elements 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...

  • Page 183: Chapter 5

    Isnan() 183 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 f...

  • Page 184: Chapter 5

    184 chapter 5: actionscript core language elements 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.Nan chapter 5 actionscript core language...

  • Page 185: Chapter 5

    New 185 new 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;...

  • Page 186: Chapter 5

    186 chapter 5: actionscript core language elements newline availability flash player 4. Usage newline parameters none. Returns nothing. Description constant; inserts a carriage return character ( ) that generates a blank line in text output generated by your code. Use newline to make space for in...

  • Page 187: Chapter 5

    Null 187 null 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 ...

  • Page 188: Chapter 5

    188 chapter 5: actionscript core language elements 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 parame...

  • Page 189: Chapter 5

    Object() 189 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 comm...

  • Page 190: Chapter 5

    190 chapter 5: actionscript core language elements 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 ...

  • Page 191

    On() 191 example in the following script, the startdrag() function executes when the mouse is pressed, and the conditional script is executed when the mouse is released and the object is dropped: on (press) { startdrag(this); } on (release) { trace("x:"+this._x); trace("y:"+this._y); stopdrag(); } s...

  • Page 192: Chapter 5

    192 chapter 5: actionscript core language elements parsefloat() 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 floa...

  • Page 193: Chapter 5

    Parseint() 193 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...

  • Page 194

    194 chapter 5: actionscript core language elements 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().

  • Page 195: Chapter 5

    Private 195 private availability flash player 6. Usage class someclassname{ private var name; private function name() { // your statements here } } parameters name the name of the variable or function that you want to specify as private. Description keyword; specifies that a variable or function is ...

  • Page 196

    196 chapter 5: actionscript core language elements 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. See also public , static.

  • Page 197: Chapter 5

    Public 197 public flash player 6. Usage class someclassname{ public var name; public function name() { // your statements here } } parameters name the name of the variable or function that you want to specify as public. Description keyword; specifies that a variable or function is available to any c...

  • Page 198: Chapter 5

    198 chapter 5: actionscript core language elements return 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,...

  • Page 199: Chapter 5

    Set 199 set availability flash player 6. Usage function set property(varname) { // your statements here } parameters property word that refers to the property that set will access; this value must be the same as the value used in the corresponding get command. Varname the local variable that sets th...

  • Page 200

    200 chapter 5: actionscript core language elements in a fla or as file that is in the same directory as login.As, enter the following actionscript: var gus:login = new login("gus", "smith"); trace(gus.Username); // output: gus gus.Username = "rupert"; trace(gus.Username); // output: rupert in the fo...

  • Page 201: Chapter 5

    Set variable 201 set variable availability flash player 4. Usage set("variablestring", expression) parameters variablestring a string that names a variable to hold the value of the expression parameter. Expression a value assigned to the variable. Returns nothing. Description statement; assigns a va...

  • Page 202

    202 chapter 5: actionscript core language elements the following code loops three times and creates three new variables, called caption0 , caption1 , and caption2 : for (var i = 0; i set("caption"+i, "this is caption "+i); } trace(caption0); trace(caption1); trace(caption2); see also var.

  • Page 203: Chapter 5

    Setinterval() 203 setinterval() availability flash player 6. Usage setinterval(functionname:function, interval:number [, param1:object, param2, ..., paramn]) : number setinterval(objectname:object, methodname:function, interval:number [, param1:object, param2, ..., paramn]) : number parameters funct...

  • Page 204

    204 chapter 5: actionscript core language elements setinterval( callback1, 1000 ); setinterval( callback2, 1000, "interval called" ); 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.Inter...

  • Page 205

    Setinterval() 205 jpeg_mcl.Addlistener(listenerobject); jpeg_mcl.Loadclip("http://www.Macromedia.Com/software/central/images/ klynch_breezo.Jpg", this.Createemptymovieclip("jpeg_mc", this.Getnexthighestdepth())); see also clearinterval().

  • Page 206: Chapter 5

    206 chapter 5: actionscript core language elements static availability flash player 6. Usage class someclassname{ static var name; static function name() { // your statements here } } parameters name the name of the variable or function that you want to specify as static. Description keyword; specif...

  • Page 207: Chapter 5

    " " (string delimiter) 207 " " (string delimiter) 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 va...

  • Page 208: Chapter 5

    208 chapter 5: actionscript core language elements 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 p...

  • Page 209: Chapter 5

    Super 209 super availability flash player 6. Usage super.Method([arg1, ..., argn]) super([arg1, ..., argn]) parameters method the method to invoke in the superclass. Arg1 optional parameters that are passed to the superclass version of the method (syntax 1) or to the constructor function of the supe...

  • Page 210

    210 chapter 5: actionscript core language elements 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 co...

  • Page 211: Chapter 5

    Switch 211 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 ...

  • Page 212

    212 chapter 5: actionscript core language elements case "i" : trace("you pressed i or i"); break; default : trace("you pressed some other key"); } }; key.Addlistener(listenerobj); see also === (strict equality) , break , case , default , if.

  • Page 213: Chapter 5

    This 213 this availability flash player 5. Usage this description identifier; refers to the object in the currently executing scope. If you are in a method and you want a reference to the object instance, use the this identifier. You can also use the this identifier to pass a class instance as an ar...

  • Page 214

    214 chapter 5: actionscript core language elements 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. Ex...

  • Page 215: Chapter 5

    Throw 215 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 or finally block, the string representation of the thrown value is sent to the l...

  • Page 216

    216 chapter 5: actionscript core language elements in a fla or as file, enter the following actionscript: import invalidemailaddress; function checkemail(email:string) { if (email.Indexof("@") == -1) { throw new invalidemailaddress(); } } try { checkemail("joe smith"); } catch (e) { this.Createtextf...

  • Page 217: Chapter 5

    Trace() 217 trace() availability flash player 4. Usage trace(expression) parameters expression an expression to evaluate. Returns nothing. Description you can use flash debug player to capture output from the trace() function and write that output to the log file. Statement; evaluates the expression...

  • Page 218: Chapter 5

    218 chapter 5: actionscript core language elements true 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...

  • Page 219: Chapter 5

    Try..Catch..Finally 219 try..Catch..Finally 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 { // ... ...

  • Page 220

    220 chapter 5: actionscript core language elements 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 a...

  • Page 221

    Try..Catch..Finally 221 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...

  • Page 222

    222 chapter 5: actionscript core language elements function randomnum():number { return math.Round(math.Random()*10)%3; } } 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 erro...

  • Page 223: Chapter 5

    Typeof 223 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 ;...

  • Page 224: Chapter 5

    224 chapter 5: actionscript core language elements undefined 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 v...

  • Page 225: Chapter 5

    Unescape() 225 unescape() 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...

  • Page 226: Chapter 5

    226 chapter 5: actionscript core language elements var availability flash player 5. Usage var variablename [= value1][...,variablenamen [=valuen]] parameters variablename an identifier. Value the value assigned to the variable. Returns nothing. Description statement; used to declare local variables....

  • Page 227: Chapter 5

    Void 227 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 t...

  • Page 228: Chapter 5

    228 chapter 5: actionscript core language elements 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. Descripti...

  • Page 229

    While 229 i += 3; } the following result is written to the log file. 0 3 6 9 12 15 18 see also do while , continue , for , for..In.

  • Page 230: Chapter 5

    230 chapter 5: actionscript core language elements 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. Descript...

  • Page 231

    With 231 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....

  • Page 232: Chapter 6

    232 chapter 6 actionscript core classes this chapter describes functions, properties, and classes of macromedia flash player that you can use in a macromedia flex application. However, many of the items described in this chapter are not for use in typical flex applications and should be used only as...

  • Page 233: Chapter 6

    Accessibility.Isactive() 233 accessibility class 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 ...

  • Page 234

    234 chapter 6: actionscript core classes example the following example checks whether an accessibility aid is currently active: if (accessibility.Isactive()) { trace ("an accessibility aid is currently active"); } else { trace ("there is currently no active accessibility aid"); } see also accessibil...

  • Page 235: Chapter 6

    _accprops 235 _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). Instancename the instance name assigned to an instance of a movie clip, but...

  • Page 236

    236 chapter 6: actionscript core classes to refer to the _accprops object that represents the entire flash document, omit the instancename parameter. The value of _accprops must be an object. This means that if no _accprops object already exists, you must create one, as shown in the following exampl...

  • Page 237: Chapter 6

    Arguments.Callee 237 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 automatica...

  • Page 238

    238 chapter 6: actionscript core classes } } trace(factorial(4)); // output: 24 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 fun...

  • Page 239

    Arguments.Length 239 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 ca...

  • Page 240: Chapter 6

    240 chapter 6: actionscript core classes array class availability flash player 5. 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. Al...

  • Page 241

    Array class 241 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. Element0...Elementn a l...

  • Page 242

    242 chapter 6: actionscript core classes 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.Join(", "));...

  • Page 243

    Array.Join() 243 var alphanumeric_array:array =alpha_array.Concat(numeric_array); trace(alphanumeric_array); // creates array [a,b,c,1,2,3] the following code concatenates three arrays: var num1_array:array = [1,3,5]; var num2_array:array = [2,4,6]; var num3_array:array = [7,8,9]; var nums_array:arr...

  • Page 244

    244 chapter 6: actionscript core classes example the following example creates an array with three elements: earth, moon, and sun. It then joins the array three times—first using the default separator (a comma [,] and a space), then using a dash (-), and then using a plus sign (+). Var a_array:array...

  • Page 245

    Array.Push() 245 my_array[9] = 'c'; trace(my_array.Length); // my_array.Length is updated to 10 trace(my_array); // displays: // a,b,undefined,undefined,undefined,undefined,undefined,undefined,undefined,c // if the length property is now set to 5, the array will be truncated my_array.Length = 5; tra...

  • Page 246

    246 chapter 6: actionscript core classes 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 ....

  • Page 247

    Array.Slice() 247 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 the...

  • Page 248

    248 chapter 6: actionscript core classes description method; returns a new array that consists of a range of elements from the original array, without modifying the original array. The returned array includes the start element and all elements up to, but not including, the end element. If you don’t ...

  • Page 250

    250 chapter 6: actionscript core classes example usage 1: the following example shows the use of array.Sort() with and without a value passed for option : var fruits_array:array = new array("oranges", "apples", "strawberries", "pineapples", "cherries"); trace(fruits_array); // displays oranges,apple...

  • Page 252

    252 chapter 6: actionscript core classes 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 ...

  • Page 253

    Array.Sorton() 253 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 sor...

  • Page 254

    254 chapter 6: actionscript core classes 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_a...

  • Page 255

    Array.Tostring() 255 deletecount an integer that specifies the number of elements to be deleted. This number includes the element specified in the start parameter. If no value is specified for deletecount , the method deletes all the values from the start element to the last element in the array. If...

  • Page 256

    256 chapter 6: actionscript core classes 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 s...

  • Page 257

    Array.Unshift() 257 example the following example shows the use of array.Unshift() : var pets_array:array = new array("dog", "cat", "fish"); trace( pets_array ); // dog,cat,fish pets_array.Unshift("ferrets", "gophers", "engineers"); trace( pets_array ); // ferrets,gophers,engineers,dog,cat,fish.

  • Page 258: Chapter 6

    258 chapter 6: actionscript core classes boolean class availability flash player 5. 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...

  • Page 259

    Boolean.Valueof() 259 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 t...

  • Page 260: Chapter 6

    260 chapter 6: actionscript core classes date class 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. ...

  • Page 261

    Date class 261 date.Setdate() sets the day of the month according to local time. Returns the new time in milliseconds. Date.Setfullyear() sets the full year according to local time. Returns the new time in milliseconds. Date.Sethours() sets the hour according to local time. Returns the new time in m...

  • Page 262

    262 chapter 6: actionscript core classes constructor for the date class availability flash player 5. Usage new date() : date new date(timevalue:number) : date new date(year:number, month:number [, date:number [, hour:number [, minute:number [, second:number [, millisecond:number ]]]]]) : date parame...

  • Page 263

    Date.Getday() 263 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 operati...

  • Page 264

    264 chapter 6: actionscript core classes example the following example creates a new date object and uses getday() to determine the current day of the week : var dayofweek_array:array = new array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"); var today_date:date = new...

  • Page 265

    Date.Getmilliseconds() 265 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. Example the following example uses the constructor t...

  • Page 266

    266 chapter 6: actionscript core classes example the following example uses the constructor to create a date object based on the current time and uses the getmilliseconds() method to return the milliseconds value from that object: var my_date:date = new date(); trace(my_date.Getmilliseconds()); date...

  • Page 267

    Date.Getseconds() 267 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. Example the following example uses the constructor to creat...

  • Page 268

    268 chapter 6: actionscript core classes 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 me...

  • Page 269

    Date.Getutcday() 269 example the following example returns the difference between the local daylight saving time for san francisco and universal time. Daylight saving time is factored into the returned result only if the date defined in the date object occurs during daylight saving time. Var my_date...

  • Page 270

    270 chapter 6: actionscript core classes 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.G...

  • Page 271

    Date.Getutcmilliseconds() 271 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 exam...

  • Page 272

    272 chapter 6: actionscript core classes 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.Getutcminutes() availability flash play...

  • Page 273

    Date.Getyear() 273 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 di...

  • Page 274

    274 chapter 6: actionscript core classes 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...

  • Page 275

    Date.Sethours() 275 date.Setfullyear() availability flash player 5. Usage my_date.Setfullyear(year:number [, month:number [, date:number]]) : number parameters year 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 t...

  • Page 276

    276 chapter 6: actionscript core classes 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 creat...

  • Page 277

    Date.Setmonth() 277 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 mill...

  • Page 278

    278 chapter 6: actionscript core classes example the following example initially creates a new date object, setting the date to may 15, 2004, and uses date.Setmonth() to change the date to june 15, 2004: var my_date:date = new date(2004,4,15); trace(my_date.Getmonth()); //output: 4 my_date.Setmonth(...

  • Page 279

    Date.Setutcdate() 279 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 ...

  • Page 280

    280 chapter 6: actionscript core classes date.Setutcfullyear() availability flash player 5. Usage my_date.Setutcfullyear(year:number [, month:number [, date:number]]) : number parameters year an integer that represents the year specified as a full four-digit year, such as 2000. Month an integer from...

  • Page 281

    Date.Setutcmilliseconds() 281 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 param...

  • Page 282

    282 chapter 6: actionscript core classes 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.Setutcmilliseconds() to change the milliseconds value to 575: var my_date:date = new date(20...

  • Page 283

    Date.Setutcseconds() 283 parameters month an integer from 0 (january) to 11 (december). Date 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 i...

  • Page 284

    284 chapter 6: actionscript core classes my_date.Setutcseconds(45); trace(my_date.Getutcseconds()); // output: 45 date.Setyear() availability flash player 5. Usage my_date.Setyear(year:number) : number parameters year a number that represents the year. If year is an integer between 0–99, setyear set...

  • Page 285

    Date.Utc() 285 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 (dateo...

  • Page 286

    286 chapter 6: actionscript core classes example the following example creates a new marybirthday_date date object defined in universal time. This is the universal time variation of the example used for the new date constructor method. Var marybirthday_date:date = new date(date.Utc(1974, 7, 12)); tr...

  • Page 287: Chapter 6

    Error class 287 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 ...

  • Page 288

    288 chapter 6: actionscript core classes 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..Finally error.Message availability flash player 7. Usage my_err....

  • Page 289

    Error.Tostring() 289 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 t...

  • Page 290

    290 chapter 6: actionscript core classes 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 ...

  • Page 291: Chapter 6

    Function.Apply() 291 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 function.Apply() availability flash player 6. Us...

  • Page 292

    292 chapter 6: actionscript core classes the following simple example shows how apply() passes an array of parameters: function thefunction() { trace(arguments); } // create a new array to pass as a parameter to apply() var firstarray:array = new array(1,2,3); thefunction.Apply(null,firstarray); // ...

  • Page 293

    Function.Call() 293 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. Parameter1 a parameter to be passed to the myfunction . You can specify ze...

  • Page 294

    294 chapter 6: actionscript core classes var obj:object = new myobject(); mymethod.Call(obj, obj); the trace() statement displays: the trace() statement sends the following code to the log file: this == obj? True see also function.Apply().

  • Page 295: Chapter 6

    Key class 295 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 o...

  • Page 296

    296 chapter 6: actionscript core classes listener summary for the key class 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 ...

  • Page 297

    Key.Backspace 297 mylistener.Onkeyup = function () { trace ("you released a key."); } key.Addlistener(mylistener); 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 _accp...

  • Page 298

    298 chapter 6: actionscript core classes }; key.Addlistener(keylistener); 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 ...

  • Page 299

    Key.Deletekey 299 } function myonkeydown() { // 55 is key code for 7 if (key.Isdown(key.Control) && key.Getcode() == 55) { selection.Setfocus(my_btn); my_btn.Onpress(); } } var mylistener:object = new object(); mylistener.Onkeydown = myonkeydown; key.Addlistener(mylistener); my_btn.Onpress = myonpre...

  • Page 300

    300 chapter 6: actionscript core classes }; key.Addlistener(keylistener); 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 consta...

  • Page 301

    Key.Enter 301 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 cl...

  • Page 302

    302 chapter 6: actionscript core classes 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 log file writes information that ...

  • Page 303

    Key.Getcode() 303 example the following example calls the getascii() method any time a key is pressed. The example creates a listener object named keylistener and defines a function that responds to the onkeydown event by calling key.Getascii() . The keylistener object is then registered to the key ...

  • Page 304

    304 chapter 6: actionscript core classes example the following example calls the getcode() method any time a key is pressed. The example creates a listener object named keylistener and defines a function that responds to the onkeydown event by calling key.Getcode() . The keylistener object is then r...

  • Page 305

    Key.Isdown() 305 this.Attachmovie("car_id", "car_mc", this.Getnexthighestdepth(), {_x:0, _y:0}); car_mc.Onpress = function() { this.Startdrag(); }; car_mc.Onrelease = function() { this.Stopdrag(); }; var keylistener:object = new object(); keylistener.Onkeydown = function() { if (key.Isdown(key.Home)...

  • Page 306

    306 chapter 6: actionscript core classes 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 b, “keyboard keys and key code values,” on page 811...

  • Page 307

    Key.Left 307 information is written to the log file when you press the caps lock key. The log file writes either true or false , depending on whether the caps lock is activated using the istoggled method. The following example creates two text fields that update when the caps lock and num lock keys ...

  • Page 308

    308 chapter 6: actionscript core classes break; case key.Right : car_mc._x += distance; break; case key.Down : car_mc._y += distance; break; } }; key.Addlistener(keylistener_obj); key.Onkeydown availability flash player 6. Usage keylistener.Onkeydown description listener; notified when a key is pres...

  • Page 309

    Key.Pgdn 309 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...

  • Page 310

    310 chapter 6: actionscript core classes 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 k...

  • Page 311

    Key.Right 311 switch (key.Getcode()) { case key.Left : car_mc._x -= 10; break; case key.Right : car_mc._x += 10; break; case key.Escape : key.Removelistener(keylistener); } }; key.Addlistener(keylistener); key.Right availability flash player 5. Usage key.Right:number description property; constant a...

  • Page 312

    312 chapter 6: actionscript core classes 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(); ke...

  • Page 313

    Key.Up 313 case key.Left : car_mc._x -= distance; break; case key.Up : car_mc._y -= distance; break; case key.Right : car_mc._x += distance; break; case key.Down : car_mc._y += distance; break; } }; key.Addlistener(keylistener_obj); key.Tab availability flash player 5. Usage key.Tab:number descripti...

  • Page 314

    314 chapter 6: actionscript core classes 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...

  • Page 315: Chapter 6

    Loadvars class 315 loadvars class availability flash player 6. Description 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 ...

  • Page 316

    316 chapter 6: actionscript core classes property summary for the loadvars class event handler summary for the loadvars class constructor for the loadvars class availability flash player 6. Usage new loadvars() : loadvars parameters none. Returns a reference to a loadvars object. Description constru...

  • Page 317

    Loadvars.Addrequestheader() 317 parameters headername a string that represents an http request header name. Headervalue a string that represents the value associated with headername . Returns nothing. Description method; adds or changes http request headers (such as content-type or soapaction ) sent...

  • Page 318

    318 chapter 6: actionscript core classes 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...

  • Page 319

    Loadvars.Getbytesloaded() 319 trace(my_lv.Tostring()); // iterate over properties in my_lv for (var prop in my_lv) { trace(prop+" -> "+my_lv[prop]); } see also loadvars.Ondata , xml.Parsexml() loadvars.Getbytesloaded() availability flash player 6. Usage my_lv.Getbytesloaded() : number parameters non...

  • Page 320

    320 chapter 6: actionscript core classes my_lv.Onload = function(success:boolean) { loadvars_pb.Setprogress(my_lv.Getbytesloaded(), my_lv.Getbytestotal()); delete timer_mc.Onenterframe; if (success) { trace("loadvars loaded successfully."); } else { trace("an error occurred while loading variables."...

  • Page 321

    Loadvars.Load() 321 trace("loaded "+lvbytesloaded+" of "+lvbytestotal+" bytes."); loadvars_pb.Setprogress(lvbytesloaded, lvbytestotal); } }; my_lv.Onload = function(success:boolean) { loadvars_pb.Setprogress(my_lv.Getbytesloaded(), my_lv.Getbytestotal()); delete timer_mc.Onenterframe; if (success) {...

  • Page 322

    322 chapter 6: actionscript core classes var my_lv:loadvars = new loadvars(); my_lv.Onload = function(success:boolean) { if (success) { 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 “u...

  • Page 323

    Loadvars.Ondata 323 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 loadvars.Sendandload() method call. Returns nothing. Description event handl...

  • Page 324

    324 chapter 6: actionscript core classes 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 bool...

  • Page 325

    Loadvars.Sendandload() 325 returns a boolean value; false if no parameters are specified, true otherwise. Description method; sends the variables in the my_lv object to the specified url. All enumerable variables in my_lv are concatenated into a string in the application/x-www-form-urlencoded format...

  • Page 326

    326 chapter 6: actionscript core classes parameters url 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” . Targetobject loadvars; the loadvars object that rece...

  • Page 327

    Loadvars.Tostring() 327 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.Name = "gary"; my_lv.Age = 26; trace (my_lv.Tostring...

  • Page 328: Chapter 6

    328 chapter 6: actionscript core classes localconnection class 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 f...

  • Page 329

    Localconnection class 329 event handler summary for the localconnection class constructor for the localconnection class availability flash player 6. Usage new localconnection() : localconnection parameters none. Returns a reference to a localconnection object. Description constructor; creates a loca...

  • Page 330

    330 chapter 6: actionscript core classes }; receiving_lc.Connect("lc_name"); the following swf file sends the request to the first swf file. // code in the sending swf file var sending_lc:localconnection = new localconnection(); sending_lc.Send("lc_name", "methodtoexecute", 5, 7); see also localconn...

  • Page 331

    Localconnection.Allowdomain 331 in files authored for flash player 6, the sendingdomain parameter contains the superdomain of the caller. In files authored for flash player 7 or later, the sendingdomain parameter contains the exact domain of the caller. In the latter case, to allow access by swf fil...

  • Page 332

    332 chapter 6: actionscript core classes domain_txt.Text = sendingdomain; return true; }; my_lc.Allowinsecuredomain = function(sendingdomain:string) { return (sendingdomain == this.Domain()); } my_lc.Sayhello = function(name:string) { welcome_txt.Text = "hello, "+name; }; my_lc.Connect("_mylc"); the...

  • Page 333

    Localconnection.Allowinsecuredomain 333 localconnection.Allowinsecuredomain availability flash player 7. Usage receiving_lc.Allowinsecuredomain = function([sendingdomain:string]) : boolean { // your statements here return true or false } parameters sendingdomain a string that represents an optional ...

  • Page 334

    334 chapter 6: actionscript core classes }; 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 , localcon...

  • Page 335

    Localconnection.Connect() 335 }; close_button.Addeventlistener("click", closelistener); see also localconnection.Connect() localconnection.Connect() availability flash player 6. Usage receiving_lc.Connect(connectionname:string) : boolean parameters connectionname a string that corresponds to the con...

  • Page 336

    336 chapter 6: actionscript core classes 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...

  • Page 337

    Localconnection.Domain() 337 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; playbac...

  • Page 338

    338 chapter 6: actionscript core classes 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 f...

  • Page 339

    Localconnection.Domain() 339 line numbers are included for reference purposes. The sequence of events is described in the following list: • the receiving swf file prepares to receive commands on a connection named "sum" (line 11). The flash player resolves the name of this connection to "mydomain.Co...

  • Page 340

    340 chapter 6: actionscript core classes 60 var domainarray:array = channeldomain.Split("."); // if more than two elements are found, // chop off first element to create superdomain 61 if (domainarray.Length > 2) 62 { 63 domainarray.Shift(); 64 channeldomain = domainarray.Join("."); 65 } 66 } 67 lc....

  • Page 341

    Localconnection.Send() 341 if the information object returned by this event handler contains a level value of error , flash cannot send the command to a receiving localconnection object, most likely because there is no receiving localconnection object connected whose name corresponds to the name spe...

  • Page 342

    342 chapter 6: actionscript core classes method a string specifying the name of the method to be invoked in the receiving localconnection object. The following method names cause the command to fail: send , connect , close , domain , onstatus , and allowdomain . P1,...Pn optional parameters to be pa...

  • Page 343

    Localconnection.Send() 343 see also localconnection.Allowdomain , localconnection.Connect() , localconnection.Domain() , localconnection.Onstatus.

  • Page 344: Chapter 6

    344 chapter 6: actionscript core classes 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 ...

  • Page 345

    Math.Abs() 345 property summary for the math class all the following properties for the math class are constants: 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...

  • Page 346

    346 chapter 6: actionscript core classes example the following example shows how math.Abs() returns the absolute value of a number and does not affect the value of the x parameter (called num in this example): var num:number = -12; var numabsolute:number = math.Abs(num); trace(num); // output: -12 t...

  • Page 347

    Math.Atan() 347 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. Example the following example displays the arc sine ...

  • Page 348

    348 chapter 6: actionscript core classes see also math.Acos() , math.Asin() , math.Atan2() , math.Cos() , math.Sin() , math.Tan() 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 a...

  • Page 349

    Math.Cos() 349 description method; returns the ceiling of the specified number or expression. The ceiling of a number is the closest integer that is greater than or equal to the number. Example the following code returns a value of 13: math.Ceil(12.5); see also math.Floor() , math.Round() math.Cos()...

  • Page 350

    350 chapter 6: actionscript core classes 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...

  • Page 351

    Math.Log() 351 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.E can provide the value of e. Example the following example displays the logarithm for two number values. Trace(math.Exp(1)); /...

  • Page 352

    352 chapter 6: actionscript core classes 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 . Example the following example displays the logarithm for three numerical values. Trace(math.Log(...

  • Page 353

    Math.Log10e 353 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 not...

  • Page 354

    354 chapter 6: actionscript core classes 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...

  • Page 355

    Math.Pi 355 description method; evaluates x and y and returns the smaller value. Example the following example displays sat dec 25 00:00:00 gmt-0700 2004 , which is the smaller of the evaluated expressions. Var date1:date = new date(2004, 11, 25); var date2:date = new date(2004, 11, 30); var mindate...

  • Page 356

    356 chapter 6: actionscript core classes mc.Curveto(-math.Tan(math.Pi/8)*r+x, -r+y, x, -r+y); mc.Curveto(math.Tan(math.Pi/8)*r+x, -r+y, math.Sin(math.Pi/4)*r+x, - math.Sin(math.Pi/4)*r+y); mc.Curveto(r+x, -math.Tan(math.Pi/8)*r+y, r+x, y); } math.Pow() availability flash player 5. In flash player 4,...

  • Page 357

    Math.Round() 357 }; mouse.Addlistener(mouselistener); 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....

  • Page 358

    358 chapter 6: actionscript core classes 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. If parameter x is equidistant from its two nearest integers (that is, the number ends in .5), the value is rounded u...

  • Page 359

    Math.Sqrt() 359 mc.Moveto(x+r, y); mc.Curveto(r+x, math.Tan(math.Pi/8)*r+y, math.Sin(math.Pi/4)*r+x, math.Sin(math.Pi/4)*r+y); mc.Curveto(math.Tan(math.Pi/8)*r+x, r+y, x, r+y); mc.Curveto(-math.Tan(math.Pi/8)*r+x, r+y, -math.Sin(math.Pi/4)*r+x, math.Sin(math.Pi/4)*r+y); mc.Curveto(-r+x, math.Tan(mat...

  • Page 360

    360 chapter 6: actionscript core classes var line_mc:movieclip = canvas_mc.Createemptymovieclip("line"+nextdepth+"_mc", nextdepth); line_mc.Moveto(this.Origx, this.Origy); line_mc.Linestyle(2, 0x000000, 100); line_mc.Lineto(this.Newx, this.Newy); var hyplen:number = math.Sqrt(math.Pow(line_mc._width...

  • Page 361

    Math.Tan() 361 trace(math.Sqrt2); // output: 1.4142135623731 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 m...

  • Page 362: Chapter 6

    362 chapter 6: actionscript core classes mouse class 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 sw...

  • Page 363

    Mouse.Onmousedown 363 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...

  • Page 364

    364 chapter 6: actionscript core classes 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 ...

  • Page 365

    Mouse.Onmousemove 365 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 onmousemov...

  • Page 366

    366 chapter 6: actionscript core classes 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 func...

  • Page 367

    Mouse.Onmousewheel 367 mouse.Onmousewheel availability flash player 6 (windows only). Usage somelistener.Onmousewheel = function ( [ delta [, scrolltarget ] ] ) { // your statements here } parameters delta an optional number indicating how many lines should be scrolled for each notch the user rolls ...

  • Page 368

    368 chapter 6: actionscript core classes mouselistener.Onmousewheel = function(delta:number) { line_mc._rotation += delta; }; mouselistener.Onmousedown = function() { trace("down"); }; mouse.Addlistener(mouselistener); see also mouse.Addlistener() , textfield.Mousewheelenabled mouse.Removelistener()...

  • Page 369

    Mouse.Show() 369 mouselistener.Onmousedown = function() { this.Isdrawing = true; canvas_mc.Linestyle(2, 0xff0000, 100); canvas_mc.Moveto(_xmouse, _ymouse); }; mouselistener.Onmousemove = function() { if (this.Isdrawing) { canvas_mc.Lineto(_xmouse, _ymouse); } updateafterevent(); }; mouselistener.Onm...

  • Page 370

    370 chapter 6: actionscript core classes description method; displays the mouse pointer in a swf file. The pointer is visible by default. Example the following example attaches a custom cursor from the library when it rolls over a movie clip called my_mc . Give a movie clip a linkage identifier of c...

  • Page 371: Chapter 6

    Number class 371 number class 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 prope...

  • Page 372

    372 chapter 6: actionscript core classes constructor for the number class availability flash player 5. Usage new number(value:number) : number parameters value 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...

  • Page 373

    Number.Negative_infinity 373 this code logs the following values: number.Min_value = 4.94065645841247e-324 number.Max_value = 1.79769313486232e+308 number.Min_value availability flash player 5. Usage number.Min_value description property; the smallest representable number (double-precision ieee-754)...

  • Page 374

    374 chapter 6: actionscript core classes 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 functi...

  • Page 375

    Number.Valueof() 375 parameters radix 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. Returns a string. Description method; returns the string representation of the specified number object ( myn...

  • Page 376: Chapter 6

    376 chapter 6: actionscript core classes 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 ...

  • Page 377

    Object.Addproperty() 377 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. Example the following example creates a generic object named myobject: var myobject:obje...

  • Page 378

    378 chapter 6: actionscript core classes you can add getter/setter properties to prototype objects. If you add a getter/setter property to a prototype object, all object instances that inherit the prototype object inherit the getter/setter property. This makes it possible to add a getter/setter prop...

  • Page 379

    Object.Addproperty() 379 the previous example works, but the properties bookcount and bookname are added to every instance of the book object, which requires having two properties for every instance of the object. If there are many properties, such as bookcount and bookname, in a class, they could c...

  • Page 380

    380 chapter 6: actionscript core classes 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 th...

  • Page 381

    Object.__resolve 381 object.Registerclass() availability flash player 6. Usage object.Registerclass(symbolid:string, theclass:function) : boolean parameters symbolid string; the linkage identifier of the movie clip symbol or the string identifier for the actionscript class. Theclass a reference to t...

  • Page 382

    382 chapter 6: actionscript core classes this property is useful for enabling highly transparent client/server communication, and is the recommended way of invoking server-side methods. Example the following examples progressively build upon the first example and illustrate five different usages of ...

  • Page 383

    Object.__resolve 383 // define the __resolve function myobject.__resolve = function(name) { 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.Myfunction(name); }; // create a new ...

  • Page 384

    384 chapter 6: actionscript core classes // define a generic function for __resolve to call myobject.Myfunction = function (name) { arguments.Shift(); trace("method " + name + " was called with arguments: " + arguments.Join(',')); }; // define the __resolve function myobject.__resolve = function (na...

  • Page 385

    Object.Tostring() 385 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. The following examples show that this meth...

  • Page 386

    386 chapter 6: actionscript core classes trace(myvehicle.Valueof()); // output: a vehicle that is red and has 2 doors 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 watche...

  • Page 387

    Object.Watch() 387 example the following example shows the return value of valueof() for a generic object (which does not have a primitive value) and compares it to the return value of tostring(): // create a generic object var myobject:object = new object(); trace(myobject.Valueof()); // output: [o...

  • Page 388

    388 chapter 6: actionscript core classes description method; registers an event handler to be invoked when a specified property of an actionscript object changes. When the property changes, the event handler is invoked with myobject as the containing object. Your can use the return statement in your...

  • Page 389

    Object.Watch() 389 var speedwatcher:function = function(prop, oldval, newval, speedlimit) { // check whether speed is above the limit if (newval > speedlimit) { trace ("you are speeding."); } else { trace ("you are not speeding."); } // return the value of newval. Return newval; } // use watch() to ...

  • Page 390: Chapter 6

    390 chapter 6: actionscript core classes 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 dynam...

  • Page 391

    Printjob.Addpage() 391 // display print dialog box, but only initiate the print job // if start returns successfully. If (my_pj.Start()) { // use a variable to track successful calls to addpage var pagestoprint:number = 0; // add specified area to print job // repeat once for each page to be printed...

  • Page 392

    392 chapter 6: actionscript core classes parameters target 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. Printarea an...

  • Page 393

    Printjob.Addpage() 393 returns a boolean value: true if the page is successfully sent to the print spooler; false otherwise. Description method; sends the specified level or movie clip as a single page to the print spooler. Before using this method, you must use printjob.Start() ; after calling prin...

  • Page 394

    394 chapter 6: actionscript core classes pagecount++; // starting at 0,0, print an area 400 pixels wide and 500 pixels high // of frame 1 of the _root movie in bitmap format if (my_pj.Addpage(0, {xmin:0,xmax:400,ymin:0,ymax:500}, {printasbitmap:true}, 1)){ pagecount++; // starting 50 pixels to the r...

  • Page 395

    Printjob.Start() 395 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 re...

  • Page 396

    396 chapter 6: actionscript core classes 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.Start() method returns successfully, the following read-only properties are populated, rep...

  • Page 397

    Printjob.Start() 397 // check the user's printer orientation setting // and add appropriate print area to print job if (my_pj.Orientation == "portrait") { // here, the printarea measurements are appropriate for an 8.5" x 11" // portrait page. Pageadded = my_pj.Addpage(this,{xmin:0,xmax:600,ymin:0,ym...

  • Page 398: Chapter 6

    398 chapter 6: actionscript core classes sharedobject class 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 o...

  • Page 399

    Sharedobject.Clear() 399 • 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...

  • Page 400

    400 chapter 6: actionscript core classes 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...

  • Page 401

    Sharedobject.Data 401 var my_so:sharedobject = sharedobject.Getlocal("superfoo"); my_so.Data.Itemnumbers = items_array; my_so.Data.Adminprivileges = currentuserisadmin; my_so.Data.Username = currentusername; for (var prop in my_so.Data) { trace(prop+": "+my_so.Data[prop]); } all attributes of a shar...

  • Page 402

    402 chapter 6: actionscript core classes sharedobject.Flush() availability flash player 6. Usage mylocalsharedobject.Flush([minimumdiskspace:number]) : boolean parameters minimumdiskspace an optional integer specifying the number of bytes that must be allotted for this object. The default value is 0...

  • Page 403

    Sharedobject.Getlocal() 403 example the following function gets a shared object, my_so, and fills writable properties with user- provided settings. Finally, flush() is called to save the settings and allot a minimum of 1000 bytes of disk space. This.Syncsettingscore = function(soname:string, overrid...

  • Page 404

    404 chapter 6: actionscript core classes description method; returns a reference to a locally persistent shared object that is available only to the current client. Note: if the user has selected to never allow local storage for this domain, the object is not saved locally, even if a value for local...

  • Page 405

    Sharedobject.Getsize() 405 textlistener.Enter = function(eventobj:object) { my_so.Data.Mytextsaved = eventobj.Target.Text; my_so.Flush(); }; // register listener with textinput component instance mytext_ti.Addeventlistener("enter", textlistener); sharedobject.Getsize() availability flash player 6. U...

  • Page 406

    406 chapter 6: actionscript core classes 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 handl...

  • Page 407

    Sharedobject.Onstatus 407 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:s...

  • Page 408: Chapter 6

    408 chapter 6: actionscript core classes 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 manip...

  • Page 409

    String.Charat() 409 property summary for the string class constructor for the string class availability flash player 5. Usage new string(value:string) : string parameters value the initial value of the new string object. Returns a reference to a string object. Description constructor; creates a new ...

  • Page 410

    410 chapter 6: actionscript core classes parameters index 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 . Returns a character. Description method; returns the character in the ...

  • Page 411

    String.Fromcharcode() 411 example in the following example, this method is called on the first letter of the string "chris" : var my_str:string = "chris"; var firstchar_num:number = my_str.Charcodeat(0); trace(firstchar_num); // output: 67 see also string.Charat() string.Concat() availability flash ...

  • Page 412

    412 chapter 6: actionscript core classes 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.Fromcharc...

  • Page 413

    String.Lastindexof() 413 index = searchstring.Indexof("i", 7); trace(index); // output: 19 index = searchstring.Indexof("z"); trace(index); // output: -1 see also string.Lastindexof() string.Lastindexof() availability flash player 5. Usage my_str.Lastindexof(substring:string, [startindex:number]) : ...

  • Page 414

    414 chapter 6: actionscript core classes index = searchstring.Lastindexof("i", 18); trace(index); // output: 6 index = searchstring.Lastindexof("z"); trace(index); // output: -1 see also string.Indexof() string.Length availability flash player 5. Usage my_str.Length:number description property; an i...

  • Page 415

    String.Slice() 415 string.Slice() availability flash player 5. Usage my_str.Slice(start:number, [end:number]) : string parameters start 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, wher...

  • Page 416

    416 chapter 6: actionscript core classes // 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 see also string.Substr() , string.Substring() string.Split() availability flas...

  • Page 417

    String.Substr() 417 the following example shows that if you use an empty string ( "" ) for the delimiter parameter, each character in the string is placed as an element in the array: var my_str:string = new string("joe"); var my_array:array = my_str.Split(""); for (var i = 0; i trace(my_array[i]); }...

  • Page 418

    418 chapter 6: actionscript core classes string.Substring() availability flash player 5. Usage my_str.Substring(start:number, [end:number]) : string parameters start a number; an integer that indicates the position of the first character of my_str used to create the substring. Valid values for start...

  • Page 419

    String.Touppercase() 419 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. Example th...

  • Page 420

    420 chapter 6: actionscript core classes 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.Touppercase(); trace("lowercase: " + lowerca...

  • Page 421: Chapter 6

    System.Exactsettings 421 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...

  • Page 422

    422 chapter 6: actionscript core classes if this value is true , the settings and data for a swf file hosted at here.Xyz.Com are stored in a directory called here.Xyz.Com, the settings and data for a swf file hosted at there.Xyz.Com are stored in a directory called there.Xyz.Com, and so on. If this ...

  • Page 423

    System.Setclipboard() 423 in addition to these specific onstatus methods, flash also provides a super function called system.Onstatus , which serves as a secondary error message handler. If an instance of the localconnection, netstream, or sharedobject class passes an information object with a level...

  • Page 424

    424 chapter 6: actionscript core classes description method; replaces the contents of the clipboard with a specified text string. Note: because of security concerns, it is not possible to read the contents of the system clipboard. In other words, there is no corresponding system.Getclipboard() metho...

  • Page 425

    System.Usecodepage 425 returns nothing. Description method; shows the specified flash player settings panel, which lets users do any of the following actions: • allow or deny access to the camera and microphone • specify the local disk space available for shared objects • select a default camera and...

  • Page 426

    426 chapter 6: actionscript core classes if you load external text files that are not unicode-encoded, you should set system.Usecodepage to true . Add the following code as the first line of code in the swf file that is loading the data: system.Usecodepage = true; when this code is present, flash pl...

  • Page 427: Chapter 6

    System.Capabilities object 427 system.Capabilities object 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...

  • Page 428

    428 chapter 6: actionscript core classes 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 ...

  • Page 429

    System.Capabilities.Hasaudio 429 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 prohibit...

  • Page 430

    430 chapter 6: actionscript core classes 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.Ca...

  • Page 431

    System.Capabilities.Hasscreenbroadcast 431 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...

  • Page 432

    432 chapter 6: actionscript core classes example the following example traces the value of this read-only property: trace(system.Capabilities.Hasscreenbroadcast); system.Capabilities.Hasscreenplayback availability flash player 6 r79. Usage system.Capabilities.Hasscreenplayback:boolean description re...

  • Page 433

    System.Capabilities.Isdebugger 433 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); ...

  • Page 434

    434 chapter 6: actionscript core classes 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 speci...

  • Page 435

    System.Capabilities.Manufacturer 435 example the following example traces the value of this read-only property: trace(system.Capabilities.Language); system.Capabilities.Localfilereaddisable availability flash player 7. Usage system.Capabilities.Localfilereaddisable:boolean description read-only prop...

  • Page 436

    436 chapter 6: actionscript core classes 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 trac...

  • Page 437

    System.Capabilities.Screendpi 437 system.Capabilities.Playertype availability flash player 7. Usage system.Capabilities.Playertype;string description read-only property; a string that indicates the type of player. This property can have one of the following values: • "standalone" for the flash stand...

  • Page 438

    438 chapter 6: actionscript core classes 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.Screendpi); sys...

  • Page 439

    System.Capabilities.Version 439 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...

  • Page 440: Chapter 6

    440 chapter 6: actionscript core classes system.Security object 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 system.Security.Allowdomain() availabil...

  • Page 441

    System.Security.Allowinsecuredomain() 441 // corresponding commands to allow access by swf files // that are running in flash player 7 or later system.Security.Allowdomain("www.Domain.Com", "store.Domain.Com"); also, for files running in flash player 7 or later, you can’t use this method to let swf ...

  • Page 442

    442 chapter 6: actionscript core classes 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. It also lets the swf files in the identified domains access any other ...

  • Page 443

    System.Security.Loadpolicyfile() 443 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 mecha...

  • Page 444

    444 chapter 6: actionscript core classes a policy file served by an xmlsocket server has the same syntax as any other policy file, except that it must also specify the ports to which access is granted. When a policy file comes from a port lower than 1024, it can grant access to any ports; when a pol...

  • Page 445: Chapter 6

    Xml class 445 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()...

  • Page 446

    446 chapter 6: actionscript core classes property summary for the xml class collections summary for the xml class event handler 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...

  • Page 447

    Xml.Addrequestheader() 447 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 u...

  • Page 448

    448 chapter 6: actionscript core classes returns nothing. Description method; adds or changes http request headers (such as content-type or soapaction ) sent with post actions. In the first usage, you pass two strings to the method: headername and headervalue . In the second usage, you pass an array...

  • Page 449

    Xml.Appendchild() 449 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. If the node to be appended already exists in another tree structure, appending ...

  • Page 450

    450 chapter 6: actionscript core classes 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 in...

  • Page 451

    Xml.Clonenode() 451 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.Inse...

  • Page 452

    452 chapter 6: actionscript core classes parameters deep a boolean value; if set to true , the children of the specified xml object will be recursively cloned. Returns an xmlnode object. Description method; constructs and returns a new xml node of the same type, name, value, and attributes as the sp...

  • Page 453

    Xml.Contenttype 453 // // 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, to rootnode rootnode.Appendchild(rootclone); trace(rootnode); // output (with line breaks added): //...

  • Page 454

    454 chapter 6: actionscript core classes 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 s...

  • Page 455

    Xml.Createtextnode() 455 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 refe...

  • Page 456

    456 chapter 6: actionscript core classes 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...

  • Page 457

    Xml.Getbytesloaded() 457 example the following example shows how to use xml.Firstchild to loop through a node’s child nodes: // create a new xml document var doc:xml = new xml(); // create a root node var rootnode:xmlnode = doc.Createelement("rootnode"); // create three child nodes var oldest:xmlnod...

  • Page 458

    458 chapter 6: actionscript core classes 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 s...

  • Page 459

    Xml.Haschildnodes() 459 description method; returns the size, in bytes, of the xml document. Example see example for xml.Getbytesloaded() . See also xml.Getbytesloaded() xml.Haschildnodes() availability flash player 5. Usage my_xml.Haschildnodes() : boolean parameters none. Returns a boolean value. ...

  • Page 460

    460 chapter 6: actionscript core classes 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 o...

  • Page 461

    Xml.Insertbefore() 461 /* 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 prope...

  • Page 462

    462 chapter 6: actionscript core classes see also xmlnode class 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 ...

  • Page 463

    Xml.Load() 463 */ 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(" rootnode>"); var rootnode:xmlnode = doc.Firstchild; // use lastchild to iterate through the c...

  • Page 464

    464 chapter 6: actionscript core classes the value you pass for the url parameter must be in exactly the same domain. For example, a swf file at www.Somedomain.Com can load data only from sources that are also at www.Somedomain.Com. If you want to load data from a different domain, you can place a c...

  • Page 465

    Xml.Nextsibling 465 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.Status); }; my_xm...

  • Page 466

    466 chapter 6: actionscript core classes 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 ...

  • Page 467

    Xml.Nodetype 467 trace(anode.Nodename+":\t"+anode.Firstchild.Nodevalue); } } } the following node names write to the log file: output: username:hank password:rudolph see also xml.Nodetype xml.Nodetype availability flash player 5. Usage my_xml.Nodetype:number description read-only property; a nodetyp...

  • Page 468

    468 chapter 6: actionscript core classes example the following example creates an element node and a text node, and checks the node type of each: // create an xml document var doc:xml = new xml(); // create an xml node using createelement() var mynode:xmlnode = doc.Createelement("rootnode"); // plac...

  • Page 469

    Xml.Nodevalue 469 var mynode:xmlnode = doc.Createelement("rootnode"); // place the new node into the xml tree doc.Appendchild(mynode); // create an xml text node using createtextnode() var mytextnode:xmlnode = doc.Createtextnode("mytextnode"); // place the new node into the xml tree mynode.Appendchi...

  • Page 470

    470 chapter 6: actionscript core classes 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; ...

  • Page 471

    Xml.Parentnode 471 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 t...

  • Page 472

    472 chapter 6: actionscript core classes 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() , insertb...

  • Page 473

    Xml.Previoussibling 473 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. Example the following example creates and parses an xml packet: var xml_str:strin...

  • Page 474

    474 chapter 6: actionscript core classes 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 crea...

  • Page 475

    Xml.Sendandload() 475 parameters url string; the destination url for the specified xml object. Window string; the browser window to show data that the server returns: • _self specifies the current frame in the current window. • _blank specifies a new window. • _parent specifies the parent of the cur...

  • Page 476

    476 chapter 6: actionscript core classes returns nothing. Description method; encodes the specified xml object into an xml document, sends it to the specified url using the post method, downloads the server’s response, and loads it into the targetxmlobject specified in the parameters. The server res...

  • Page 477

    Xml.Status 477 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...

  • Page 478

    478 chapter 6: actionscript core classes 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...

  • Page 479

    Xml.Xmldecl 479 for top-level xml objects (those created with the constructor), the xml.Tostring() method outputs the document’s xml declaration (stored in the xml.Xmldecl property), followed by the document’s doctype declaration (stored in the xml.Doctypedecl property), followed by the text represe...

  • Page 480

    480 chapter 6: actionscript core classes var my_xml:xml = new xml(); my_xml.Ignorewhite = true; my_xml.Onload = function(success:boolean) { var endtime:number = gettimer(); var elapsedtime:number = endtime-starttime; if (success) { my_txt.Text = "xmldecl:"+newline+my_xml.Xmldecl+newline+newline; my_...

  • Page 481: Chapter 6

    Xmlnode class 481 xmlnode class 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 informa...

  • Page 482: Chapter 6

    482 chapter 6: actionscript core classes xmlsocket class 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 ...

  • Page 483

    Xmlsocket.Close() 483 method summary for the xmlsocket class event handler summary for the xmlsocket class constructor for the xmlsocket class availability flash player 5. Usage new xmlsocket() : xmlsocket parameters none. Returns a reference to an xmlsocket object. Description constructor; creates ...

  • Page 484

    484 chapter 6: actionscript core classes 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:xmlsocke...

  • Page 485

    Xmlsocket.Connect() 485 if you specify null for the host parameter, the host contacted is the one where the swf file calling xmlsocket.Connect() resides. For example, if the swf file was downloaded from www.Yoursite.Com, specifying null for the host parameter is the same as entering the ip address f...

  • Page 486

    486 chapter 6: actionscript core classes 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 implementa...

  • Page 487

    Xmlsocket.Ondata 487 description event handler; invoked by flash player when a connection request initiated through xmlsocket.Connect() has succeeded or failed. If the connection succeeded, the success parameter is true ; otherwise the success parameter is false . The default implementation of this ...

  • Page 488

    488 chapter 6: actionscript core classes 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; invo...

  • Page 489

    Xmlsocket.Send() 489 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...

  • Page 490: Chapter 7

    490 chapter 7 actionscript for flash this chapter describes functions, properties, and classes of macromedia flash player that you can use in a macromedia flex application. However, many items described in this chapter are not for use in typical flex applications and should be used only as necessary...

  • Page 491: Chapter 7

    Asfunction 491 asfunction availability flash player 5. Usage asfunction:function:function,"parameter":string parameters function an identifier for a function. Parameter a string that is passed to the function named in the function parameter. Returns nothing. Description protocol; a special protocol ...

  • Page 492: Chapter 7

    492 chapter 7: actionscript for flash 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 t...

  • Page 493

    Camera.Activitylevel 493 event handler summary for the camera class constructor for the camera class see camera.Get() . 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 came...

  • Page 494

    494 chapter 7: actionscript for flash example the following example detects the amount of motion the camera detects using the activitylevel property: // video instance on the stage. Var my_video:video; var activity_pb:mx.Controls.Progressbar; var my_cam:camera = camera.Get(); my_video.Attachvideo(my...

  • Page 495

    Camera.Currentfps 495 // bandwidth_nstep.Minimum = 0; bandwidth_nstep.Maximum = 128; bandwidth_nstep.Stepsize = 16; bandwidth_nstep.Value = my_cam.Bandwidth/1024; function changebandwidth(evt:object) { my_cam.Setquality(evt.Target.Value*1024, 0); } bandwidth_nstep.Addeventlistener("change", changeba...

  • Page 496

    496 chapter 7: actionscript for flash 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,...

  • Page 497

    Camera.Get() 497 parameters index 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. Returns • if index is not specified, t...

  • Page 498

    498 chapter 7: actionscript for flash if camera.Get returns null , either the camera is in use by another application, or there are no cameras installed on the system. To determine whether any cameras are installed, use camera.Names.Length . To display the flash player camera settings panel, which l...

  • Page 499

    Camera.Index 499 var my_cam:camera = camera.Get(); var my_video:video; my_video.Attachvideo(my_cam); var dimensions_lbl:mx.Controls.Label; dimensions_lbl.Setstyle("fontsize", 9); dimensions_lbl.Setstyle("fontweight", "bold"); dimensions_lbl.Setstyle("textalign", "center"); dimensions_lbl.Text = "wid...

  • Page 500

    500 chapter 7: actionscript for flash see also camera.Get() , camera.Names 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 v...

  • Page 501

    Camera.Motiontimeout 501 /* if isactive equals true, set the themecolor variable to "halogreen". Otherwise set the themecolor to "haloorange". */ var themecolor:string = (isactive) ? "halogreen" : "haloorange"; motion_pb.Setstyle("themecolor", themecolor); }; function changemotionlevel() { /* set th...

  • Page 502

    502 chapter 7: actionscript for flash motion_pb.Label = "motion is above "+my_cam.Motionlevel; } else { motion_pb.Setstyle("themecolor", "haloorange"); motion_pb.Label = "motion is below "+my_cam.Motionlevel; } }; function changemotiontimeout() { my_cam.Setmotionlevel(my_cam.Motionlevel, motiontimeo...

  • Page 503

    Camera.Names 503 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 writes the name of the default camera to the log file. In w...

  • Page 504

    504 chapter 7: actionscript for flash example the following example uses the default camera unless more than one camera is available, in which case the user can choose which camera to set as the default camera. If only one camera is present, then the default camera is used. Var my_video:video; var c...

  • Page 505

    Camera.Onstatus 505 trace(mode); } see also camera.Onactivity , camera.Setmotionlevel() 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. R...

  • Page 506

    506 chapter 7: actionscript for flash switch (infoobj.Code) { case 'camera.Muted' : trace("camera access is denied"); break; case 'camera.Unmuted' : trace("camera access granted"); break; } }; see also camera.Get() , camera.Muted , system.Showsettings() ; system.Onstatus camera.Quality availability ...

  • Page 507

    Camera.Setmode() 507 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 defa...

  • Page 508

    508 chapter 7: actionscript for flash var my_video:video; my_video.Attachvideo(my_cam); fps_ti.Maxchars = 2; fps_ti.Restrict = [0-9]; fps_lbl.Text = "current: "+my_cam.Fps+" fps"; function changefps():void { my_cam.Setmode(my_cam.Width, my_cam.Height, fps_ti.Text); fps_lbl.Text = "current: "+my_cam....

  • Page 509

    Camera.Setquality() 509 • to determine the amount of motion the camera is currently detecting, use the camera.Activitylevel property. Motion sensitivity values correspond directly to activity values. Complete lack of motion is an activity value of 0. Constant motion is an activity value of 100. Your...

  • Page 510

    510 chapter 7: actionscript for flash parameters bandwidth 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 b...

  • Page 511

    Camera.Width 511 see also camera.Bandwidth , camera.Get() , camera.Quality 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 follow...

  • Page 512: Chapter 7

    512 chapter 7: actionscript for flash 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 c...

  • Page 513

    Color.Gettransform() 513 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 c...

  • Page 514

    514 chapter 7: actionscript for flash 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: var my_color:color = new color(my_mc); var mytransform:object = my_color.Gettransform(); mytransform = { ra: 50...

  • Page 515

    Color.Settransform() 515 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 spec...

  • Page 516

    516 chapter 7: actionscript for flash 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. // create a color ob...

  • Page 517: Chapter 7

    Contextmenu class 517 contextmenu class 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...

  • Page 518

    518 chapter 7: actionscript for flash property summary for the contextmenu class event handler summary for the contextmenu class constructor for the contextmenu class availability flash player 7. Usage new contextmenu ([callbackfunction]) parameters callbackfunction a reference to a function that is...

  • Page 519

    Contextmenu.Builtinitems 519 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 = ...

  • Page 520

    520 chapter 7: actionscript for flash var propvalue = my_cm.Builtinitems[propname]; trace(propname + ": " + propvalue); } contextmenu.Copy() availability flash player 7. Usage my_cm.Copy() : contextmenu parameters none. Returns a contextmenu object. Description method; creates a copy of the specifie...

  • Page 521

    Contextmenu.Hidebuiltinitems() 521 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 ...

  • Page 522

    522 chapter 7: actionscript for flash 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. This metho...

  • Page 523

    Contextmenu.Onselect 523 example the following example determines over what type of object the context menu was invoked: my_cm = new contextmenu(); function menuhandler(obj:object, menu:contextmenu) { if(obj instanceof movieclip) { trace("movie clip: " + obj); } if(obj instanceof textfield) { trace(...

  • Page 524: Chapter 7

    524 chapter 7: actionscript for flash contextmenuitem class 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 ...

  • Page 525

    Contextmenuitem class 525 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 th...

  • Page 526

    526 chapter 7: actionscript for flash 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 writes the caption for the selected men...

  • Page 527

    Contextmenuitem.Enabled 527 my_cm.Customitems.Push(copy_cmi); my_mc.Menu = my_cm; 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 prop...

  • Page 528

    528 chapter 7: actionscript for flash 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 th...

  • Page 529

    Contextmenuitem.Visible 529 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 s...

  • Page 530

    530 chapter 7: actionscript for flash 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. When stop is selected, the number of ...

  • Page 531: Chapter 7

    Duplicatemovieclip() 531 duplicatemovieclip() availability flash player 4. Usage duplicatemovieclip(target:string, newname:string, depth:number) : void parameters target the target path of the movie clip to duplicate. Newname a unique identifier for the duplicated movie clip. Depth a unique depth le...

  • Page 532: Chapter 7

    532 chapter 7: actionscript for flash _focusrect 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 ye...

  • Page 533: Chapter 7

    Getproperty() 533 getproperty() 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. Descr...

  • Page 534: Chapter 7

    534 chapter 7: actionscript for flash microphone class 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 us...

  • Page 535

    Microphone.Activitylevel 535 event handler summary for the microphone class constructor for the microphone class see microphone.Get() . Microphone.Activitylevel availability flash player 6. Usage active_mic.Activitylevel:number description read-only property; a numeric value that specifies the amoun...

  • Page 536

    536 chapter 7: actionscript for flash activitylevel_pb.Label = "activity level: %3%%"; activitylevel_pb.Setstyle("themecolor", "0xff0000"); this.Createemptymovieclip("sound_mc", this.Getnexthighestdepth()); var active_mic:microphone = microphone.Get(); sound_mc.Attachaudio(active_mic); this.Onenterf...

  • Page 537

    Microphone.Get() 537 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 i...

  • Page 538

    538 chapter 7: actionscript for flash 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...

  • Page 539

    Microphone.Name 539 mic_lbl.Text = "["+active_mic.Index+"] "+active_mic.Name; mic_cb.Dataprovider = microphone.Names; mic_cb.Selectedindex = active_mic.Index; var cblistener:object = new object(); cblistener.Change = function(evt:object) { active_mic = microphone.Get(evt.Target.Selectedindex); sound...

  • Page 540

    540 chapter 7: actionscript for flash 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.Setstyle("fontsize", 9); var...

  • Page 541

    Microphone.Onactivity 541 status_ta.Text += "you have "+microphone_array.Length+" device(s) installed."+newline+newline; for (var i = 0; i status_ta.Text += "["+i+"] "+microphone_array[i]+newline; } for example, the following information could be displayed: the default device is: logitech usb headse...

  • Page 542

    542 chapter 7: actionscript for flash active_mic.Onactivity = function(active:boolean) { if (active) { activitylevel_pb.Indeterminate = false; activitylevel_pb.Label = "activity level: %3%%"; } else { activitylevel_pb.Indeterminate = true; activitylevel_pb.Label = "activity level: (inactive)"; } }; ...

  • Page 543

    Microphone.Rate 543 note: if the user chooses to permanently allow or deny access to all swf files from a specified domain, this method is not invoked for swf files from that domain unless the user later changes the privacy setting. For more information, see microphone.Get() . Example the following ...

  • Page 544

    544 chapter 7: actionscript for flash example the following code lets you use a combobox instance, called rate_cb , to change the rate at which your microphone captures sound. The current rate displays in a label instance called rate_lbl . This.Createemptymovieclip("sound_mc", this.Getnexthighestdep...

  • Page 545

    Microphone.Setrate() 545 you can think of this setting like a volume knob on a stereo: 0 is no volume and 50 is normal volume; numbers below 50 specify lower than normal volume, while numbers above 50 specify higher than normal volume. Example the following example uses a progressbar instance called...

  • Page 546

    546 chapter 7: actionscript for flash example the following example sets the microphone rate to the user’s preference (which you have assigned to the userrate variable) if it is one of the following values: 5, 8, 11, 22, or 44. If it is not, the value is rounded to the nearest acceptable value that ...

  • Page 547

    Microphone.Setsilencelevel() 547 returns nothing. Description method; sets the minimum input level that should be considered sound and (optionally) the amount of silent time signifying that silence has actually begun. • to prevent the microphone from detecting sound at all, pass a value of 100 for l...

  • Page 548

    548 chapter 7: actionscript for flash var nsteplistener:object = new object(); nsteplistener.Change = function(evt:object) { active_mic.Setsilencelevel(evt.Target.Value, active_mic.Silencetimeout); }; silencelevel_nstep.Addeventlistener("change", nsteplistener); this.Onenterframe = function() { sile...

  • Page 549

    Microphone.Silencelevel 549 generally, echo suppression is advisable when the sound being captured is played through speakers—instead of a headset—on the same computer. If your swf file allows users to specify the sound output device, you may want to call microphone.Setuseechosuppression(true) if th...

  • Page 550

    550 chapter 7: actionscript for flash var silencelevel_pb:mx.Controls.Progressbar; var silencelevel_nstep:mx.Controls.Numericstepper; this.Createemptymovieclip("sound_mc", this.Getnexthighestdepth()); var active_mic:microphone = microphone.Get(); sound_mc.Attachaudio(active_mic); silencelevel_pb.Lab...

  • Page 551

    Microphone.Useechosuppression 551 example the following example enables the user to control the amount of time between when the microphone stops detecting sound and when microphone.Onactivity(false) is invoked. The user controls this value using a numericstepper instance called silencetimeout_nstep ...

  • Page 552

    552 chapter 7: actionscript for flash 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 e...

  • Page 553: Chapter 7

    Mmexecute() 553 mmexecute() 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 state...

  • Page 554: Chapter 7

    554 chapter 7: actionscript for flash movieclip class availability flash player 3. Description the movieclip class is the base class for flex components. However, while macromedia supports some of the movieclip interface for use in flex applications, much of the interface has been overridden by flex...

  • Page 555

    Movieclip class 555 drawing method summary for the movieclip class 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.Gotoandst...

  • Page 556

    556 chapter 7: actionscript for flash property summary for the movieclip class 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 dra...

  • Page 557

    Movieclip class 557 event handler summary for the movieclip class 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 cli...

  • Page 558

    558 chapter 7: actionscript for flash 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...

  • Page 559

    Movieclip.Attachaudio() 559 // replace with your own image or use the following holder_mc.Image_mc.Loadmovie("http://www.Macromedia.Com/devnet/mx/blueprint/ articles/nielsen/spotlight_jnielsen.Jpg"); holder_mc.Onrollover = function() { this._alpha = 50; }; holder_mc.Onrollout = function() { this._al...

  • Page 560

    560 chapter 7: actionscript for flash volup_btn.Onrelease = function() { if (audio_sound.Getvolume() audio_sound.Setvolume(audio_sound.Getvolume()+10); updatevolume(); } }; voldown_btn.Onrelease = function() { if (audio_sound.Getvolume()>0) { audio_sound.Setvolume(audio_sound.Getvolume()-10); update...

  • Page 561

    Movieclip.Beginfill() 561 returns a reference to the newly created instance. Description method; takes a symbol from the library and attaches it to the swf file on the stage specified by my_mc . Use movieclip.Removemovieclip() or movieclip.Unloadmovie() to remove a swf file attached with attachmovie...

  • Page 562

    562 chapter 7: actionscript for flash example the following example creates a square with red fill on the stage. This.Createemptymovieclip("square_mc", this.Getnexthighestdepth()); square_mc.Beginfill(0xff0000); square_mc.Moveto(10, 10); square_mc.Lineto(100, 10); square_mc.Lineto(100, 100); square_...

  • Page 563

    Movieclip.Begingradientfill() 563 moveto(100, 100); lineto(100, 300); lineto(300, 300); lineto(300, 100); lineto(100, 100); endfill(); } 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, translat...

  • Page 564

    564 chapter 7: actionscript for flash if a matrixtype property exists then it must equal "box" and the remaining parameters are all required. The function fails if any of these conditions are not met. Returns nothing. Description method; indicates the beginning of a new drawing path. If the first pa...

  • Page 565

    Movieclip.Clear() 565 moveto(100, 310); lineto(100, 510); lineto(600, 510); lineto(600, 310); lineto(100, 310); endfill(); } see also movieclip.Beginfill() , movieclip.Endfill() , movieclip.Linestyle() , movieclip.Lineto() , movieclip.Moveto() movieclip.Clear() availability flash player 6. Usage my_...

  • Page 566

    566 chapter 7: actionscript for flash box_mc.Onrelease = function() { this.Clear(); }; drawbox(box_mc, 10, 10, 320, 240); function drawbox(mc:movieclip, x:number, y:number, w:number, h:number):void { mc.Linestyle(0); mc.Beginfill(0xeeeeee); mc.Moveto(x, y); mc.Lineto(x+w, y); mc.Lineto(x+w, y+h); mc...

  • Page 567

    Movieclip.Createtextfield() 567 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 a string that identifies the instance name of the new text field. De...

  • Page 568

    568 chapter 7: actionscript for flash variable = null maxchars = null stylesheet = undefined tabinded = 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 = ...

  • Page 569

    Movieclip.Curveto() 569 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 ah...

  • Page 570

    570 chapter 7: actionscript for flash example the following example draws a circle with a solid blue hairline stroke and a solid red fill: this.Createemptymovieclip("circle_mc", 1); with (circle_mc) { linestyle(0, 0x0000ff, 100); beginfill(0xff0000); moveto(500, 500); curveto(600, 500, 600, 400); cu...

  • Page 571

    Movieclip.Duplicatemovieclip() 571 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 pat...

  • Page 572

    572 chapter 7: actionscript for flash parameters newname a unique identifier for the duplicate movie clip. Depth a unique number specifying the depth at which the swf file specified is to be placed. Initobject (supported for flash player 6 and later.) an object containing properties with which to po...

  • Page 573

    Movieclip.Endfill() 573 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 ar...

  • Page 574

    574 chapter 7: actionscript for flash square_mc.Lineto(10, 100); square_mc.Lineto(10, 10); square_mc.Endfill(); see also movieclip.Beginfill() , movieclip.Begingradientfill() , movieclip.Moveto() movieclip.Focusenabled availability flash player 6. Usage my_mc.Focusenabled:boolean description propert...

  • Page 575

    Movieclip.Getbounds() 575 example this example demonstrates how to hide the yellow rectangle around a specified movie clip instance in a swf file when it has focus in a browser window. Create three movie clips called mc1_mc , mc2_mc , and mc3_mc , and add the following actionscript: mc1_mc._focusrec...

  • Page 576

    576 chapter 7: actionscript for flash 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 ma...

  • Page 577

    Movieclip.Getbytestotal() 577 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 cli...

  • Page 578

    578 chapter 7: actionscript for flash 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. You can extend the methods and event handlers of the movieclip class by creatin...

  • Page 579

    Movieclip.Getnexthighestdepth() 579 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.Duplicatemovieclip() , or movieclip.Createemptymovieclip() to determine if the depth paramete...

  • Page 580

    580 chapter 7: actionscript for flash mcllistener.Onloadinit = function(target_mc:movieclip) { target_mc.Onpress = function() { this.Startdrag(); }; target_mc.Onrelease = function() { this.Stopdrag(); }; }; logo_mcl.Addlistener(mcllistener); logo_mcl.Loadclip("http://www.Macromedia.Com/devnet/mx/blu...

  • Page 581

    Movieclip.Gettextsnapshot() 581 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 ...

  • Page 582

    582 chapter 7: actionscript for flash text_mc.Textsnapshot_txt.Htmltext += ""+i+"\t"+textsnap[i]; } text_mc.Textsnapshot_txt.Htmltext += ""; the following text appears in text_mc.Textsnapshot_txt : gettextruninfo[type function] setselectcolor[type function] findtext[type function] hittesttextnearpos...

  • Page 583

    Movieclip.Globaltolocal() 583 example the following actionscript creates a new movie clip instance and opens the macromedia website in a new browser window: this.Createemptymovieclip("loader_mc", this.Getnexthighestdepth()); loader_mc.Geturl("http://www.Macromedia.Com", “_blank”); the geturl() metho...

  • Page 584

    584 chapter 7: actionscript for flash var mouselistener:object = new object(); mouselistener.Onmousemove = function() { var point:object = {x:_xmouse, y:_ymouse}; target_mc.Globaltolocal(point); var rowheaders = " \t_x\t_y"; var row_1 = "_root\t"+_xmouse+"\t"+_ymouse; var row_2 = "target_mc\t"+point...

  • Page 585

    Movieclip.Hitarea 585 returns nothing. Description method; brings the playhead to the specified frame of the movie clip and stops it there. 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:...

  • Page 586

    586 chapter 7: actionscript for flash 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...

  • Page 587

    Movieclip.Linestyle() 587 returns a boolean value of true if my_mc overlaps with the specified hit area, false otherwise. Description method; evaluates the instance specified by my_mc to see if it overlaps or intersects with the hit area identified by the target or x and y coordinate parameters. Usa...

  • Page 588

    588 chapter 7: actionscript for flash alpha an integer that indicates the alpha value of the line’s color; valid values are 0–100. If a value isn’t indicated, flash uses 100 (solid). If the value is less than 0, flash uses 0; if the value is greater than 100, flash uses 100. Returns nothing. Descrip...

  • Page 589

    Movieclip.Loadmovie() 589 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 ). If the movie clip that you are drawing in contains content that was created with the flash drawing tools, cal...

  • Page 590

    590 chapter 7: actionscript for flash description method; loads swf or jpeg files into a movie clip in flash player while the original swf file is playing. Tip: if you want to monitor the progress of the download, use moviecliploader.Loadclip() instead of this function. Without the loadmovie() metho...

  • Page 591

    Movieclip.Localtoglobal() 591 see also movieclip.Loadmovie() , movieclip.Loadvariables() , movieclip.Unloadmovie() , unloadmovie() , unloadmovienum() movieclip.Loadvariables() availability flash player 5. Usage my_mc.Loadvariables(url:string [, variables:string]) : void parameters url the absolute o...

  • Page 592

    592 chapter 7: actionscript for flash parameters point the name or identifier of an object created with the object class , specifying the x and y coordinates as properties. Returns nothing. Description method; converts the point object from the movie clip’s (local) coordinates to the stage (global) ...

  • Page 593

    Movieclip._lockroot 593 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.Swf ) into the game_mc movie clip. You want to make sure that, if _root is used in chess.Swf, it still refers to _root in chess.Swf after b...

  • Page 594

    594 chapter 7: actionscript for flash the lockroot.Swf file has _ lockroot applied to it, and nolockroot.Swf does not. After the files are loaded, each file dumps variables from their _root scopes. Place the following actionscript on the main timeline of a fla document: this.Createemptymovieclip("lo...

  • Page 595

    Movieclip.Menu 595 from lockroot.Swf myothervar -> 2 myvar -> 1 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 contex...

  • Page 596

    596 chapter 7: actionscript for flash movieclip.Moveto() availability flash player 6. Usage my_mc.Moveto(x:number, y:number) : void parameters x an integer indicating the horizontal position relative to the registration point of the parent movie clip. Y an integer indicating the vertical position re...

  • Page 597

    Movieclip.Ondata 597 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 fl...

  • Page 598

    598 chapter 7: actionscript for flash 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 fu...

  • Page 599

    Movieclip.Ondragover 599 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 f...

  • Page 600

    600 chapter 7: actionscript for flash 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 movie...

  • Page 601

    Movieclip.Onkeydown 601 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 ...

  • Page 602

    602 chapter 7: actionscript for flash see also movieclip.Onkeyup 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 invok...

  • Page 603

    Movieclip.Onload 603 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 ke...

  • Page 604

    604 chapter 7: actionscript for flash 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 ...

  • Page 605

    Movieclip.Onmousemove 605 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...

  • Page 606

    606 chapter 7: actionscript for flash example the following example defines a function for the onmousemove method that writes the results of a trace() method to the log file: my_mc.Onmousemove = function () { trace ("onmousemove called"); }; movieclip.Onmouseup availability flash player 6. Usage my_...

  • Page 607

    Movieclip.Onrelease 607 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 t...

  • Page 608

    608 chapter 7: actionscript for flash 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 ...

  • Page 609

    Movieclip.Onrollover 609 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 ...

  • Page 610

    610 chapter 7: actionscript for flash 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. ...

  • Page 611

    Movieclip._parent 611 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 a...

  • Page 612

    612 chapter 7: actionscript for flash example the following example logs the reference to a movie clip and its relationship to the main timeline. Create a movie clip with the instance name my_mc , and add it to the main timeline. Add the following actionscript to your fla or as file: my_mc.Onrelease...

  • Page 613

    Movieclip.Prevframe() 613 see also movieclip.Gotoandplay() 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 t...

  • Page 614

    614 chapter 7: actionscript for flash 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.At...

  • Page 615

    Movieclip.Setmask() 615 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 obta...

  • Page 616

    616 chapter 7: actionscript for flash to cancel a mask created with actionscript, pass the value null to the setmask() method. The following code cancels the mask without affecting the mask layer in the timeline. Uimask.Setmask(null); you can extend the methods and event handlers of the movieclip cl...

  • Page 617

    Movieclip.Stopdrag() 617 }; var image_mcl:moviecliploader = new moviecliploader(); image_mcl.Addlistener(mcllistener); image_mcl.Loadclip("http://www.Macromedia.Com/devnet/mx/blueprint/articles/ nielsen/spotlight_jnielsen.Jpg", image_mc); see also movieclip._droptarget , startdrag() , movieclip.Stop...

  • Page 618

    618 chapter 7: actionscript for flash 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 ca...

  • Page 619

    Movieclip.Tabchildren 619 description method; swaps the stacking, or z-order (depth level), of the specified instance ( my_mc ) with the movie clip specified by the target parameter, or with the movie clip that currently occupies the depth level specified in the depth parameter. Both movie clips mus...

  • Page 620

    620 chapter 7: actionscript for flash the following example disables tabbing for all children movie clips inside a parent movie clip called menu_mc . Menu_mc.Onrelease = function(){}; menu_mc.Menu1_mc.Onrelease = function(){}; menu_mc.Menu2_mc.Onrelease = function(){}; menu_mc.Menu3_mc.Onrelease = f...

  • Page 621

    Movieclip._target 621 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 a...

  • Page 622

    622 chapter 7: actionscript for flash for (var i in this) { if (typeof (this[i]) == "movieclip") { trace("name: "+this[i]._name+",\t target: "+this[i]._target+",\t target(2): "+eval(this[i]._target)); } } movieclip._totalframes availability flash player 4. Usage my_mc._totalframes:number description...

  • Page 623

    Movieclip.Unloadmovie() 623 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 no...

  • Page 624

    624 chapter 7: actionscript for flash example the following example unloads a movie clip instance called image_mc when a user clicks the unloadmc_btn instance. This.Createemptymovieclip("image_mc", 1); image_mc.Loadmovie("http://www.Macromedia.Com/images/shared/product_boxes/ 112x112/box_studio_112x...

  • Page 625

    Movieclip._visible 625 }; var image_mcl:moviecliploader = new moviecliploader(); image_mcl.Addlistener(mcllistener); image_mcl.Loadclip("photo1.Jpg", image_mc); function viewimage(target_mc:movieclip, obj:object) { geturl(target_mc._url, "_blank"); } when you right-click or control-click the image a...

  • Page 626

    626 chapter 7: actionscript for flash 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 b...

  • Page 627

    Movieclip._xmouse 627 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 ...

  • Page 628

    628 chapter 7: actionscript for flash 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 = t...

  • Page 629

    Movieclip._y 629 endfill(); } box_mc.Onrollover = function() { this._x -= this._width/2; this._y -= this._height/2; this._xscale = 200; this._yscale = 200; }; box_mc.Onrollout = function() { this._xscale = 100; this._yscale = 100; this._x += this._width/2; this._y += this._height/2; }; see also movi...

  • Page 630

    630 chapter 7: actionscript for flash see also movieclip._x , movieclip._xscale , movieclip._yscale 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 cu...

  • Page 631

    Movieclip._yscale 631 example the following example creates a movie clip at runtime called box_mc . The drawing api is used to draw a box in this instance, and when the mouse rolls over the box, horizontal and vertical scaling is applied to the movie clip. When the mouse rolls off the instance, it r...

  • Page 632: Chapter 7

    632 chapter 7: actionscript for flash moviecliploader class 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 movieclip...

  • Page 633

    Moviecliploader.Addlistener() 633 listener summary for the moviecliploader class constructor for the moviecliploader class availability flash player 7. Usage new moviecliploader() : moviecliploader parameters none. Returns a reference to a moviecliploader object. Description constructor; creates a m...

  • Page 634

    634 chapter 7: actionscript for flash 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 fo...

  • Page 635

    Moviecliploader.Loadclip() 635 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 nu...

  • Page 636

    636 chapter 7: actionscript for flash target the target path of a movie clip, or an integer specifying the level in flash player into which the movie will be loaded. The target movie clip is replaced by the loaded swf file or image. Returns a boolean value. The return value is true if the url reques...

  • Page 637

    Moviecliploader.Loadclip() 637 var mylistener:object = new object(); mylistener.Onloadstart = function(target_mc:movieclip) { trace("*********first my_mcl instance*********"); trace("your load has begun on movie clip = "+target_mc); var loadprogress:object = my_mcl.Getprogress(target_mc); trace(load...

  • Page 638

    638 chapter 7: actionscript for flash var loadprogress:object = my_mcl.Getprogress(target_mc); trace(loadprogress.Bytesloaded+" = bytes loaded at start"); trace(loadprogress.Bytestotal+" = bytes total at start"); }; mylistener2.Onloadcomplete = function(target_mc:movieclip) { trace("*********second ...

  • Page 639

    Moviecliploader.Onloaderror 639 description listener; invoked when a file loaded with moviecliploader.Loadclip() has completely downloaded. The value for target_mc identifies the movie clip for which this call is being made. This is useful if multiple files are being loaded with the same set of list...

  • Page 640

    640 chapter 7: actionscript for flash // 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 ...

  • Page 641

    Moviecliploader.Onloadinit 641 image_mcl.Addlistener(mcllistener); image_mcl.Loadclip("http://www.Fakedomain.Com/images/bad_hair_day.Jpg", image_mc); moviecliploader.Onloadinit availability flash player 7. Usage listenerobject.Onloadinit = function([target_mc:movieclip]) { // your statements here } ...

  • Page 642

    642 chapter 7: actionscript for flash 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.Onloadstart moviecliploader...

  • Page 643

    Moviecliploader.Onloadprogress 643 example the following example creates a progress bar using the drawing api. The progress bar displays the loading progress of an image using the onloadprogress listener. When the image finishes loading, the progress bar is removed from the stage. You must replace t...

  • Page 644

    644 chapter 7: actionscript for flash see also moviecliploader.Getprogress() moviecliploader.Onloadstart availability flash player 7. Usage listenerobject.Onloadstart = function([target_mc:object]) { // your statements here } parameters listenerobject a listener object that was added using movieclip...

  • Page 645

    Moviecliploader.Removelistener() 645 see also moviecliploader.Onloaderror , moviecliploader.Onloadinit , moviecliploader.Onloadcomplete moviecliploader.Removelistener() availability flash player 7. Usage my_mcl.Removelistener(listenerobject:object) : void parameters listenerobject a listener object ...

  • Page 646

    646 chapter 7: actionscript for flash image_mcl.Loadclip("http://www.Macromedia.Com/devnet/images/160x160/ flex_logo.Jpg", image_mc); }; stop_button.Clickhandler = function() { trace("stopping..."); start_button.Enabled = true; stop_button.Enabled = false; // image_mcl.Removelistener(mcllistener); }...

  • Page 647: Chapter 7

    Netconnection class 647 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 p...

  • Page 648

    648 chapter 7: actionscript for flash 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 paramet...

  • Page 649: Chapter 7

    Netstream class 649 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...

  • Page 650

    650 chapter 7: actionscript for flash event handler summary for the netstream class 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 serve...

  • Page 651

    Netstream.Buffertime 651 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.Buffertime to estimate how close the buffer is to being full—for example, to display feedback to a u...

  • Page 652

    652 chapter 7: actionscript for flash 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 . Example the follo...

  • Page 653

    Netstream.Bytesloaded 653 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 t...

  • Page 654

    654 chapter 7: actionscript for flash 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 b...

  • Page 655

    Netstream.Close() 655 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.Buffertim...

  • Page 656

    656 chapter 7: actionscript for flash 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...

  • Page 657

    Netstream.Onstatus 657 returns nothing. Description event handler; invoked every time a status change or error is posted for the netstream object. If you want to respond to this event handler, you must create a function to process the information object. The information object has a code property co...

  • Page 658

    658 chapter 7: actionscript for flash see also system.Onstatus , netstream.Setbuffertime() 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 document...

  • Page 659

    Netstream.Play() 659 parameters filename 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. Returns nothing. Description method; begins playback of an external video (flv) file....

  • Page 660

    660 chapter 7: actionscript for flash 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...

  • Page 661

    Netstream.Time 661 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 ...

  • Page 662

    662 chapter 7: actionscript for flash stream_ns.Play("video1.Flv"); // stream_ns.Onstatus = function(infoobject:object) { statuscode_txt.Text = infoobject.Code; }; this.Createtextfield("time_txt", this.Getnexthighestdepth(), 10, 10, 100, 22); time_txt.Text = "loading"; var time_interval:number = set...

  • Page 663: Chapter 7

    Onclipevent() 663 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 spe...

  • Page 664

    664 chapter 7: actionscript for flash 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 k...

  • Page 665: Chapter 7

    Onupdate 665 onupdate 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...

  • Page 666: Chapter 7

    666 chapter 7: actionscript for flash _parent 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 ...

  • Page 667: Chapter 7

    Removemovieclip() 667 removemovieclip() availability flash player 4. Usage removemovieclip(target) parameters target 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() ,...

  • Page 668: Chapter 7

    668 chapter 7: actionscript for flash _root availability flash player 5. Usage _root.Movieclip _root.Action _root.Property parameters movieclip the instance name of a movie clip. Action an action or method. Property a property of the movieclip object. Description identifier; specifies or returns a r...

  • Page 669: Chapter 7

    Selection.Addlistener() 669 selection class 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, t...

  • Page 670

    670 chapter 7: actionscript for flash 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 object...

  • Page 671

    Selection.Getcaretindex() 671 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 posi...

  • Page 672

    672 chapter 7: actionscript for flash 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 ...

  • Page 673

    Selection.Getfocus() 673 example /* define the function which converts the selected text in an instance, and convert the string to upper or lower case. */ function convertcase(target, menuitem) { var beginindex:number = selection.Getbeginindex(); var endindex:number = selection.Getendindex(); var te...

  • Page 674

    674 chapter 7: actionscript for flash • 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. • if a button object or button movie clip has focus, this method returns the...

  • Page 675

    Selection.Removelistener() 675 // statements } selection.Addlistener(somelistener); listeners enable different pieces of code to cooperate because multiple listeners can receive notification about a single event. Example the following example demonstrates how to determine when input focus changes in...

  • Page 676

    676 chapter 7: actionscript for flash 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...

  • Page 677

    Selection.Setfocus() 677 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 . The instancepathname parameter must be a string literal of the path...

  • Page 678

    678 chapter 7: actionscript for flash status_txt.Text = "success!"; selection.Setfocus(null); return true; } see also selection.Getfocus() , selection.Onsetfocus selection.Setselection() availability flash player 5. Usage selection.Setselection(start:number, end:number) : void parameters start the b...

  • Page 679: Chapter 7

    Setproperty() 679 setproperty() availability flash player 4. Usage setproperty(target:object, property:object, value/expression:object) : void parameters target the path to the instance name of the movie clip whose property is to be set. Property the property to be set. Value the new literal value o...

  • Page 680: Chapter 7

    680 chapter 7: actionscript for flash 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 ...

  • Page 681

    Sound.Attachsound() 681 event handler summary for the sound class 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 s...

  • Page 682

    682 chapter 7: actionscript for flash parameters idname the identifier of an exported sound in the library. The identifier is located in the linkage properties dialog box. Returns nothing. Description method; attaches the sound specified in the idname parameter to the specified sound object. The sou...

  • Page 683

    Sound.Duration 683 the following example loads several songs into a swf file. A progress bar, created using the drawing api, displays the loading progress. When the music starts and completes loading, information writes to the log file. Add the following actionscript to your fla or as file. Var pb_h...

  • Page 684

    684 chapter 7: actionscript for flash function updateprogressbar(the_sound:sound):void { var pos:number = math.Round(the_sound.Position/the_sound.Duration*100); pb.Bar_mc._xscale = pos; pb.Vbar_mc._x = pb.Bar_mc._width; pb.Pos_txt.Text = pos+"%"; } see also sound.Position sound.Getbytesloaded() avai...

  • Page 685

    Sound.Getpan() 685 clearinterval(my_interval); }; my_sound.Loadsound("song2.Mp3", true); var my_interval:number; my_interval = setinterval(checkprogress, 100, my_sound); function checkprogress(the_sound:sound):void { var pct:number = math.Round(the_sound.Getbytesloaded()/ the_sound.Getbytestotal()*1...

  • Page 686

    686 chapter 7: actionscript for flash 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 curre...

  • Page 687

    Sound.Gettransform() 687 }; 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.Loa...

  • Page 688

    688 chapter 7: actionscript for flash transform_mc.Createtextfield("transform_txt", transform_mc.Getnexthighestdepth, 0, 8, 120, 22); transform_mc.Transform_txt.Html = true; var knob_ll:movieclip = transform_mc.Attachmovie("knob_id", "ll_mc", transform_mc.Getnexthighestdepth(), {_x:0, _y:30}); var k...

  • Page 689

    Sound.Getvolume() 689 function releaseknob() { this.Stopdrag(); updatetransformtxt(); } function updatetransformtxt() { var ll_num:number = 30+100-knob_ll._y; var lr_num:number = 30+100-knob_lr._y; var rl_num:number = 30+100-knob_rl._y; var rr_num:number = 30+100-knob_rr._y; my_sound.Settransform({l...

  • Page 690

    690 chapter 7: actionscript for flash knob_mc.Bottom = knob_mc._y; knob_mc._x = my_sound.Getvolume(); with (knob_mc) { linestyle(0, 0x000000); beginfill(0xcccccc); moveto(0, 0); lineto(4, 0); lineto(4, 18); lineto(0, 18); lineto(0, 0); endfill(); } knob_mc.Createtextfield("volume_txt", knob_mc.Getne...

  • Page 691

    Sound.Id3 691 flash player 6 (6.0.40.0) and later use the sound.Id3 property to support id3 1.0 and id3 1.1 tags. Flash player 7 adds support for id3 2.0 tags, specifically 2.3 and 2.4. The following table lists the standard id3 2.0 tags and the type of content the tags represent; you query them in ...

  • Page 692

    692 chapter 7: actionscript for flash flash player 6 supported several id31.0 tags. If these tags are in not in the mp3 file, but corresponding id3 2.0 tags are, the id3 2.0 tags are copied into the id3 1.0 properties, as shown in the following table. This process provides backward compatibility wit...

  • Page 693

    Sound.Loadsound() 693 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 s...

  • Page 694

    694 chapter 7: actionscript for flash 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()...

  • Page 695

    Sound.Onload 695 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 automatica...

  • Page 696

    696 chapter 7: actionscript for flash 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 t...

  • Page 697

    Sound.Setpan() 697 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...

  • Page 698

    698 chapter 7: actionscript for flash 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 s...

  • Page 699

    Sound.Settransform() 699 mono sounds play all sound input in the left speaker and have the following transform settings by default: ll = 100 lr = 100 rr = 0 rl = 0 example the following example illustrates a setting that can be achieved by using settransform() , but cannot be achieved by using setvo...

  • Page 700

    700 chapter 7: actionscript for flash sound.Setvolume() availability flash player 5. Usage my_sound.Setvolume(volume:number) : void parameters volume a number from 0 to 100 representing a volume level. 100 is full volume and 0 is no volume. The default setting is 100. Returns nothing. Description me...

  • Page 701

    Sound.Stop() 701 example the following example creates a new sound object, and loads a sound. Loading the sound is handled by the onload handler, which allows you to start the song after it’s successfully loaded. Then the sound starts playing using the start() method. Create a new fla file, and add ...

  • Page 702

    702 chapter 7: actionscript for flash example the following example uses two buttons, stop_btn and play_btn , to control the playback of a sound that loads into a swf file. Add two buttons to your document and add the following actionscript to your fla or as file: var my_sound:sound = new sound(); m...

  • Page 703: Chapter 7

    _soundbuftime 703 _soundbuftime 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 secon...

  • Page 704: Chapter 7

    704 chapter 7: actionscript for flash 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 ...

  • Page 705

    Stage.Align 705 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 ). To use addlistener() ...

  • Page 706

    706 chapter 7: actionscript for flash example the following example demonstrates different alignments of the swf file. Add a combobox instance to your document with the instance name stagealign_cb . Add the following actionscript to your fla or as file: var stagealign_cb:mx.Controls.Combobox; stagea...

  • Page 707

    Stage.Removelistener() 707 stage.Scalemode = "noscale"; stage.Addlistener(stagelistener); see also stage.Align , stage.Scalemode , stage.Width stage.Onresize availability flash player 6. Usage mylistener.Onresize = function(){ // your statements here } parameters none. Returns nothing. Description l...

  • Page 708

    708 chapter 7: actionscript for flash 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() . See also stage.Addlistener() stage.Scalemode availability flash player 6. ...

  • Page 709

    Stage.Width 709 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...

  • Page 710

    710 chapter 7: actionscript for flash stagelistener.Onresize = function() { stagesize_txt.Text = "w:"+stage.Width+", h:"+stage.Height; }; stage.Scalemode = "noscale"; stage.Addlistener(stagelistener); see also stage.Align , stage.Height , stage.Scalemode.

  • Page 711: Chapter 7

    Startdrag() 711 startdrag() 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. Lock a boolean value specifying whether the draggable movie clip is locked ...

  • Page 712: Chapter 7

    712 chapter 7: actionscript for flash stop() 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 movieclip.Gotoandstop() chapter 7 ...

  • Page 713: Chapter 7

    Stopallsounds() 713 stopallsounds() 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 th...

  • Page 714: Chapter 7

    714 chapter 7: actionscript for flash stopdrag() 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...

  • Page 715: Chapter 7

    Targetpath() 715 targetpath() 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 spe...

  • Page 716: Chapter 7

    716 chapter 7: actionscript for flash textfield class availability flash player 6. Description you can use the textfield class to perform low-level text rendering. However, in flex, you typically use the label, text, textarea, and textinput controls to process text. All dynamic and input text fields...

  • Page 717

    Textfield class 717 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 ...

  • Page 718

    718 chapter 7: actionscript for flash event handler summary for the textfield class listener summary for the textfield class 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...

  • Page 719

    Textfield.Addlistener() 719 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 onc...

  • Page 720

    720 chapter 7: actionscript for flash }; my_txt.Addlistener(txtlistener); see also textfield.Onchanged , textfield.Onscroller , textfield.Removelistener() textfield._alpha availability flash player 6. Usage my_txt._alpha:number description property; sets or retrieves the alpha transparency value of ...

  • Page 721

    Textfield.Autosize 721 the values of autosize and textfield.Wordwrap determine whether a text field expands or contracts to the left side, right side, or bottom side. The default value for each of these properties is false . If autosize is set to "none" (the default) or false , then no resizing will...

  • Page 722

    722 chapter 7: actionscript for flash // define a function that executes when a user clicks the mouse mymouselistener.Onmousedown = function() { left_txt.Autosize = "left"; left_txt.Text = "this is much longer text"; center_txt.Autosize = "center"; center_txt.Text = "this is much longer text"; right...

  • Page 723

    Textfield.Bordercolor 723 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.Ba...

  • Page 724

    724 chapter 7: actionscript for flash my_txt.Bordercolor = 0x00ff00; my_txt.Text = "lorum ipsum"; see also textfield.Border textfield.Bottomscroll availability flash player 6. Usage my_txt.Bottomscroll:number description read-only property; an integer (one-based index) that indicates the bottommost ...

  • Page 725

    Textfield.Embedfonts 725 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...

  • Page 726

    726 chapter 7: actionscript for flash 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 . Var ...

  • Page 727

    Textfield.Getnewtextformat() 727 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 t...

  • Page 728

    728 chapter 7: actionscript for flash 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 ...

  • Page 729

    Textfield.Hscroll 729 example the following actionscript traces all of the formatting information for a text field that is created at runtime. This.Createtextfield("dyn_txt", this.Getnexthighestdepth(), 0, 0, 100, 200); dyn_txt.Text = "frank"; dyn_txt.Settextformat(new textformat()); var my_fmt:text...

  • Page 730

    730 chapter 7: actionscript for flash horizontal scrolling is measured in pixels because most fonts you typically use are proportionally spaced; meaning, the characters can have different widths. Flash performs vertical scrolling by line because users usually want to see a line of text in its entire...

  • Page 731

    Textfield.Length 731 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.Getnexthighestdepth(), 10, 10, 160, 22); my_txt.Html = true; my_txt.Htmltext = " this is bold text "; see ...

  • Page 732

    732 chapter 7: actionscript for flash 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.Getnexthighestdepth(), 10, 10, 100, 22); date_txt.Autosize = true; date...

  • Page 733

    Textfield.Menu 733 textfield.Maxscroll availability flash player 6. Usage textfield.Maxscroll:number description read-only property; indicates the maximum value of textfield.Scroll . Example the following example sets the maximum value for the scrolling text field my_txt . Create two buttons, scroll...

  • Page 734

    734 chapter 7: actionscript for flash this property works only with selectable (editable) text fields; it has no effect on nonselectable text fields. In flex, only top-level components in the application can have context menus. For example, if a datagrid control is a child of a tabnavigator or vbox ...

  • Page 735

    Textfield.Multiline 735 example the following example creates two text fields. The scrollable_txt field has the mousewheelenabled property set to true, so scrollable_txt scrolls when you click the field and roll the mouse wheel. The nonscrollable_txt field does not scroll if you click the field and ...

  • Page 736

    736 chapter 7: actionscript for flash 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. Add the following action...

  • Page 737

    Textfield.Onkillfocus 737 a reference to the text field instance is passed as a parameter to the onchanged handler. You can capture this data by putting a parameter in the event handler method. For example, the following code uses textfield_txt as the parameter that is passed to the onchanged event ...

  • Page 738

    738 chapter 7: actionscript for flash second_txt.Border = true; second_txt.Type = "input"; first_txt.Onkillfocus = function(newfocus:object) { trace(this._name+" lost focus. New focus changed to: "+newfocus._name); }; first_txt.Onsetfocus = function(oldfocus:object) { trace(this._name+" gained focus...

  • Page 739

    Textfield.Onsetfocus 739 onscroller is called whether the scroll position changed because of a users interaction with the text field, or programmatic changes. The onchanged handler fires only if a user interaction causes the change. These two options are necessary because often one piece of code cha...

  • Page 740

    740 chapter 7: actionscript for flash 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...

  • Page 741

    Textfield.Password 741 the following information writes to the log file: first_txt's _parent is: _level0 second_txt's _parent is: _level0.Holder_mc see also movieclip._parent , _root , targetpath() textfield.Password availability flash player 6. Usage my_txt.Password:boolean description property; if...

  • Page 742

    742 chapter 7: actionscript for flash 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...

  • Page 743

    Textfield.Replacesel() 743 txtlistener.Onchanged = function(textfield_txt:textfield) { trace(textfield_txt+" changed. Current length is: "+textfield_txt.Length); }; my_txt.Addlistener(txtlistener); removelistener_btn.Onrelease = function() { trace("removing listener..."); if (!My_txt.Removelistener(...

  • Page 744

    744 chapter 7: actionscript for flash 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 t...

  • Page 745

    Textfield.Restrict 745 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 ...

  • Page 746

    746 chapter 7: actionscript for flash the following example includes all characters, but excludes lowercase letters: my_txt.Restrict = "^a-z"; you can use a backslash to enter a ^ or - verbatim. The accepted backslash sequences are \-, \^ or \\. The backslash must be an actual character in the strin...

  • Page 747

    Textfield.Scroll 747 apply additional formatting for the text field using the textformat class . See also movieclip._rotation 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 f...

  • Page 748

    748 chapter 7: actionscript for flash 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 wh...

  • Page 749

    Textfield.Settextformat() 749 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 th...

  • Page 750

    750 chapter 7: actionscript for flash description method; applies the text formatting specified by textformat to some or all of the text in a text field. Textformat must be a textformat object that specifies the text formatting changes desired. Only the non-null properties of textformat are applied ...

  • Page 751

    Textfield.Stylesheet 751 see also textfield.Setnewtextformat() , textformat class 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 sh...

  • Page 752

    752 chapter 7: actionscript for flash css2_btn.Onrelease = function() { var styleobj:textfield.Stylesheet = new textfield.Stylesheet(); styleobj.Onload = function(success:boolean) { if (success) { news_txt.Stylesheet = styleobj; news_txt.Htmltext = newstext; } }; styleobj.Load("styles2.Css"); }; cle...

  • Page 753

    Textfield.Tabindex 753 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 autom...

  • Page 754

    754 chapter 7: actionscript for flash 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. If any currently displayed object...

  • Page 755

    Textfield.Text 755 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 spe...

  • Page 756

    756 chapter 7: actionscript for flash htmltext: color="#000000">remember to always update your help panel. Color="#000000">remember to always update your help panel. Text: remember to always update your help panel. */ see also textfield.Htmltext textfield.Textcolor availability flash player 6. Usage...

  • Page 757

    Textfield.Type 757 trace("after my_txt.Autosize = true;"); trace("_height: "+my_txt._height+", _width: "+my_txt._width); which outputs the following information: textheight: 15, textwidth: 56 _height: 300, _width: 100 after my_txt.Autosize = true; _height: 19, _width: 60 see also textfield.Textwidth...

  • Page 758

    758 chapter 7: actionscript for flash username_txt.Border = true; username_txt.Type = "input"; username_txt.Maxchars = 16; username_txt.Text = "hello"; this.Createtextfield("password_txt", this.Getnexthighestdepth(), 10, 40, 100, 22); password_txt.Border = true; password_txt.Type = "input"; password...

  • Page 759

    Textfield._visible 759 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...

  • Page 760

    760 chapter 7: actionscript for flash 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 ...

  • Page 761

    Textfield._x 761 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 w...

  • Page 762

    762 chapter 7: actionscript for flash coords_txt.Border = true; var mouselistener:object = new object(); mouselistener.Onmousedown = function() { coords_txt.Text = "x:"+math.Round(_xmouse)+", y:"+math.Round(_ymouse); coords_txt._x = _xmouse; coords_txt._y = _ymouse; }; mouse.Addlistener(mouselistene...

  • Page 763

    Textfield._y 763 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 th...

  • Page 764

    764 chapter 7: actionscript for flash example see the example for textfield._x . See also textfield._x , textfield._xscale , textfield._yscale textfield._ymouse availability flash player 6. Usage my_txt._ymouse:number description read-only property; indicates the y coordinate of the mouse position r...

  • Page 765: Chapter 7

    Textfield.Stylesheet class 765 textfield.Stylesheet class availability flash player 7. Description you can use the textfield.Stylesheet class to perform low-level text rendering. However, in flex, you typically use the label, text, textarea, and textinput controls to process text. The textfield.Styl...

  • Page 766

    766 chapter 7: actionscript for flash 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 ...

  • Page 767

    Textfield.Stylesheet.Getstyle() 767 example the following example loads a style sheet called styles.Css into a swf file, and writes the styles that are loaded to the log file. When you click clear_btn , all styles from the my_stylesheet object are removed. // create a new style sheet object var my_s...

  • Page 768

    768 chapter 7: actionscript for flash example the following example loads styles from a css file, parses the stylesheet and writes style names and property values to the log file. Create a new actionscript file called stylesheettracer.As and enter the following code: import textfield.Stylesheet; cla...

  • Page 769

    Textfield.Stylesheet.Getstylenames() 769 font-family: arial, helvetica, sans-serif; font-size: 12px; font-weight: normal; } and finally, in a fla or as file, enter the following actionscript to load the external style sheet, styles.Css. Stylesheettracer.Displayfromurl("styles.Css"); this writes the ...

  • Page 770

    770 chapter 7: actionscript for flash var names_array:array = my_stylesheet.Getstylenames(); trace(names_array.Join("")); the following information is written to the log file: bodytext heading see also textfield.Stylesheet.Getstyle() textfield.Stylesheet.Load() availability flash player 7. Usage s...

  • Page 771

    Textfield.Stylesheet.Onload 771 news_txt.Stylesheet = my_stylesheet; news_txt.Htmltext = " heading goes here! Class=\"mainbody\">lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. } }; my_stylesheet.Load("s...

  • Page 772

    772 chapter 7: actionscript for flash news_txt.Htmltext = " heading goes here! Class=\"mainbody\">lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. } }; my_stylesheet.Load("styles.Css"); for the code conta...

  • Page 773

    Textfield.Stylesheet.Setstyle() 773 // function dumpstyles(styles:textfield.Stylesheet):void { var stylenames_array:array = styles.Getstylenames(); for (var i = 0; i var stylename_str:string = stylenames_array[i]; var styleobject:object = styles.Getstyle(stylename_str); trace(stylename_str); for (va...

  • Page 774

    774 chapter 7: actionscript for flash my_stylesheet.Setstyle("emphasized", styleobj); delete styleobj; var stylenames_array:array = my_stylesheet.Getstylenames(); for (var i=0;i var stylename:string = stylenames_array[i]; var thisstyle:object = my_stylesheet.Getstyle(stylename); trace(stylename); fo...

  • Page 775

    Textfield.Stylesheet.Transform() 775 example the following code subclasses this method: class advcss extends textfield.Stylesheet { // override the transform method function transform(style:object):textformat { for (var z in style) { if (z == "margin") { style.Marginleft = style[z]; style.Marginrigh...

  • Page 776: Chapter 7

    776 chapter 7: actionscript for flash textformat class 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 ...

  • Page 777

    Textformat class 777 constructor for the textformat class availability flash player 6. Usage new textformat([font:string, [size:number, [color:number, [bold:boolean, [italic:boolean, [underline:boolean, [url:string, [target:string, [align:string, [leftmargin:number, [rightmargin:number, [indent:numb...

  • Page 778

    778 chapter 7: actionscript for flash leftmargin indicates the left margin of the paragraph, in points. Rightmargin 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 ...

  • Page 779

    Textformat.Bold 779 example the following example creates a text field with a border and uses textformat.Align to center the text. Var my_fmt:textformat = new textformat(); my_fmt.Align = "center"; this.Createtextfield("my_txt", 1, 100, 100, 300, 100); my_txt.Multiline = true; my_txt.Wordwrap = true...

  • Page 780

    780 chapter 7: actionscript for flash 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 th...

  • Page 781

    Textformat.Font 781 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 s...

  • Page 782

    782 chapter 7: actionscript for flash 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. Width an optional number that represents the width, in...

  • Page 783

    Textformat.Gettextextent() 783 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 ...

  • Page 784

    784 chapter 7: actionscript for flash // 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 = "...

  • Page 785

    Textformat.Leading 785 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 exa...

  • Page 786

    786 chapter 7: actionscript for flash 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...

  • Page 787

    Textformat.Tabstops 787 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 ...

  • Page 788

    788 chapter 7: actionscript for flash this.Createtextfield("mytext2",2,100,220,200,100); mytext2.Multiline = true; mytext2.Wordwrap = true; mytext2.Border = true; var myformat2:textformat = new textformat(); myformat2.Tabstops = [40,80,120,160]; mytext2.Text ="abcd"; mytext2.Settextformat(myformat2)...

  • Page 789

    Textformat.Url 789 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 correctl...

  • Page 790: Chapter 7

    790 chapter 7: actionscript for flash textsnapshot object 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 exampl...

  • Page 791

    Textsnapshot.Getcount() 791 texttofind a string specifying the text to search for. If you specify a string literal instead of a variable of type string, enclose the string in quotation marks. Casesensitive a boolean value specifying whether the text in my_snap must match the case of the string in te...

  • Page 792

    792 chapter 7: actionscript for flash example the following example illustrates how you can output the number of characters in a specified textsnapshot object. To use this code, create a static text field that contains the text “textsnapshot example”. // this example assumes that the movie clip cont...

  • Page 793

    Textsnapshot.Getselectedtext() 793 example the following example illustrates how to use this method. To use this code, create a static text field that contains the text “textsnapshot example”. // this example assumes that the movie clip contains // the static text "textsnapshot example" var my_mc:mo...

  • Page 794

    794 chapter 7: actionscript for flash 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 from a...

  • Page 795

    Textsnapshot.Hittesttextnearpos() 795 trace(count); // output: 20 trace(thetext); // output: textsnapshot example see also textsnapshot.Getselectedtext() textsnapshot.Hittesttextnearpos() availability authoring: flash mx 2004. Playback: swf files published for flash player 6 or later, playing in fla...

  • Page 796

    796 chapter 7: actionscript for flash example the following example illustrates how to use this method. To use this code, place a static text field containing the text “textsnapshot example” on the stage. To test the code, move the pointer over the static text field. Note: if characters don’t appear...

  • Page 797

    Textsnapshot.Setselected() 797 example the following example illustrates how to use this method. To use this code, place a static text field containing the text “textsnapshot example” on the stage. Add the following actionscript to your as or fla file. Note: if characters don’t appear to be selected...

  • Page 798

    798 chapter 7: actionscript for flash description method; specifies a range of characters in a textsnapshot object to be selected or deselected. Characters that are selected are drawn with a colored rectangle behind them, matching the bounding box of the character. The color of the bounding box is d...

  • Page 799: Chapter 7

    Unloadmovie() 799 unloadmovie() 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 pla...

  • Page 800: Chapter 7

    800 chapter 7: actionscript for flash unloadmovienum() 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 ...

  • Page 801: Chapter 7

    Updateafterevent() 801 updateafterevent() 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...

  • Page 802: Chapter 7

    802 chapter 7: actionscript for flash 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...

  • Page 803

    Video.Clear() 803 returns nothing. Description method; specifies a video stream ( source ) to be displayed within the boundaries of the video object on the stage. The video stream is either an flv file being displayed by means of the netstream.Play() command, a camera object, or null . If source is ...

  • Page 804

    804 chapter 7: actionscript for flash 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 pl...

  • Page 805

    Video.Height 805 var my_video:video; // my_video is a video object on the stage var my_nc:netconnection = new netconnection(); my_nc.Connect(null); var my_ns:netstream = new netstream(my_nc); my_video.Attachvideo(my_ns); my_ns.Play("video1.Flv"); deblocking_cb.Additem({data:0, label:'auto'}); debloc...

  • Page 806

    806 chapter 7: actionscript for flash my_mc._width = my_mc.My_video.Width; my_mc._height = my_mc.My_video.Height; break; } }; usage 2: the following example lets the user press a button to set the height and width of a video stream being displayed in the flash player to be the same as the height and...

  • Page 807

    Video.Width 807 }; smoothing_btn.Onrelease = function() { my_video.Smoothing = !My_video.Smoothing; updatesmoothing(); }; function updatesmoothing():void { smoothing_txt.Text = "smoothing = "+my_video.Smoothing; } video.Width availability flash player 6. Usage my_video.Width:number description prope...

  • Page 808

    808 chapter 7: actionscript for flash.

  • Page 809: Appendix A

    809 appendix a deprecated flash 4 operators the following table lists flash 4-only operators, which are deprecated in actionscript 2.0. Do not use these operators unless you are publishing to flash player 4 and earlier. Operator description associativity not logical not right to left and logical and...

  • Page 810

    810 appendix a: deprecated flash 4 operators.

  • Page 811: Appendix B

    811 appendix b keyboard keys and key code values the following tables list all the keys on a standard keyboard and the corresponding ascii key code values that are used to identify the keys in actionscript: • “letters a to z and standard numbers 0 to 9” • “keys on the numeric keypad” on page 813 • “...

  • Page 812

    812 appendix b: keyboard keys and key code values l 76 m 77 n 78 o 79 p 80 q 81 r 82 s 83 t 84 u 85 v 86 w 87 x 88 y 89 z 90 0 48 1 49 2 50 3 51 4 52 5 53 6 54 7 55 8 56 9 57 letter or number key key code.

  • Page 813

    Function keys 813 keys on the numeric keypad the following table lists the keys on a numeric keypad, with the corresponding ascii key code values that are used to identify the keys in actionscript: function keys the following table lists the function keys on a standard keyboard, with the correspondi...

  • Page 814

    814 appendix b: keyboard keys and key code values other keys the following table lists keys on a standard keyboard other than letters, numbers, numeric keypad keys, or function keys, with the corresponding ascii key code values that are used to identify the keys in actionscript: f10 this key is rese...

  • Page 816

    816 appendix b: keyboard keys and key code values.

  • Page 817: Index

    817 index a accessing object properties 38 actions repeating 40 actionscript classpath 64 interfaces 59 actionscript 2.0 overview 45 adding notes to scripts 16 animation, symbols and 21 arguments. See parameters array access operators 38 arrays, multidimensional 39 ascii values function keys 813 key...

  • Page 818

    818 index classes, built-in extending 55 classpaths defined 64 combining operations 37 comments 16 communicating with the flash player 72 comparison operators 34 compile time, defined 6 concatenating strings 19 conditions, checking for 40 constants 11, 18 constructors defined 11 overview 52 conversi...

  • Page 819

    Index 819 g getter/setter methods of classes 63 getting information from remote files 67 global variables 29 and strict data typing 25 grouping statements 15, 16 h http protocol 67 communicating with server-side scripts 69 https protocol 67 i identifiers, defined 12 importing classes 65 information,...

  • Page 820

    820 index o object properties accessing 38 object-oriented programming 45 objects and object-oriented programming 46 data type 21 defined 12 looping through children of 40 operators 12 array access 38 assignment 37 associativity 32 bitwise 36 combining with values 31 comparison 34 deprecated 809 dot...

  • Page 821

    Index 821 syntax case sensitivity 14 curly braces 15, 16 dot 14 parentheses 16 rules 13 semicolon 15 t target paths defined 13 tcp/ip connection sending information 68 with xmlsocket object 72 terminating statements 15 terminology 11 transferring variables between movie and server 70 typing variable...

  • Page 822

    822 index.

  • Page 823: Index of Language Elements

    823 index of language elements symbols – (minus) 93 –– (decrement) 81 ! (logical not) 83 != (inequality) 84 !== (strict inequality) 86 " " (string delimiter) 207 #include 175 % (modulo) 87 %= (modulo assignment) 88 & (bitwise and operator) 89 && (logical and) 90 &= (bitwise and assignment) 91 () (pa...

  • Page 824

    824 index of language elements array.Sort() 248 array.Sorton() 251 array.Splice() 254 array.Tostring() 255 array.Unshift() 256 asfunction 491 b boolean class 258 boolean() 129 boolean.Tostring() 258 boolean.Valueof() 259 break 132 c camera class 492 camera.Activitylevel 493 camera.Bandwidth 494 came...

  • Page 825

    Index of language elements 825 do while 145 duplicatemovieclip() 531 dynamic 147 e else 149 else if 150 error class 287 error.Message 288 error.Name 289 error.Tostring() 289 escape 151 eval() 152 extends 153 f false 156 for 157 for..In 159 fscommand() 161 function 163 function class 291 function.App...

  • Page 826

    826 index of language elements math.Atan() 347 math.Atan2() 348 math.Ceil() 348 math.Cos() 349 math.E 350 math.Exp() 350 math.Floor() 351 math.Ln10 352 math.Ln2 352 math.Log() 351 math.Log10e 353 math.Log2e 353 math.Max() 354 math.Min() 354 math.Pi 355 math.Pow() 356 math.Random() 357 math.Round() 3...

  • Page 827

    Index of language elements 827 movieclip.Linestyle() 587 movieclip.Lineto() 588 movieclip.Loadmovie() 589 movieclip.Loadvariables() 591 movieclip.Localtoglobal() 591 movieclip.Menu 595 movieclip.Moveto() 596 movieclip.Nextframe() 597 movieclip.Ondata 597 movieclip.Ondragout 599 movieclip.Ondragover ...

  • Page 828

    828 index of language elements printjob.Send() 395 printjob.Start() 395 private 195 public 197 r removemovieclip() 667 return 198 s selection class 669 selection.Addlistener() 669 selection.Getbeginindex() 670 selection.Getcaretindex() 671 selection.Getendindex() 672 selection.Getfocus() 673 selecti...

  • Page 829

    Index of language elements 829 system.Capabilities.Os 436 system.Capabilities.Pixelaspectratio 436 system.Capabilities.Playertype 437 system.Capabilities.Screencolor 437 system.Capabilities.Screendpi 437 system.Capabilities.Screenresolutionx 438 system.Capabilities.Screenresolutiony 438 system.Capab...

  • Page 830

    830 index of language elements textformat.Italic 785 textformat.Leading 785 textformat.Leftmargin 786 textformat.Rightmargin 786 textformat.Size 787 textformat.Tabstops 787 textformat.Target 788 textformat.Underline 788 textformat.Url 789 textsnapshot object 790 textsnapshot.Findtext() 790 textsnaps...