Object as3 adobe




















You can remove such a reference by setting the variable to null. The garbage collector removes any object that has no references. The following example deletes the value of an array element, but the value of the length property is not changed:. The following example shows how the returned Boolean from delete can be used as a condition for future code execution.

Note that if an item has already been deleted, calling delete on the item again will return false. Deletes the XML elements or attributes specified by reference. The matching elements or attributes need not be direct children of the XML or XMLList object; they can be lower in the tree for example, grandchildren.

The result is an XMLList object, because more than one child element or attribute can match. The order of nodes in the XMLList object returned is the result of a depth-first traversal. For example, consider the following:. Divides expression1 by expression2. The result of the division operation is a double-precision floating-point number. Accesses class variables and methods, gets and sets object properties, and delimits imported packages or classes. The object returned is an XMLList, because more than one child element or attribute can match.

Tests two expressions for equality. The result is true if the expressions are equal. If the data types of the two operands match, the definition of equal depends on the data type of the operands:. Compares two expressions and determines whether expression1 is greater than expression2 ; if it is, the result is true.

If expression1 is less than or equal to expression2 , the result is false. If both operands are of type String, the operands are compared using alphabetical order; all capital letters come before lowercase letters. Otherwise, operands are first converted to numbers, then compared. Compares two expressions and determines whether expression1 is greater than or equal to expression2 true or expression1 is less than expression2 false.

Evaluates whether a property is part of a specific object. To use the in operator, specify a property name as the first operand and an object as the second operand. If the object you specify contains such a property, the result is true ; otherwise the result is false. If the specified object is an Array object, you can use the in operator to check whether a particular index number is valid.

If you pass an integer as the first operand, the result is true if the index is within the valid range of index numbers, and false otherwise.

The following example uses the in operator to show that the numbers 0, 1, and 2 are valid index numbers in the myArray object, but that the number 3 is not. Adds 1 to an expression. The expression can be a variable, an element in an array, or a property of an object. If expression1 is equal to expression2 , the result is false. Evaluates whether an expression's prototype chain includes the prototype object for function.

The instanceof operator is included for backward compatibility with ECMAScript edition 3, and may be useful for advanced programmers who choose to use prototype-based inheritance with constructor functions instead of classes. To check whether an object is a member of a specific data type, use the is operator. When used with classes, the instanceof operator is similar to the is operator because a class's prototype chain includes all of its superclasses. Interfaces, however, are not included on prototype chains, so the instanceof operator always results in false when used with interfaces, whereas the is operator results in true if an object belongs to a class that implements the specified interface.

Note: The ActionScript is operator is the equivalent of the Java instanceof operator. Evaluates whether an object is compatible with a specific data type, class, or interface. Use the is operator instead of the instanceof operator for type comparisons. You can also use the is operator to check whether an object implements an interface. Compares two expressions and determines whether expression1 is less than expression2 ; if so, the result is true.

If expression1 is greater than or equal to expression2 , the result is false. Compares two expressions and determines whether expression1 is less than or equal to expression2 ; if it is, the result is true. If expression1 is greater than expression2 , the result is false. Indicates the beginning of a script comment. Returns expression1 if it is false or can be converted to false , and expression2 otherwise.

Examples of values that can be converted to false are 0, NaN , null , and undefined. If you use a function call as expression2 , the function is not called if expression1 evaluates to false.

If both operands are of type Boolean, the result is true only if both operands are true , as shown in the following table:. Inverts the Boolean value of a variable or expression. If expression is a variable with the absolute or converted value true , the value of! The following expressions illustrate the result of using the logical NOT! Returns expression1 if it is true or can be converted to true , and expression2 otherwise. If you use a function call as expression2 , the function is not called if expression1 evaluates to true.

If both operands are of type Boolean, the result is true if either or both expressions are true ; the result is false only if both expressions are false , as shown in the following table:. The following example demonstrates how using a function call as the second operand can lead to unexpected results.

If the expression on the left of the operator evaluates to true , that result is returned without evaluating the expression on the right the function fx2 is not called. Calculates the remainder of expression1 divided by expression2. The sign of the modulo result matches the sign of the dividend the first number. Multiplies two numerical expressions.

If both expressions are integers, the product is an integer. If either or both expressions are floating-point numbers, the product is a floating-point number. Instantiates a class instance. The new operator can be used with a class or a variable of type Class to create an instance of a class. The new operator is commonly used with a class object to create an instance of a class.

For example, the statement new Sprite creates an instance of the Sprite class. The new operator can also be used to associate a class with an embedded asset, which is an external object such as an image, sound, or font that is compiled into a SWF file. Each embedded asset is represented by a unique embedded asset class. To access an embedded asset, you must use the new operator to instantiate its associated class.

