Examples in detail to explain Flash animation tween tween

Source: Internet
Author: User
Tags setinterval
Flash Animation

When it comes to tweens, many people will think of defining two keyframes in the timeline and then creating a tween, in fact, as can do the equivalent work, and can do better.

To use the program to create a tween, there are two ways, one is through the setinterval function, timed to move the MC, can achieve results, but more trouble. The second is to create a motion tween through the tween class today.

Why tween is more convenient than setinterval, first the amount of code is small, look comfortable, second, tween class can use some of the more well-known easing class, and, tween class can broadcast and listen to events, these three points is enough for us to choose tween rather than setinterval.

Let's start with the use of the tween class.

To use the Tween class, first import the Tween class

Import Mx.transtions.Tween;

The syntax of the tween class is

var twmove:tween=new Tween (Mclip, "_x", null,0,550,10,true);

To explain:

Mclip: Displaying objects--references to objects to display
_x: Properties to Tween
Easing function: a reference to an easing function, here is NULL, is not referenced
0--the start value of the Tween property
550--the end value of the Tween property
10--duration
Use seconds--true, false does not use

Because the Tween class broadcasts events, you can establish listeners for the tween class, tween the method of the class, and see Help.

Here is an example, please do the link identifier "ball" in advance of the MC, copy the following code to the first frame.

Import Mx.transitions.Tween;
Import mx.transitions.easing.*;
var aclass=[back,bounce,elastic,regular,strong];
var aeasingmethod:array=new Array ();
Put each easing method in the Aeasingmethod
for (i=0 i < aclass.length; i++) {
Aeasingmethod.push (Aclass[i].easein);
Aeasingmethod.push (aclass[i].easeout);
Aeasingmethod.push (aclass[i].easeinout);
}
Defining an initial variable
var nx=10;
var y=20;
var oclips:object=new Object ();
Set up listeners
var tlistener:object=new Object ();
Tlistener.onmotionfinished=function (Twobject:tween) {
Return by original path at end of easing
Twobject.yoyo ();
}
for (i=0 i < aeasingmethod.length; i++) {
Depth=this.getnexthighestdepth ();
Mclip=this.attachmovie ("Ball", "Ball" +i,depth,{_x:nx,_y:y});
Set X coordinates
nx+=mclip._width+10;
Add an easing method to the Oclips object
Oclips[mclip._name]=aeasingmethod[i];
Start _y property's tween when the user clicks
Mclip.onpress=function () {
var twmove:tween = new Tween (This, "_y", oclips[this._name],20,400,4,true);
Add listeners
Twmove.addlistener (Tlistener);
}
}

  Click here to see the full screen effect



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.