Package | fl.transitions |
Class | public class Tween |
Inheritance | Tween ![]() ![]() |
Language Version: | ActionScript 3.0 |
Product Version: | Flash CS3 |
Runtime Versions: | Flash Player 9, AIR 1.0 |
The Tween class also lets you specify a variety of easing methods. "Easing" refers to gradual acceleration or deceleration during an animation, which helps your animations appear more realistic. The fl.transitions.easing package provides many easing methods that contain equations for this acceleration and deceleration, which change the easing animation accordingly.
To use the methods and properties of the Tween class, you use the new
operator with the constructor function to create an instance of the class, and you specify an easing
method as a parameter. For example:
import fl.transitions.Tween; import fl.transitions.easing.*; var myTween:Tween = new Tween(myObject, "x", Elastic.easeOut, 0, 300, 3, true);
Related API Elements
Property | Defined By | ||
---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance. | Object |
Method | Defined By | ||
---|---|---|---|
![]() | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event. | EventDispatcher | |
![]() |
Dispatches an event into the event flow. | EventDispatcher | |
![]() |
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | |
![]() |
Indicates whether an object has a specified property defined. | Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | |
![]() |
Indicates whether the specified property exists and is enumerable. | Object | |
![]() |
Removes a listener from the EventDispatcher object. | EventDispatcher | |
![]() |
Sets the availability of a dynamic property for loop operations. | Object | |
![]() |
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | |
![]() |
Returns the string representation of the specified object. | Object | |
![]() |
Returns the primitive value of the specified object. | Object | |
![]() |
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | EventDispatcher |
Event | Summary | Defined By | ||
---|---|---|---|---|
![]() | [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher | ||
![]() | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher |
userNumber
, which is then passed to the Tween constructor as a parameter for the width
of the shape.
Note: For the classes in the fl.transitions package, you need to use an import
statement, even
in the Actions panel of Flash Professional (for most classes you do not need the import statement within the Actions
panel). Use * at the package level to include all the classes in the package, or import each one individually.
import fl.transitions.Tween; import fl.transitions.easing.*; //create a Sprite instance var mySprite:Sprite = new Sprite() // create an input text field var myTextField:TextField = new TextField(); myTextField.type = TextFieldType.INPUT; myTextField.width = 180; myTextField.height = 20; myTextField.x = 20; myTextField.y = 140; myTextField.border = true; myTextField.text = "Type a number here and press Enter"; myTextField.restrict = "0-9"; addChild(myTextField); // add a listener when the user clicks in the text field myTextField.addEventListener(MouseEvent.CLICK, fieldClickHandler); // add a listener for a key press myTextField.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler); // clear the text field when the user clicks in it to enter a value function fieldClickHandler(event:MouseEvent):void { myTextField.text = ""; } // if the key pressed is the Enter key // change the values of the box's width based on the value provided function keyDownHandler(event:KeyboardEvent):void { if (event.keyCode == Keyboard.ENTER) { mySprite.graphics.clear(); var userNumber:Number = new Number(myTextField.text); mySprite.graphics.beginFill(0x666999); mySprite.graphics.drawRect(0, 0, 40, 120); addChild(mySprite); //provide tween values, including passing the variable userNumber for the width at //the end of the tween var myTween:Tween = new Tween(mySprite, "width", Elastic.easeOut, 0, userNumber, 4, true); } }
import fl.transitions.Tween; import fl.transitions.easing.*; //create a Sprite instance var mySprite:Sprite = new Sprite() // create an input text field var myTextField:TextField = new TextField(); myTextField.type = TextFieldType.INPUT; myTextField.width = 180; myTextField.height = 20; myTextField.x = 20; myTextField.y = 140; myTextField.border = true; myTextField.text = "Type a number here and press Enter"; myTextField.restrict = "0-9"; addChild(myTextField); // add a listener when the user clicks in the text field myTextField.addEventListener(MouseEvent.CLICK, fieldClickHandler); // add a listener for a key press myTextField.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler); // clear the text field when the user clicks in it to enter a value function fieldClickHandler(event:MouseEvent):void { myTextField.text = ""; } // if the key pressed is the Enter key // change the values of the box's width based on the value provided function keyDownHandler(event:KeyboardEvent):void { if (event.keyCode == Keyboard.ENTER) { mySprite.graphics.clear(); var userNumber:Number = new Number(myTextField.text); // Set up drawing data // stroke object var myStroke:GraphicsStroke = new GraphicsStroke(2); myStroke.joints = JointStyle.MITER; myStroke.fill = new GraphicsSolidFill(0x102020); // solid stroke // fill object var myFill:GraphicsGradientFill = new GraphicsGradientFill(); myFill.colors = [0xEEFFEE, 0x0000FF]; myFill.matrix = new Matrix(); myFill.matrix.createGradientBox(300, 300, 0); // path object var myPath:GraphicsPath = new GraphicsPath(new Vector.<int>(), new Vector.<Number>()); myPath.commands.push(1,2,2,2,2); myPath.data.push(0,0, 240,0, 240,60, 0,60, 0,0); // combine the objects for a complete drawing var myDrawing:Vector.<IGraphicsData> = new Vector.<IGraphicsData>(); myDrawing.push(myStroke, myFill, myPath); // render the drawing mySprite.graphics.drawGraphicsData(myDrawing); addChild(mySprite); //provide tween values, including passing the variable userNumber for the width at //the end of the tween var myTween:Tween = new Tween(mySprite, "width", Elastic.easeOut, 0, userNumber, 4, true); } }
Wed Nov 21 2018, 06:34 AM -08:00