Subsequently, you can call the appropriate methods and properties of the embedded asset class to manipulate the embedded asset. If you prefer to define classes with Function objects instead of the class keyword, you can use the new operator to create objects based on constructor functions. Do not confuse constructor functions with constructor methods of a class.

A constructor function is a Function object that is defined with the function keyword, but that is not part of a class definition. If you use constructor functions to create objects, you must use prototype inheritance instead of class inheritance. Creates a new object and initializes it with the specified name and value property pairs. Using this operator is the same as using the new Object syntax and populating the property pairs using the assignment operator.

The prototype of the newly created object is generically named the Object object. This operator is also used to mark blocks of contiguous code associated with flow control statements for , while , if , else , switch and functions. Performs a grouping operation on one or more parameters, performs sequential evaluation of expressions, or surrounds one or more parameters and passes them as arguments to a function that precedes the parentheses.

Usage 1: Controls the order in which the operators execute. Parentheses override the normal precedence order and cause the expressions within the parentheses to be evaluated first. When parentheses are nested, the contents of the innermost parentheses are evaluated before the contents of the outer ones.

Usage 2: Evaluates a series of expressions, separated by commas, in sequence, and returns the result of the final expression. Usage 3: Surrounds one or more parameters and passes them to the function that precedes the parentheses. The result is an XMLList object. When used before and after characters, indicates that the characters have a literal value and are considered a regular expression RegExp , not a variable, string, or other ActionScript element.

Tests two expressions for equality, but does not perform automatic data conversion. The result is true if both expressions, including their data types, are equal. First, comparisons between primitive values and primitive objects that contain the same value return true in ActionScript 3. In earlier versions, the data type of a primitive value is either Boolean, Number, or String, whereas the data type of a primitive object is always Object rather than Boolean, Number or String.

You can use this property to exclude properties of dynamic objects from serialization; to write values to properties of dynamic objects; or to create new properties for dynamic objects. To do so, set this property to an object that implements the IDynamicPropertyWriter interface. For more information, see the IDynamicPropertyWriter interface. For example, if an object has the objectEncoding property set to ObjectEncoding.

You can use this constant only if you're not concerned at all about interoperability with previous versions. Filters: Retrieving Data from Server Retrieving Data from Server Classes x. ArgumentError — When the shader specifies an image input that isn't provided. See the ShaderInput. More examples Using a shader as a blend mode. BlendMode flash. Shader flash. A display object does not use a bitmap even if the cacheAsBitmap property is set to true and instead renders from vector data in the following cases: The bitmap is too large.

In AIR 1. So, if a bitmap image is 8, pixels wide, it can only be 2, pixels high. In Flash Player 9 and earlier, the limitation is is pixels in height and 2, pixels in width. The bitmap fails to allocate out of memory error. The following example applies a drop shadow to a Shape instance. It then traces the value of the cacheAsBitmap property, which is set to true when the filter is applied: Copy.

For example, the following code sends an untransformed bitmap representation of the display object to the GPU: Copy. Cached bitmap transform matrices.

To add a filter by using ActionScript, perform the following steps assume that the target display object is named myDisplayObject : Create a new filter object by using the constructor method of your chosen filter class. Assign the value of the myDisplayObject. Add the new filter object to the myFilters temporary array.

Assign the value of the temporary array to the myDisplayObject. To modify an existing filter object, you must use the technique of modifying a copy of the filters array: Assign the value of the filters array to a temporary array, such as one named myFilters.

Modify the property by using the temporary array, myFilters. For example, to set the quality property of the first filter in the array, you could use the following code: myFilters[0]. For example, to create a DropShadow filter, you would write: Copy.

TextField; import flash. When you set the height property, the scaleY property is adjusted accordingly, as shown in the following code: Copy. The following code creates two TextField objects and adjusts the height property of each based on the textHeight property of each; it also positions the second text field by setting its y property: Copy.

The following code assumes that this refers to a display object. Implementation public function get mask : DisplayObject public function set mask value: DisplayObject : void More examples Masking display objects. The following code creates a TextField object as well as a Sprite object that is set as a mask for the TextField object. When the user clicks the text field, the drag event listener function calls the startDrag method of the mask Sprite object: Copy.

Implementation public function get metaData : Object public function set metaData value: Object : void. Implementation public function get mouseX : Number Example How to use this example The following code creates a Sprite object and traces the mouseX and mouseY positions when the user clicks the sprite: Copy.

Implementation public function get mouseY : Number Example How to use this example The following code creates a Sprite object and traces the mouseX and mouseY positions when the user clicks the sprite: Copy.

Implementation public function get name : String public function set name value: String : void Throws IllegalOperationError — If you are attempting to set this property on an object that was placed on the timeline in the Flash authoring tool. Example How to use this example The following code creates two Sprite object and traces the associated name property when the user clicks either of the objects: Copy.

The opaque background region does not respond to mouse events. Implementation public function get opaqueBackground : Object public function set opaqueBackground value: Object : void More examples Setting an opaque background color.

The following code creates a Shape object with a blue circle and sets its opaqueBackground property to red 0xFF : Copy. You can use parent to move up multiple levels in the display list as in the following: Copy. The following code creates three Sprite objects and shows how the parent property reflects the display list hierarchy: Copy.

Implementation public function get root : DisplayObject Example How to use this example The following code shows the difference between the root property for the Stage object, for a display object a Loader object that is not loaded both before and after it has been added to the display list , and for a loaded object a loaded Bitmap object : Copy.

Implementation public function get rotation : Number public function set rotation value: Number : void Example How to use this example The following code creates a Sprite object and rotates the object when the user clicks it: Copy. Implementation public function get rotationX : Number public function set rotationX value: Number : void Example How to use this example In this example, two ellipses rotate using their rotationX and rotationY properties.

The first ellipse's registration point is set to its center. It rotates around itself. The second ellipse rotates around an external point. The following example shows how you can 3D rotate a Sprite object around its x-axis with Flash Professional, ActionScript 3.

Example provided by ActionScriptExamples. Implementation public function get rotationY : Number public function set rotationY value: Number : void Example How to use this example In this example, two ellipses rotate using their rotationX and rotationY properties. Implementation public function get rotationZ : Number public function set rotationZ value: Number : void. The eight other regions of the grid are the following areas: The upper-left corner outside of the rectangle The area above the rectangle The upper-right corner outside of the rectangle The area to the left of the rectangle The area to the right of the rectangle The lower-left corner outside of the rectangle The area below the rectangle The lower-right corner outside of the rectangle You can think of the eight regions outside of the center defined by the rectangle as being like a picture frame that has special rules applied to it when scaled.

When the scale9Grid property is set and a display object is scaled, all text and gradients are scaled normally; however, for other types of objects the following rules apply: Content in the center region is scaled normally.

Content in the corners is not scaled. Content in the top and bottom regions is scaled horizontally only. Content in the left and right regions is scaled vertically only. All fills including bitmaps, video, and gradients are stretched to fit their shapes. For example, consider the following display object and a rectangle that is applied as the display object's scale9Grid : The display object.

The red rectangle shows the scale9Grid. Implementation public function get scale9Grid : Rectangle public function set scale9Grid value: Rectangle : void Throws ArgumentError — If you pass an invalid argument to the method. More examples Controlling distortion when scaling. The following code creates a Shape object with a rectangle drawn in its graphics property. The rectangle has a pixel-thick line as the border and it is filled with a gradient.

The timer event calls the scale function, which scales the Shape object by adjusting the scaleX and scaleY properties. The scale9Grid applied to the Shape object prevents the rectangle's border line from scaling — only the gradient fill scales: Copy. Implementation public function get scaleX : Number public function set scaleX value: Number : void More examples Manipulating size and scaling objects.

The following code creates a Sprite object with a rectangle drawn in its graphics property. Implementation public function get scaleY : Number public function set scaleY value: Number : void More examples Manipulating size and scaling objects. Implementation public function get scrollRect : Rectangle public function set scrollRect value: Rectangle : void More examples Panning and scrolling display objects. The following example shows how the scrollRect property defines the scrolling area for a display object, circle.

When you click the circle object, the clicked event handler method adjusts the y property of the scrollRect property of the circle object, causing the object to scroll down: Copy. Implementation public function get stage : Stage Example How to use this example The following code creates two TextField objects and uses the width property of the Stage object to position the text fields: Copy. The following code has no effect on myDisplayObject : myDisplayObject. Implementation public function get transform : flash.

The following code sets up a square Sprite object. When the user clicks the sprite, the transformer method adjusts the colorTransform and matrix properties of the transform property of the sprite: Copy. Implementation public function get visible : Boolean public function set visible value: Boolean : void Example How to use this example The following code uses a Timer object to call a function that periodically changes the visible property of a display object, resulting in a blinking effect: Copy.

When you set the width property, the scaleX property is adjusted accordingly, as shown in the following code: Copy. When the user clicks the sprite, the widen method increases the width property of the sprite: Copy. Implementation public function get x : Number public function set x value: Number : void More examples Changing position.

The following code sets up a circle Sprite object. A Timer object is used to change the x property of the sprite every 50 milliseconds: Copy. Implementation public function get y : Number public function set y value: Number : void More examples Changing position.

PerspectiveProjection flash. Matrix3D transform. This example draws two ellipses and has them go back and forth down and up the z axis toward the vanishing point. One ellipse is set to move faster than the other. Consider the following code, which shows how the rectangle returned can vary depending on the targetCoordinateSpace parameter that you pass to the method: Copy.

Returns Rectangle — The rectangle that defines the area of the display object relative to the targetCoordinateSpace object's coordinate system. The following example shows how the getBounds method can return a larger rectangle than the getRect method does, because of the additional area taken up by strokes. In this case, the triangle sprite includes extra strokes because of the width and jointStyle parameters of the lineStyle method.

The trace output in the last two lines shows the differences between the getRect and getBounds rectangles: Copy. Returns Point — A Point object with coordinates relative to the display object.

More examples Changing position relative to the Stage. Point class. The following code creates a Shape object and shows the result of calling the hitTestPoint method, using different points as parameters. The globalToLocal method converts the point from Stage coordinates to the coordinate space of the shape: Copy. Returns Vector3D — A Vector3D object with coordinates relative to the three-dimensional display object. Returns Boolean — true if the bounding boxes of the display objects intersect; false if not.

Example How to use this example The following code creates three Shape objects and shows the result of calling the hitTestObject method. Note that although circle2 and circle3 do not overlap, their bounding boxes do. Thus, the hit test of circle2 and circle3 returns true.

Returns Boolean — true if the display object overlaps or intersects with the specified point; false otherwise. Returns Point — A two-dimensional point representing a three-dimensional point in two-dimensional space. Example How to use this example This example draws a simple three-dimensional cube in a two dimensional space using display. The location of this display object is offset, so the cube's registration point is in its center.

A vector of Vector3D objects holds the cube's three dimensional coordinates. The top of the cube is draw first, the bottom is drawn second, and then the top and bottom four corners are connected. You need to add the cube to the display object container before drawing the cube in order to use the local3DToGlobal method. Returns Point — A Point object with coordinates relative to the Stage.

More examples Using Point objects. The following code creates a Sprite object. The mouseX and mouseY properties of the sprite are in the coordinate space of the display object. This code uses the localToGlobal method to translate these properties to the global Stage coordinates: Copy.

Event Object Type: flash. Event property Event. The Event. ADDED constant defines the value of the type property of an added event object. This event has the following properties: Property Value bubbles true cancelable false ; there is no default behavior to cancel. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.

At its core, an associative array is an instance of the Object class, and each key-value pair is represented by a property and its value. Another reason to declare an associative array using the Object data type is that you can then use an object literal to populate your associative array but only at the time you declare it. The following example creates an associative array using an object literal, accesses items using both the dot operator and the array access operator, and then adds a new key-value pair by creating a new property:.

Both class inheritance and prototype inheritance can exist simultaneously, as shown in the following example:. Using functions instead of classes, you can construct custom prototype inheritance trees. With classes, the prototype inheritance tree mirrors the class inheritance tree. However, since the prototype objects are dynamic, you can add and delete prototype-based properties at run time.

A reference to the class object or constructor function for a given object instance. If an object is an instance of a class, the constructor property holds a reference to the class object. If an object is created with a constructor function, the constructor property holds a reference to the constructor function. Do not confuse a constructor function with a constructor method of a class.

A constructor function is a Function object used to create objects, and is an alternative to using the class keyword for defining classes. If you use the class keyword to define a class, the class's prototype object is assigned a property named constructor that holds a reference to the class object. An instance of the class inherits this property from the prototype object.

For example, the following code creates a new class, A , and a class instance named myA :. Advanced users may choose to use the function keyword instead of the class keyword to define a Function object that can be used as a template for creating objects. Such a function is called a constructor function because you can use it in conjunction with the new operator to create objects.

If you use the function keyword to create a constructor function, its prototype object is assigned a property named constructor that holds a reference to the constructor function. If you then use the constructor function to create an object, the object inherits the constructor property from the constructor function's prototype object.

For example, the following code creates a new constructor function, f , and an object named myF :. Note : The constructor property is writable, which means that user code can change its value with an assignment statement. Changing the value of the constructor property is not recommended, but if you write code that depends on the value of the constructor property, you should ensure that the value is not reset. The value can be changed only when the property is accessed through the prototype object for example, className.

If you access the constructor property and compile in strict mode, you will get an error at compile time because the constructor property depends on the protoype object, which is a runtime entity. If you use standard mode or if the class description specifies "dynamic", the code runs without generating an error.



0コメント

  • 1000 / 1000