| Adding Action Script to your file |
|
| Introduction to ActionScript |
|
| Flash 8 supports ActionScript 2.0 and ActionScript 1.0. ActionScript 2.0 is an integral part of creating a wide range of documents in Flash Pro. Rich Internet applications rely onActionScript 2.0 because it can be used to call up external files, control objects on and off the stage, and create interactivity in flash movies. |
|
| However, ActionScript 2.0 is only one of many tools that make up flash. Therefore although the documents you create with flash will typically contain ActionScript 2.0, they are also made up of different objects created with the array of other tools found in Flash Pro. |
|
| The actions panel along with the Script window is at the heart of the scripting you’ll be doing. All external coding is done in the scripts window, and the internal code preserved in FLA files is created in the Actions Panel. |
|
| The ActionScript scripting language lets you add complex interactivity, playback control, and data display to your application. You can add ActionScript in the authoring environment by using the Actions panel, Script window, or an external editor. |
|
| ActionScript follows its own rules of syntax, reserved keywords, and lets you use variables to store and retrieve information. ActionScript includes a large library of built in classes that let you create objects to perform many useful tasks. |
|
| You don’t need to understand every ActionScript element to begin scripting; if you have a clear goal, you can start building scripts with simple actions. |
|
| Ways of working with ActionScript |
|
| There are several ways to work with ActionScript. |
|
| • Script Assist mode lets you add ActionScript to your FLA file without writing the code yourself. You select actions, and the software presents you with a user-interface for entering the parameters required for each one. You must know a little about what functions to use to accomplish specific tasks, but you don’t have to learn syntax. Many designers and non-programmers use this mode. |
|
| • Behaviors also let you add code to your file without writing it yourself. Behaviors are prewritten scripts for common tasks. You can add a behavior and then easily configure it in the Behaviors panel. Behaviors are available only for ActionScript 2.0 and earlier. |
|
| • Writing your own ActionScript gives you the greatest flexibility and control over your document, but it requires you to become familiar with the ActionScript language and conventions. |
|
| • Components are pre-built movie clips that help you implement complex functionality. A component can be a simple user interface control, such as a check box, or it can be a complicated control, such as a scroll pane. You can customize a component’s functionality and appearance, and you can download components created by other developers. Most components require you to write some ActionScript code of your own to trigger or control a component. |
|
| What is a Variable? |
|
| A variable is the simplest means of keeping track of information in your Flash code. A variable's value can be set once and never changed, or changed often. Values can be set during author-time (when you're creating your Flash file), or determined during run-time, like the score in a game. |
|
| Variables can be thought of as named boxes in which we store information. In order to access the information again we need to know the name of the variable which holds it. We provide the name by which the variable can be referenced when we create (or declare) our variable. |
|
| Declaration let's Flash know that we'd like to create a new variable with a set name to store information in. Of course, a variable with no value is of little use, so generally we wish to define our variable also. Defining a variable is the act of allocating a value to the variable. In Flash, declaration and definition are generally combined into one statement of the form: |
|
| Var variable_name = some value; |
|
| For example, to record that my name is Peter, we could declare and define a new variable called 'myname' as follows: |
|
| Var myname = “Peter”; |
|
| This code consists of the variable definition (which states we are creating a new variable called 'myname') and the value of this variable which is the string "Peter". The semi-colon at the end of the line signifies the end of our ActionScript command (or statement). Flash is quite forgiving if you leave off semi-colons at the end of statements, but strictly-speaking they are required. |
|
| A Note On Variable Naming: |
|
| In the above example, the variable name myname is purely arbitrary; we could have called it 'name' or pretty much anything else. Note however that variable names may not contain spaces or be the same as a reserved Flash keyword. Examples of some reserved keywords are if, else, this, function, and return. |
|
| Variable Declaration |
|
| Creating a variable is called declaration. Declaration is like giving the variable a name. It can also be bringing the variable into existence. When a variable is declared i.e.: var, it is empty. To close a variable you must declare a special value called undefined. (indicating the absence of data). var text; |
|
var movieclip;
var animation; |
|
| The word var tells us that were declaring a variable. Text follows the variable i.e.: text, movieclip, and animation. |
|
| Legal Variables |
|
• It Must be written exclusively of letters, numbers, and underscores.
• No spaces, hyphens, or punctuation.
• It Must start with a letter to an underscore
• It must not exceed 255 characters.
• Variables are case-sensitive |
| Examples of Legal Variables |
|
var computer;
var counter:
var middle_name |
|
| Examples of Illegal Variables |
|
var 1stplace
var my name
var 2-dimes |
|
| Data Types:- |
|
| A data type describes a piece of data and the kinds of operations that can be performed on it. That data is stored in a variable. You use data types when creating variables, object instances, and function definitions. |
|
| ActionScript has the following basic data types that you can use in your applications: |
|
Data type
|
Description
|
| Boolean | The Boolean data type consists of two values: true and false. No other values are valid for variables of this type. The default value of Boolean variable that has been declared but not initialized is false. For more information, see Boolean data type. |
| MovieClip | The MovieClip data type lets you control movie clip symbols using the methods of the MovieClip class. For more information, see MovieClip data type. |
| null | The null data type contains the value null. This value means no value--that is, a lack of data. You can assign the null value in a variety of situations to indicate that a property or variable does not have a value assigned to it. The null data type is the default data type for all classes that define complex data types. An exception to this rule is the Object class, which defaults to undefined. |
| Number | This data type can represent integers, unsigned integers, and floating point numbers. To store a floating point number, you should include a decimal point in the number. Without the decimal point, the number is stored as an integer. The Number data type can store values from Number.MAX_VALUE (very high) to Number.MIN_VALUE (very low). For more information, see ActionScript 2.0 Language Reference and Number data type. |
| Object | The Object data type is defined by the Object class. The Object class serves as the base class for all class definitions in ActionScript, and it lets you arrange objects inside each other (nested objects). For more information, see Object data type. |
| String | The String data type represents a sequence of 16-bit characters that might include letters, numbers, and punctuation marks. Strings are stored as Unicode characters, using the UTF-16 format. An operation on a String value returns a new instance of the string. For more information, see String data type. |
| undefined | The undefined data type contains one value: undefined. This is the default value for instances of the Object class. You can only assign a value of undefined to variables that belong to the Object class. For more information, see undefined data type. |
| Void | The Void data type contains only one value: void. You use this data type to designate functions that don't return a value. Void is a complex data type that references the primitive Void data type. For more information, see Void data type. |
|
|
| The starting point in learning ActionScript or any other programming language is to learn how to use variables. Variables are data containers, you need these to be able to refer to whatever data you want to produce, manipulate or save in ActionScript. |
|
| Variables are named data containers, each of which can hold a single piece of information. We might want to store the user's name in our variable, or in a game situation, use our variable to save the player's score. Once we create a variable, we can recall the data stored inside it as many times as we wish. In addition, we can edit this data, update it, and at some situations, we might even be required to delete the variable completely. |
|
| To create a new empty variable we use the var operator followed by a name to label our variable. The variable's name is called its 'identifier'. The identifier of a variable (i.e. its name) can only contain letters, numbers, underscores, and the dollar sign $. |
|
| It cannot start with a number or contain any spaces. By convention, a variable name should not start with a capital letter either. The process of creating a new empty variable is called "variable declaration", and as we said before, this requires using the var operator. Here is a very basic example: |
|
| var myScore; |
|
| (The semi-colon is used in ActionScript to signify the ending of a statement.) Our variable is still empty and could be used at will to store any sort of data in it. To store data in a variable we use the equal sign operator followed by the value of our data. |
|
var myScore;
myScore = 100; |
|
| We stored the number 100 in our variable 'myScore'. We did this by creating an empty variable first and then assigning the value of 100 to the variable, however, we can shorten the process by creating the variable and adding content to it at the same time this way: |
|
| var myScore = 100; |
|
| We can display the content of our variable using the trace() method which will show the content in an output window when testing the movie in Flash. (By pressing Ctrl+Enter) |
|
var myScore = 100;
trace (myScore); |
|
| This should output the number '100' in the output window. The trace() method is used to test our movie through out simple and complex projects. Anyway, going back to variables, the content of the variable could be recalled at any time by simply writing down the name of the variable as the previous example has showed. It is possible to assign a value to a variable by using values of other variables. |
|
| For example: |
|
var round1score = 100;
var round2score = 200;
var totalScore = round1score + round2score;
trace (totalScore); |
|
| The output window should say "300" in the previous example when the movie is tested. We can modify the content of our variable by simply assigning a new value to it, this requires using the equal sign operator. In the following example we will initiate the variable with the value 100 then change this value to 200 as seen here: |
|
var myScore = 100;
myScore= 200;
trace (myScore); |
|
| There are different types of data in ActionScript, the basic most known data types are strings, numbers, Boolean, and array. Strings are sequences of characters, these are always surrounded by the quotation marks. Examples of strings are: |
|
"Macromedia Flash"
"ActionScript Tutorial on ActionScript"
"1200" |
|
| Notice that numbers surrounded by quotation marks belong to the string data type and not the number data type. For a number to have a mathematical value it has to be written without the quotation marks as we have done in our earlier examples, here are more examples of number values: |
|
1200
1.6
0.22 |
|
| The third most used data type in Flash is the Boolean data type. This data type can only have two values, true or false. |
|
| There are other data types in Flash, but those that we have mentioned are the simples and most commonly used. Variables in flash naturally can accept any type of data at any time, even if the variable initially had a number value, it is possible to overwrite a different data type as a new value for the variable. For example: |
|
var myBox;
myBox = "Tree"; |
|
| I can overwrite this content with any other data type: |
|
var myBox;
myBox = "Tree";
myBox = 234; |
|
| The variable myBox will have at the end, the number value 234. This might sound helpful if we want to have a variable to save whatever data the user gives to it, but this flexibility in reality could cover up nested errors of incompatible data types that are unintentionally assigned to a variable. For example if we put a string instead of a number in this situation we will not get the result intended: |
|
var round1Score = "2";
var round2Score = "3";
var totalScore = round1Score + round2Score;
trace (totalScore); |
|
| Because we made a mistake by putting the numbers 2 and 3 in a string format by using the quotation marks the trace command will generate the value 23 instead of 5. To make sure that we insert the correct data type to a variable we can use the new Strict Data Typing feature Macromedia introduced in Macromedia Flash MX 2004. |
|
| Strict Data Typing allows us to explicitly declare the data type that a certain variable should accept, if the wrong data type is assigned to a variable an error message would pop up when the movie is tested identifying at what line exactly the wrong value was assigned to the variable. Strict Data Typing requires activation for each variable by using the : operator when the variable is declared in the following format: |
|
| var identifier:DataType; |
|
| For example we can make our variable myScore except the number data type this way: |
|
| var myScore:Number; |
|
| This way this variable will not accept any value other than numbers. An error message will be generated when the movie is created telling that the wrong data type was assigned to the variable. We can create another variable that will accept only the string data type this way: |
|
| var myName:String; |
|
| One should not underestimate the benefits of strict data types, they do not only prevent you from assigning an incompatible data type and make error correction much easier, but they also make your code much easier to read because as the intended purposes of the variables that you create become clearer and easier to follow. |
|
| A great other benefit of using Strict Data Typing is that variables to which this feature is enabled activate ActionScript quick reference code hints that pop-up when the variable name is written in ActionScript. This concludes our tutorial, the topic of variables is a massive one and there are a lot of other concepts to learn such as scopes and custom data types. I hope that you learned something new from this tutorial. |
|
| Boolean data type |
|
| The Boolean data type comprises two values: true and false. No other values are valid for variables of Boolean type. The default value of a Boolean variable that has been declared but not initialized is false. |
|
| Null data type |
|
| The Null data type contains only one value, null. This is the default value for the String data type and all classes that define complex data types, including the Object class. None of the other primitive data types, such as Boolean, Number, int and uint, contain the value null. |
|
| Flash Player will convert the value null to the appropriate default value if you attempt to assign null to variables of type Boolean, Number, int, or uint. You cannot use this data type as a type annotation. |
|
| Number data type |
|
| In ActionScript 3.0, the Number data type can represent integers, unsigned integers, and floating-point numbers. However, to maximize performance, you should use the Number data type only for integer values larger than the 32-bit int and uint types can store or for floating-point numbers. To store a floating-point number, include a decimal point in the number. If you omit a decimal point, the number will be stored as an integer. |
|
| The Number data type uses the 64-bit double-precision format as specified by the IEEE Standard for Binary Floating-Point Arithmetic (IEEE-754). This standard dictates how floating-point numbers are stored using the 64 available bits. |
|
| One bit is used to designate whether the number is positive or negative. Eleven bits are used for the exponent, which is stored as base 2. The remaining 52 bits are used to store the significant (also called the mantissa), which is the number that is raised to the power indicated by the exponent. |
|
| By using some of its bits to store an exponent, the Number data type can store floating-point numbers significantly larger than if it used all of its bits for the significant. For example, if the Number data type used all 64 bits to store the significant, it could store a number as large as 265 - 1. By using 11 bits to store an exponent, the Number data type can raise its significant to a power of 21023. |
|
| The Number data type uses 52 bits to store the significant, with the result that numbers that require more than 52 bits to represent precisely, such as the fraction 1/3, are only approximations. If your application requires absolute precision with decimal numbers, you need to use software that implements decimal floating-point arithmetic as opposed to binary floating-point arithmetic. |
|
| When you store integer values with the Number data type, only the 52 bits of the significant are used. The Number data type uses these 52 bits and a special hidden bit to represent integers from -9,007,199,254,740,992 (-253) to 9,007,199,254,740,992 (253). |
|
| Flash Player uses the Nan value not only as the default value for variables of type Number, but also as the result of any operation that should return a number but does not. For example, if you attempt to calculate the square root of a negative number, the result will be Nan. Other special Number values include positive infinity and negative infinity. |
|
| String data type |
|
| The String data type represents a sequence of 16-bit characters. Strings are stored internally as Unicode characters, using the UTF-16 format. Strings are immutable values, just as they are in the Java programming language. An operation on a String value returns a new instance of the string. The default value for a variable declared with the String data type is null. The value null is not the same as the empty string (""), even though they both represent the absence of any characters. |
|
| void data type |
|
| The void data type contains only one value, undefined. In previous versions of ActionScript, undefined was the default value for instances of the Object class. In ActionScript 3.0, the default value for Object instances is null. |
|
| If you attempt to assign the value undefined to an instance of the Object class, Flash Player will convert the value to null. You can only assign a value of undefined to variables that are untyped. Untyped variables are variables that either lack any type annotation, or use the asterisk (*) symbol for type annotation. You can use void only as a return type annotation. |
|
| Object data type |
|
| The Object data type is defined by the Object class. The Object class serves as the base class for all class definitions in ActionScript. The ActionScript 3.0 version of the Object data type differs from that of previous versions in three ways. |
|
| First, the Object data type is no longer the default data type assigned to variables with no type annotation. Second, the Object data type no longer includes the value undefined, which used to be the default value of Object instances. Third, in ActionScript 3.0, the default value for instances of the Object class is null. |
|
| Operators |
|
| Symbolic operators are characters that specify how to combine, compare, or modify the values of an expression. |
|
Operators
|
Description
|
| + (addition) | Adds numeric expressions or concatenates (combines) strings. |
| += (addition assignment) | Assigns expression1 the value of expression1 + expression2. |
| [] (array access) | Initializes a new array or multidimensional array with the specified elements (a0 , and so on), or accesses elements in an array. |
| = (assignment) | Assigns the value of expression2 (the parameter on the right) to the variable, array element, or property in expression1. |
| & (bitwise AND) | Converts expression1 and expression2 to 32-bit unsigned integers, and performs a Boolean AND operation on each bit of the integer parameters. |
| &= (bitwise AND assignment) | Assigns expression1 the value of expression1& expression2. |
| << (bitwise left shift) | Converts expression1 and expression2 to 32-bit integers, and shifts all the bits in expression1 to the left by the number of places specified by the integer resulting from the conversion of expression2. |
| <<= (bitwise left shift and assignment) | This operator performs a bitwise left shift (<<=) operation and stores the contents as a result in expression1. |
| ~ (bitwise NOT) | Also known as the one's complement operator or the bitwise complement operator. |
| | (bitwise OR) | Converts expression1 and expression2 to 32-bit unsigned integers, and returns a 1 in each bit position where the corresponding bits of eitherexpression1 or expression2 are 1. |
| |= (bitwise OR assignment) | Assigns expression1 the value of expression1 | expression2. |
| >> (bitwise right shift) | Converts expression1 and expression2 to 32-bit integers, and shifts all the bits in expression1 to the right by the number of places specified by the integer that results from the conversion of expression2. |
| >>= (bitwise right shift and assignment) | This operator performs a bitwise right-shift operation and stores the contents as a result in expression1. |
| >>> (bitwise unsigned right shift) | The same as the bitwise right shift (>> ) operator except that it does not preserve the sign of the original expression because the bits on the left are always filled with 0. Floating-point numbers are converted to integers by discarding any digits after the decimal point. |
| >>>= (bitwise unsigned right shift and assignment) | Performs an unsigned bitwise right-shift operation and stores the contents as a result in expression1. |
| ^ (bitwise XOR) | Converts expression1 and expression2 to 32-bit unsigned integers, and returns a 1 in each bit position where the corresponding bits inexpression1 or expression2 , but not both, are 1. |
| ^= (bitwise XOR assignment) | Assigns expression1 the value of expression1 ^ expression2. |
| /*..*/ (block comment delimiter) | Indicates one or more lines of script comments. |
| , (comma) | Evaluates expression1 , then expression2 , and so on. |
| add (concatenation (strings)) | Macromedia recommends that you use the add (+) operator when creating content for Flash Player 5 or later. This operator is not supported in Flash Player 8 or later.
Concatenates two or more strings. |
| ?: (conditional) | Instructs Flash to evaluate expression1 , and if the value of expression1 is true , it returns the value of expression2 ; otherwise it returns the value of expression3. |
| -- (decrement) | A pre-decrement and post-decrement unary operator that subtracts 1 from the expression. |
| / (division) | Divides expression1 by expression2. |
| /= (division assignment) | Assigns expression1 the value of expression1 / expression2. |
| . (dot) | Used to navigate movie clip hierarchies to access nested (child) movie clips, variables, or properties. |
| == (equality) | Tests two expressions for equality. |
| eq (equality (strings)) | This operator was deprecated in favor of the == (equality) operator.
Returns true if the string representation of expression1 is equal to the string representation of expression2, false otherwise. |
| > (greater than) | Compares two expressions and determines whether expression1 is greater than expression2; if it is, the operator returns true. |
| gt (greater than (strings)) | This operator was deprecated in favor of the > (greater than) operator.
Compares the string representation of expression1 with the string representation of expression2 and returns true if expression1 is greater than expression2, false otherwise. |
| >= (greater than or equal to) | Compares two expressions and determines whether expression1 is greater than or equal to expression2 (true) or expression1 is less thanexpression2 (false). |
| ge (greater than or equal to (strings)) | This operator was deprecated in favor of the >= (greater than or equal to) operator.
Returns true if expression1 is greater than or equal to expression2, false otherwise. |
| ++ (increment) | A pre-increment and post-increment unary operator that adds 1 toexpression . |
| != (inequality) | Tests for the exact opposite of the equality (== ) operator. |
| <> (inequality) | This operator has been deprecated. Macromedia recommends that you use the != (inequality) operator.
Tests for the exact opposite of the equality (==) operator. |
| instanceof | Tests whether object is an instance of classConstructor or a subclass of classConstructor. |
| < (less than) | Compares two expressions and determines whether expression1 is less than expression2 ; if so, the operator returns true. |
| lt (less than (strings)) | This operator was deprecated in favor of the < (less than) operator.
Returns true if expression1 is less than expression2, false otherwise. |
| <= (less than or equal to) | Compares two expressions and determines whether expression1 is less than or equal to expression2 ; if it is, the operator returns true. |
| le (less than or equal to (strings)) | This operator was deprecated in Flash 5 in favor of the <= (less than or equal to) operator.
Returns true if expression1 is less than or equal to expression2, false otherwise. |
| // (line comment delimiter) | Indicates the beginning of a script comment. |
| && (logical AND) | Performs a Boolean operation on the values of both expressions. |
| and (logical AND) | Macromedia recommends that you use the logical AND (&&) operator.
Performs a logical AND (&&) operation in Flash Player 4. |
| ! (logical NOT) | Inverts the Boolean value of a variable or expression. |
| not (logical NOT) | This operator was deprecated in favor of the! (logical NOT) operator.
Performs a logical NOT (!) operation in Flash Player 4. |
| || (logical OR) | Evaluates expression1 (the expression on the left side of the operator) and returns true if the expression evaluates to true. |
| or (logical OR) | This operator was deprecated in favor of the || (logical OR) operator.
Evaluates condition1 and condition2, and if either expression is true, the whole expression is true. |
| % (modulo) | Calculates the remainder of expression1 divided by expression2. |
| %= (modulo assignment) | Assigns expression1 the value of expression1 % expression2. |
| * (multiplication) | Multiplies two numerical expressions. |
| *= (multiplication assignment) | Assigns expression1 the value of expression1 * expression2. |
| new | Creates a new, initially anonymous, object and calls the function identified by the constructor parameter. |
| ne (not equal (strings)) | This operator was deprecated in favor of the != (inequality) operator.
Returns true if expression1 is not equal to expression2; false otherwise. |
| {} (object initializer) | Creates a new object and initializes it with the specified name and valueproperty pairs. |
| () (parentheses) | Performs a grouping operation on one or more parameters, performs sequential evaluation of expressions, or surrounds one or more parameters and passes them as parameters to a function outside the parentheses. |
| === (strict equality) | Tests two expressions for equality; the strict equality (=== )operator performs in the same way as the equality (== ) operator, except that data types are not converted. |
| !== (strict inequality) | Tests for the exact opposite of the strict equality ( === ) operator. |
| " (string delimiter) | When used before and after characters, quotation marks (") indicate that the characters have a literal value and are considered a string, not a variable, numerical value, or other ActionScript element. |
| - (subtraction) | Used for negating or subtracting. |
| -= (subtraction assignment) | Assigns expression1 the value of expression1 - expression2. |
| : (type) | Used for strict data typing; this operator specifies the variable type, function return type, or function parameter type. |
| typeof | The typeof operator evaluate the expression and returns a string specifying whether the expression is a String, MovieClip, Object, Function, Number, or Boolean value. |
| void | The void operator evaluates an expression and then discards its value, returning undefined |
|
|
| Mouse classes |
|
| The Mouse class lets you control the mouse in a SWF file; for example, this class lets you hide or show the mouse pointer. |
|
| The following tables lists the methods and events attached to the mouse class. In Flash movies where the mouse sis required, you can use the Mouse class. |
|
| Mouse Methods:- |
|
Method
|
Actions
|
| Mouse.addListener(obj) | Registers an object (obj) to receive notifications of the onMouseDown, onMouseMove, onMouseUp, and onMouseWheel listeners. |
| Mouse.hide() | Hides the mouse pointer in a SWF file. |
| Mouse.removeListener(obj) | Removes the listner from an object (obj) that was previously registered with addListener (). |
| Mouse.show() | Shows the mouse pointer in a SWF file. |
|
|
| Mouse Events:- |
|
Method
|
Actions
|
| Mouse.onMouseDown() | The Down state of the mouse button triggers notification to listener subscribers. |
| Mouse.onMouseMove() | Any mouse movement triggers notification to lieteners subscribers. |
| Mouse.onMouseUp() | The Up state of the mouse button triggers notification to listener subscribers. |
| Mouse.onMouseWheel() | The mouse wheel triggers notification to listener subscribers. |
|
|
| MovieClip class |
|
| The methods for the MovieClip class provide the same functionality as actions that target movie clips. There are also additional methods that do not have equivalent actions in the Actions toolbox in the Actions panel. |
|
| To call the methods of the MovieClip class, you refer the movie clip instances by name, using the following syntax: |
|
my_mc.play();
my_mc.gotoAndPlay(3); |
|
| The following tables lists the methods and events attached to the mouse class. In Flash movies where the mouse sis required, you can use the Mouse class. |
|
| MovieClip Methods:- |
|
Method
|
Description
|
| MovieClip.attachAudio() | Captures and plays local audio from the microphone hardware. |
| MovieClip.attachMovie() | Attaches a SWF file or movie clip in the library. |
| MovieClip.createEmptyMovieClip() | Creates an empty movie clip. |
| MovieClip.createTextField() | Creates an empty text field. |
| MovieClip.duplicateMovieClip() | Duplicates the specified movie clip. |
| MovieClip.getBounds() | Returns the minimum and maximum x and ycoordinates of a SWF file in a specified coordinate space. |
| MovieClip.getBytesLoaded() | Returns the number of bytes loaded for the specified movie clip. |
| MovieClip.getBytesTotal() | Returns the size of the movie clip, in bytes. |
| MovieClip.getDepth() | Returns the depth of a movie clip. |
| MovieClip.getInstanceAtDepth() | Returns the movie clip instance from a particular depth if it exists. |
| MovieClip.getNextHighestDepth() | Returns the next available depth that can be passed to other methods. This ensures that Flash renders the movie clip in front of all other objects in the current movie clip. |
| MovieClip.getSWFVersion() | Returns an integer that indicates the Flash Player version for which the movie clip was published. |
| MovieClip.getTextSnapshot() | Returns a TextSnapshot object that contains the text in the static text fields in the specified movie clip. |
| MovieClip.getURL() | Retrieves a document from a URL. |
| MovieClip.globalToLocal() | Converts Stage coordinates to the local coordinates of the specified movie clip. |
| MovieClip.gotoAndPlay() | Sends the playhead to a specific frame in the movie clip and plays the movie clip. |
| MovieClip.gotoAndStop() | Sends the playhead to a specific frame in the movie clip and stops the movie clip. |
| MovieClip.hitTest() | Returns true if bounding box of the specified movie clip intersects the bounding box of the target movie clip. |
| MovieClip.loadMovie() | Loads the specified SWF or JPEG file into the movie clip. |
| MovieClip.loadVariables() | Loads variables from a URL or other location into the movie clip. |
| MovieClip.localToGlobal() | Converts local coordinates of the movie clip to the global Stage. |
| MovieClip.nextFrame() | Sends the playhead to the next frame of the movie clip. |
| MovieClip.play() | Plays the specified movie clip. |
| MovieClip.prevFrame() | Sends the playhead to the previous frame of the movie clip. |
| MovieClip.removeMovieClip() | Removes the movie clip from the Timeline if it was created with duplicateMovieClip(), MovieClip.duplicateMovieClip(), or MovieClip.attachMovie(). |
| MovieClip.setMask() | Sets a movie clip as the mask for the specified movie clip. |
| MovieClip.startDrag() | Specifies a movie clip as draggable and begins dragging the movie clip. |
| MovieClip.stop() | Stops the currently playing movie clip. |
| MovieClip.stopDrag() | Stops the dragging of any movie clip that is being dragged. |
| MovieClip.swapDepths() | Swaps the depth level of two movie clips. |
| MovieClip.unloadMovie() | Removes a SWF file that was loaded with MovieClip.loadMovie(). |
|
|
| MovieClip Properties- |
|
Property
|
Description
|
| MovieClip._alpha | The transparency value of a movie clip instance. |
| MovieClip._currentframe | Read-only; the frame number in which the playhead is currently located. |
| MovieClip._droptarget | Read-only; the absolute path in slash syntax notation of the movie clip instance on which a draggable movie clip was dropped. |
| MovieClip.enabled | A Boolean value that indicates whether a movie clip is enabled. |
| MovieClip.focusEnabled | A Boolean value that enables a movie clip to receive focus. |
| MovieClip._focusrect | A Boolean value that indicates whether a focused movie clip has a yellow rectangle around it. |
| MovieClip._framesloaded | Read-only; the number of frames that have been loaded from a streaming SWF file. |
| MovieClip._height | The height of a movie clip instance, in pixels. |
| MovieClip.hitArea | A reference to a movie clip that serves as the hit area for another movie clip. |
| MovieClip._lockroot | The specification of what _root refers to when a SWF file is loaded into a movie clip. |
| MovieClip.menu | An object that associates a ContextMenu object with a movie clip. |
| MovieClip._name | The instance name of a movie clip instance. |
| MovieClip._parent | A reference to the movie clip that encloses the movie clip. |
| MovieClip._quality | A string that sets the rendering quality of a SWF file. |
| MovieClip._rotation | The degree of rotation of a movie clip instance. |
| MovieClip._soundbuftime | The number of seconds before a sound starts to stream. |
| MovieClip.tabChildren | A Boolean value that indicates whether the children of a movie clip are included in automatic tab ordering. |
| MovieClip.tabEnabled | A Boolean value that indicates whether a movie clip is included in tab ordering. |
| MovieClip.tabIndex | A number that indicates the tab order of an object. |
| MovieClip._target | Read-only; the target path of a movie clip instance. |
| MovieClip._totalframes | Read-only; the total number of frames in a movie clip instance. |
| MovieClip.trackAsMenu | A Boolean value that indicates whether other movie clips can receive mouse release events. |
| MovieClip._url | Read-only; the URL of the SWF file from which a movie clip was downloaded. |
| MovieClip.useHandCursor | A Boolean value that determines whether the hand is displayed when the mouse rolls over a movie clip. |
| MovieClip._visible | A Boolean value that determines whether a movie clip instance is hidden or visible. |
| MovieClip._width | The width of a movie clip instance, in pixels. |
| MovieClip._x | The x coordinate of a movie clip instance |
| MovieClip._xmouse | Read-only; the x coordinate of the mouse pointer within a movie clip instance. |
| MovieClip._xscale | The value specifying the percentage that the movie clip is scaled horizontally. |
| MovieClip._y | The y coordinate of a movie clip instance. |
| MovieClip._ymouse | Read-only; the y coordinate of the mouse pointer within a movie clip instance. |
| MovieClip._yscale | The value specifying the percentage for vertically scaling a movie clip. |
|
|
| MovieClip Event Handler:- |
|
Event handler
|
Description
|
| MovieClip.onData |
Invoked when all the data is loaded into a movie clip.
|
| MovieClip.onDragOut | Invoked when the mouse button is pressed inside the movie clip area and then rolled outside the movie clip area. |
| MovieClip.onDragOver | Invoked when the mouse pointer is dragged over the movie clip. |
| MovieClip.onEnterFrame | Invoked continually at the frame rate of the SWF file. The actions associated with the enterFrame event are processed before any frame actions that are attached to the affected frames. |
| MovieClip.onKeyDown | Invoked when a key is pressed. Use the Key.getCode() and Key.getAscii() methods to retrieve information about the last key pressed. |
| MovieClip.onKeyUp | Invoked when a key is released. |
| MovieClip.onKillFocus | Invoked when focus is removed from a movie clip. |
| MovieClip.onLoad | Invoked when the movie clip is instantiated and appears in the Timeline. |
| MovieClip.onMouseDown | Invoked when the left mouse button is pressed. |
| MovieClip.onMouseMove | Invoked every time the mouse is moved. |
| MovieClip.onMouseUp | Invoked when the left mouse button is released. |
| MovieClip.onPress | Invoked when the mouse is pressed while the pointer is over a movie clip. |
| MovieClip.onRelease | Invoked when the mouse is released while the pointer is over a movie clip. |
| MovieClip.onReleaseOutside | Invoked when the mouse is clicked over a movie clip and released while the pointer is outside the movie clip's area. |
| MovieClip.onRollOut | Invoked when the pointer rolls outside of a movie clip area. |
| MovieClip.onRollOver | Invoked when the mouse pointer rolls over a movie clip. |
| MovieClip.onSetFocus | Invoked when a movie clip has input focus and a key is released. |
| MovieClip.onUnload | Invoked in the first frame after the movie clip is removed from the Timeline. The actions associated with the Unload movie clip event are processed before any actions are attached to the affected frame. |
|
|
| Date class |
|
| The Date class lets you retrieve date and time values relative to universal time (Greenwich mean time, now called universal time or UTC) or relative to the operating system on which Flash Player is running. The methods of the Date class are not static but apply only to the individual Date object specified when the method is called. The Date.UTC() method is an exception; it is a static method. |
|
| To call the methods of the Date class, you must first create a Date object using the constructor for the Date class, described later in this section. |
|
| Date Class Methods:- |
|
Signature
|
Description
|
| getDate() : Number | Returns the day of the month (an integer from 1 to 31) of the specified Date object according to local time. |
| getDay() : Number | Returns the day of the week (0 for Sunday, 1 for Monday, and so on) of the specified Date object according to local time. |
| getFullYear() : Number | Returns the full year (a four-digit number, such as 2000) of the specified Date object, according to local time. |
| getHours() : Number | Returns the hour (an integer from 0 to 23) of the specified Date object, according to local time. |
| getMilliseconds() : Number | Returns the milliseconds (an integer from 0 to 999) of the specified Date object, according to local time. |
| getMinutes() : Number | Returns the minutes (an integer from 0 to 59) of the specified Date object, according to local time. |
| getMonth() : Number | Returns the month (0 for January, 1 for February, and so on) of the specified Date object, according to local time. |
| getSeconds() : Number | Returns the seconds (an integer from 0 to 59) of the specified Date object, according to local time. |
| getTime() : Number | Returns the number of milliseconds since midnight January 1, 1970, universal time, for the specified Date object. |
| getTimezoneOffset() : Number | Returns the difference, in minutes, between the computer's local time and universal time. |
| getUTCDate() : Number | Returns the day of the month (an integer from 1 to 31) in the specified Date object, according to universal time. |
| getUTCDay() : Number | Returns the day of the week (0 for Sunday, 1 for Monday, and so on) of the specified Date object, according to universal time. |
| getUTCFullYear() : Number | Returns the four-digit year of the specified Date object, according to universal time. |
| getUTCHours() : Number | Returns the hour (an integer from 0 to 23) of the specified Date object, according to universal time. |
| getUTCMilliseconds() : Number | Returns the milliseconds (an integer from 0 to 999) of the specified Date object, according to universal time. |
| getUTCMinutes() : Number | Returns the minutes (an integer from 0 to 59) of the specified Date object, according to universal time. |
| getUTCMonth() : Number | Returns the month (0 [January] to 11 [December]) of the specified Date object, according to universal time. |
| getUTCSeconds() : Number | Returns the seconds (an integer from 0 to 59) of the specified Date object, according to universal time. |
| getUTCYear() : Number | Returns the year of this Date according to universal time (UTC). |
| getYear() : Number | Returns the year of the specified Date object, according to local time. |
| setDate(date:Number) : Number | Sets the day of the month for the specified Date object, according to local time, and returns the new time in milliseconds. |
| setFullYear(year:Number, [month:Number], [date:Number]) : Number | Sets the year of the specified Date object, according to local time and returns the new time in milliseconds. |
| setHours(hour:Number) : Number | Sets the hours for the specified Date object according to local time and returns the new time in milliseconds. |
| setMilliseconds(millisecond:Number) : Number | Sets the milliseconds for the specified Date object according to local time and returns the new time in milliseconds. |
| setMinutes(minute:Number) : Number | Sets the minutes for a specified Date object according to local time and returns the new time in milliseconds. |
| setMonth(month:Number, [date:Number]) : Number | Sets the month for the specified Date object in local time and returns the new time in milliseconds. |
| setSeconds(second:Number) : Number | Sets the seconds for the specified Date object in local time and returns the new time in milliseconds. |
| setTime(millisecond:Number) : Number | Sets the date for the specified Date object in milliseconds since midnight on January 1, 1970, and returns the new time in milliseconds. |
| setUTCDate(date:Number) : Number | Sets the date for the specified Date object in universal time and returns the new time in milliseconds. |
| setUTCFullYear(year:Number, [month:Number], [date:Number]) : Number | Sets the year for the specified Date object (my_date) in universal time and returns the new time in milliseconds. |
| setUTCHours(hour:Number, [minute:Number], [second:Number], [millisecond:Number]) : Number | Sets the hour for the specified Date object in universal time and returns the new time in milliseconds. |
| setUTCMilliseconds(millisecond:Number) : Number | Sets the milliseconds for the specified Date object in universal time and returns the new time in milliseconds. |
| setUTCMinutes(minute:Number, [second:Number], [millisecond:Number]) : Number | Sets the minute for the specified Date object in universal time and returns the new time in milliseconds. |
| setUTCMonth(month:Number, [date:Number]) : Number | Sets the month, and optionally the day, for the specified Date object in universal time and returns the new time in milliseconds. |
| setUTCSeconds(second:Number, [millisecond:Number]) : Number | Sets the seconds for the specified Date object in universal time and returns the new time in milliseconds. |
| setYear(year:Number) : Number | Sets the year for the specified Date object in local time and returns the new time in milliseconds. |
| toString() : String | Returns a string value for the specified date object in a readable format. |
| UTC(year:Number, month:Number, [date:Number], [hour:Number], [minute:Number], [second:Number], [millisecond:Number]) : Number | Returns the number of milliseconds between midnight on January 1, 1970, universal time, and the time specified in the parameters. |
| valueOf() : Number | Returns the number of milliseconds since midnight January 1, 1970, universal time, for this Date. |
|
|
| TextField class |
|
| TextField Class Properties:- |
|
Property
|
Description
|
| _alpha:Number | Sets or retrieves the alpha transparency value of the text field. |
| antiAliasType:String | The type of anti-aliasing used for this TextField instance. |
| autoSize:Object | Controls automatic sizing and alignment of text fields. |
| background:Boolean | Specifies if the text field has a background fill. |
| backgroundColor:Number | The color of the text field background. |
| border:Boolean | Specifies if the text field has a border. |
| borderColor:Number | The color of the text field border. |
| bottomScroll:Number [read-only] | An integer (one-based index) that indicates the bottommost line that is currently visible the text field. |
| condenseWhite:Boolean | 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. |
| embedFonts:Boolean | Specifies whether to render using embedded font outlines. |
| filters:Array | An indexed array containing each filter object currently associated with the text field. |
| gridFitType:String | The type of grid fitting used for this TextField instance. |
| _height:Number | The height of the text field in pixels. |
| _highquality:Number | This property was deprecated in favor of TextField._quality.
Specifies the level of anti-aliasing applied to the current SWF file. |
| hscroll:Number | Indicates the current horizontal scrolling position. |
| html:Boolean | A flag that indicates whether the text field contains an HTML representation. |
| htmlText:String | If the text field is an HTML text field, this property contains the HTML representation of the text field's contents. |
| length:Number [read-only] | Indicates the number of characters in a text field. |
| maxChars:Number | Indicates the maximum number of characters that the text field can contain. |
| maxhscroll:Number [read-only] | Indicates the maximum value of TextField.hscroll. |
| maxscroll:Number [read-only] | Indicates the maximum value of TextField.scroll. |
| menu:ContextMenu | Associates the ContextMenu object contextMenu with the text field my_txt. |
| mouseWheelEnabled:Boolean | A Boolean value that indicates whether Flash Player should automatically scroll multiline text fields when the mouse pointer clicks a text field and the user rolls the mouse wheel. |
| multiline:Boolean | Indicates whether the text field is a multiline text field. |
| _name:String | The instance name of the text field. |
| _parent:MovieClip | A reference to the movie clip or object that contains the current text field or object. |
| password:Boolean | Specifies whether the text field is a password text field. |
| _quality:String | The rendering quality used for a SWF file. |
| restrict:String | Indicates the set of characters that a user may enter into the text field. |
| _rotation:Number | The rotation of the text field, in degrees, from its original orientation. |
| scroll:Number | The vertical position of text in a text field. |
| selectable:Boolean | A Boolean value that indicates whether the text field is selectable. |
| sharpness:Number | The sharpness of the glyph edges in this TextField instance. |
| _soundbuftime:Number | The number of seconds a sound prebuffers before it starts to stream. |
| styleSheet:StyleSheet | Attaches a style sheet to the text field. |
| tabEnabled:Boolean | Specifies whether the text field is included in automatic tab ordering. |
| tabIndex:Number | Lets you customize the tab ordering of objects in a SWF file. |
| _target:String [read-only] | The target path of the text field instance. |
| text:String | Indicates the current text in the text field. |
| textColor:Number | Indicates the color of the text in a text field. |
| textHeight:Number | Indicates the height of the text. |
| textWidth:Number | Indicates the width of the text. |
| thickness:Number | The thickness of the glyph edges in this TextField instance. |
| type:String | Specifies the type of text field. |
| _url:String [read-only] | Retrieves the URL of the SWF file that created the text field. |
| variable:String | The name of the variable that the text field is associated with. |
| _visible:Boolean | A Boolean value that indicates whether the text field my_txtis visible. |
| _width:Number | The width of the text field, in pixels. |
| wordWrap:Boolean | A Boolean value that indicates if the text field has word wrap. |
| _x:Number | An integer that sets the x coordinate of a text field relative to the local coordinates of the parent movie clip. |
| _xmouse:Number [read-only] | Returns the x coordinate of the mouse position relative to the text field. |
| _xscale:Number | Determines the horizontal scale of the text field as applied from the registration point of the text field, expressed as a percentage. |
| _y:Number | The y coordinate of a text field relative to the local coordinates of the parent movie clip. |
| _ymouse:Number [read-only] | Indicates the y coordinate of the mouse position relative to the text field. |
| _yscale:Number | The vertical scale of the text field as applied from the registration point of the text field, expressed as a percentage. |
|
|
| TextField Class Events:- |
|
Event
|
Description
|
| onChanged = function(changedField:TextField) {} | Event handler/listener; invoked when the content of a text field changes. |
| onKillFocus = function(newFocus:Object) {} | Invoked when a text field loses keyboard focus. |
| onScroller = function(scrolledField:TextField) {} | Event handler/listener; invoked when one of the text field scroll properties changes. |
| onSetFocus = function(oldFocus:Object) {} | Invoked when a text field receives keyboard focus. |
|
|
| TextField Class Methods:- |
|
Methods
|
Description
|
| addListener(listener:Object) : Boolean | Registers an object to receive TextField event notifications. |
| getDepth() : Number | Returns the depth of a text field. |
| getFontList() : Array | Returns the names of fonts on the player's host system as an array. |
| getNewTextFormat() : TextFormat | Returns a TextFormat object containing a copy of the text field's text format object. |
| getTextFormat([beginIndex:Number], [endIndex:Number]) : TextFormat | Returns a TextFormat object for a character, a range of characters, or an entire TextField object. |
| removeListener(listener:Object) : Boolean | Removes a listener object previously registered to a text field instance with TextField.addListener(). |
| removeTextField() : Void | Removes the text field. |
| replaceSel(newText:String) : Void | Replaces the current selection with the contents of the newText parameter. |
| replaceText(beginIndex:Number, endIndex:Number, newText:String) : Void | Replaces a range of characters, specified by the beginIndex and endIndex parameters, in the specified text field with the contents of the newText parameter. |
| setNewTextFormat(tf:TextFormat) : Void | Sets the default new text format of a text field. |
| setTextFormat([beginIndex:Number], [endIndex:Number], textFormat:TextFormat) : Void | Applies the text formatting specified by the textFormat parameter to some or all of the text in a text field. |
|
|
| TextFormat class |
|
| TextFormat Class Properties:- |
|
Property
|
Description
|
| align:String | A string that indicates the alignment of the paragraph. |
| blockIndent:Number | A number that indicates the block indentation in points. |
| bold:Boolean | A Boolean value that specifies whether the text is boldface. |
| bullet:Boolean | A Boolean value that indicates that the text is part of a bulleted list. |
| color:Number | Indicates the color of text. |
| font:String | The name of the font for text in this text format, as a string. |
| indent:Number | An integer that indicates the indentation from the left margin to the first character in the paragraph. |
| italic:Boolean | A Boolean value that indicates whether text in this text format is italicized. |
| kerning:Boolean | A Boolean value that indicates whether kerning is enabled or disabled. |
| leading:Number | An integer that represents the amount of vertical space in pixels (called leading) between lines. |
| leftMargin:Number | The left margin of the paragraph, in points. |
| letterSpacing:Number | The amount of space that is uniformly distributed between characters. |
| rightMargin:Number | The right margin of the paragraph, in points. |
| size:Number | The point size of text in this text format. |
| tabStops:Array | Specifies custom tab stops as an array of non-negative integers. |
| target:String | Indicates the target window where the hyperlink is displayed. |
| underline:Boolean | A Boolean value that indicates whether the text that uses this text format is underlined (true) or not (false). |
| url:String | Indicates the URL that text in this text format hyperlinks to. |
|
|
| Using loops |
|
| ActionScript can repeat an action a specified number of times or while a specific condition exists. Loops let you repeat a series of statements when a particular condition is true. There are four types of loops in ActionScript: for loops, for..in loops, while loops, and do..while loops. Each type of loop behaves somewhat differently, and each one is useful for different purposes. |
|
| Most loops use some kind of counter to control how many times the loop executes. Each execution of a loop is called an iteration. You can declare a variable and write a statement that increases or decreases the variable each time the loop executes. In the for action, the counter and the statement that increments the counter are part of the action. |
|
Loop
|
Description
|
| for loops | Repeat an action using a built-in counter. |
| for..in loops | Iterate over the children of a movie clip or object. |
| while loops | Repeat an action while a condition exists. |
| do..while loops | Similar to while loops, except the expression evaluates at the bottom of the code block, so the loop always runs at least once. |
|
|
| The most common type of loop is the for loop, which loops over a block of code a predefined number of times. For example, if you have an array of items, and you want to perform a series of statements on each item in the array, you would use a for loop and loop from 0 to the number of items in the array. |
|
| Another type of loop is the for..in loop, which can be very useful when you want to loop over each name/value pair within an object and then perform some type of action. This can be very useful when you are debugging your Flash projects and want to display the values that load from external sources, such as web services or external text/XML files. |
|
| The final two types of loops (while and do..while) are useful when you want to loop over a series of statements but you don't necessarily know how many times you need to loop. In this case you can use a while loop that loops as long as a certain condition is true. |
|
| ActionScript can repeat an action a specified number of times or while a specific condition exists. Use the while, do..while, for, and for..in actions to create loops. This section contains general information on these loops. See the following procedures for more information on each of these loops. |
|
| To repeat an action while a condition exists: |
|
| • Use the while statement. |
|
| A while loop evaluates an expression and executes the code in the body of the loop if the expression is true. After each statement in the body is executed, the expression is evaluated again. In the following example, the loop executes four times: |
|
var i:Number = 4;
while (i > 0) {
myClip.duplicateMovieClip("newMC" + i, i, {_x:i*20,
_y:i*20});
i--;
} |
|
| You can use the do..while statement to create the same kind of loop as a while loop. In a do..while loop, the expression is evaluated at the bottom of the code block so that the loop always runs at least once. |
|
| This is shown in the following example: |
|
var i:Number = 4;
do { myClip.duplicateMovieClip("newMC" + i, i, {_x:i*20, _y:i*20});
i--;
}
while (i > 0); |
|
| To repeat an action using a built-in counter: |
|
| • Use the for statement. |
|
| Most loops use some kind of counter to control how many times the loop executes. Each execution of a loop is called an iteration. You can declare a variable and write a statement that increases or decreases the variable each time the loop executes. In the for action, the counter and the statement that increments the counter are part of the action. |
|
| In the following example, the first expression (var i:Number = 4) is the initial expression that is evaluated before the first iteration. The second expression (i > 0) is the condition that is checked each time before the loop runs. The third expression (i--) is called the post expression and is evaluated each time after the loop runs. |
|
for (var i:Number = 4; i > 0; i--)
{
myClip.duplicateMovieClip("newMC" + i, i, {_x:i*20,
_y:i*20});
} |
|
| To loop through the children of a movie clip or an object: |
|
| • Use the for..in statement. |
|
| Most loops use some kind of counter to control how many times the loop executes. Each execution of a loop is called an iteration. You can declare a variable and write a statement that increases or decreases the variable each time the loop executes. In the for action, the counter and the statement that increments the counter are part of the action. |
|
| In the following example, the first expression (var i:Number = 4) is the initial expression that is evaluated before the first iteration. The second expression (i > 0) is the condition that is checked each time before the loop runs. The third expression (i--) is called the post expression and is evaluated each time after the loop runs. |
|
for (var i:Number = 4; i > 0; i--)
{
myClip.duplicateMovieClip("newMC" + i, i, {_x:i*20,
_y:i*20});
} |
|
| To loop through the children of a movie clip or an object: |
|
| • Use the for..in statement. |
|
| Children include other movie clips, 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'};
var propertyName:String;
for (propertyName in myObject)
{
trace("myObject has the property: " + propertyName + ",
with the value: " + myObject[propertyName]);
}
|
|
| This example produces the following results in the Output panel: |
|
myObject has the property: name, with the value: Joe
myObject has the property: age, with the value: 25
myObject has the property: city, with the value: San Francisco |
|
| You might want your script to iterate over a particular type of child--for example, over only movie clip children. You can do this using for..in with the typeof operator. In the following example, a child movie clip instance (called instance2) is inside a movie clip instance on the Stage. Add the following ActionScript to Frame 1 of the Timeline: |
|
for (var myName in this)
{
if (typeof (this[myName]) == "movieclip")
{
trace("I have a movie clip child named " + myName);
}
}
|
|
|
|
|
|
| Adding Action Script to your file |
|
| Playing and Pausing a movie clip:- |
|
| 1. For playing and pausing a movie clip, first you need a movie clip. So first let make a movie clip. Make a shape and convert it into a movie clip as I have done below. |
|
 |
|
| 2. Then give it a good border so that video playing feel comes. |
|
 |
|
| 3. Now you need to add 5 playback buttons i.e. previous frame, stop, play, pause and next frame. You can pick them up from the common button library as I have. And place them accordingly. |
|
 |
|
| 4. Give all the playback buttons their instance name. |
|
• Previous button = prev_btn
• Stop button = stop_btn
• Play button = play_btn
• Pause button = pause_btn
• Next button = next_btn |
|
| 5. Now click on the movie clip you created earlier and give it an instance name as movie_mc. |
|
 |
|
| 6. Now double click the movie clip and go inside it. Now over here make an animation. I have made a ball animation. |
|
 |
|
 |
|
 |
|
 |
|
 |
|
| 7. Make sure you that the ball is placed a little far of from the starting point in the last frame so that it does not give a jerky effect as shown in the above image. |
|
| 8. Now on the first frame of the current layer open the actions palette by pressing F9. And write the following script over there. |
|
| Stop(); |
|
| 9. As soon as you write the above given script you will see an ‘a’ appearing on the first frame indicating that some action script is written on the layer. |
|
 |
|
| 10. Now double-click anywhere outside the image area on or out of the stage or click on the Scene1 written just above the Layers and Timeline palette. |
|
| 11. Now make a new layer above all the layers and name it Actions layer and on its first frame write the following ActionScript. |
|
play_btn.onPress = function()
{
movie_mc.play()
}
pause_btn.onPress = function()
{
movie_mc.stop()
}
stop_btn.onPress = function()
{
movie_mc.gotoAndStop(1)
}
next_btn.onPress = function()
{
movie_mc.nextFrame()
}
prev_btn.onPress = function()
{
movie_mc.prevFrame()
}
|
|
|
|
|
|
| Adding Action Script to your file |
|
| Analog Clock:- |
|
| To make an analog clock first you will need to make a base according to your choice. I have taken a circle. |
|
 |
|
| 2. Then make small/big marking for the numbers. |
|
 |
|
| 3. Now write down the numbers from 1 to 12. |
|
 |
|
| 4. Then the main and important thing is to make the needles. Make three needles and convert them into movie clips. But make sure when you convert it into a movie clip keep the registration at the bottom center point for all the needles. This makes them rotate from that point. |
|
 |
|
| 5. After creating all the needles select the Free transform tool (Q). Now select the centercircle i.e. the circle at the center of the needle then drag it down to the bottom or the place where you want it to rotate from. I have dragged the center circle for the minutes and the hours needle till their bottom points. |
|
| But I have kept the center circle a little above the bottom point so that it gives a independent look to it. Place the needles on top of the designs but make sure their ends i.e. their bottom ends are all in the center of the base circle. |
|
 |
|
| 6. The naming of the needles is equally important. Name each needle carefully i.e. their instance names. Name the seconds needle as sec_mc, minutes as min_mc and hours needle as hour_mc (case sensitive). All are to be named in the properties inspector. |
|
| 7. Then create a new layer on top of all layers and name it actions layer. ActionScript will be written on this layer. I have named all the layers according to the content. This is how it will look. |
|
 |
|
| 8. Having done that. Open the Actions Panel (F9). All the actions are written in the actions panel |
|
| 9. Now select the first frame of the layer and write the following script in the Actions panel. |
|
onEnterFrame = function()
{
var mydate_dt:Date = new Date();
var min:Number = mydate_dt.getMinutes();
var sec:Number = mydate_dt.getSeconds();
var hour:Number = mydate_dt.getHours();
sec_mc._rotation = sec*6;
min_mc._rotation = min*6 + (sec/10)
hour_mc._rotation = hour*30 + {(min + (sec/10))/12}
}
|
|
|
|
|
|
| Adding Action Script to your file |
|
| Complete Date with Digital Clock:- |
|
| 1. To make a complete date with digital clock you will need only a text box, so it is better you decrease the size of the stage as given in the following image. |
|
 |
|
| 2. Make the Dynamic text box in which you will show the output of the following size. Make the text type of the text box as dynamic in the properties inspector so that it can be called and accessed programmatically. And name it show_txt. |
|
 |
|
| 3. Having done that make a layer on top of all the layers and name it as Actions Layer. Open the Actions Panel (F9). All the actions are written in the actions panel |
|
| 4. Now select the first frame of that layer and write the following script in the actions panel. |
|
function showdate()
{
var clearclock:Date = new Date();
var month:Array = new Array();
month.push("January", "February",
"March", "April", "May", "June", "July");
month.push("August", "September",
"October", "November", "December");
var day:Array = new Array();
day.push("Sunday", "Monday", "
Tuesday", "Wednesday", "Thursday");
day.push("Friday", "Saturday");
var nowmonth:String = month[clearclock.getMonth()];
var nowdate:Number = clearclock.getDate();
var nowday:Number = day[clearclock.getDay()];
var nowyear:Number = clearclock.getFullYear();
var nowcalendar:Object = nowday + " " + nowmonth + " ";
nowcalendar += nowdate + ", " + nowyear;
var nowhour = clearclock.getHours();
var norneve:String;
if (nowhour>12)
{
nowhour = nowhour-12;
norneve = "pm";
}
else
{
norneve = "am";
}
var nowminute:Object = clearclock.getMinutes();
if (nowminute<10)
{
nowminute = "0" + nowminute;
}
var nowsecond:Object = clearclock.getSeconds();
if (nowsecond<10)
{
nowsecond = "0" + nowsecond;
}
var nowtime:Object = "
Time: " + nowhour + ":" + nowminute;
nowtime += ":" + nowsecond + " " + norneve;
show_txt.text = nowcalendar + " " + nowtime;
}
setInterval(showdate, 1000);
|
|
|
|
|
|
|
|
|
0 comments: