As3.0 instances are familiar with the use of Tween and tweenevent.

Source: Internet
Author: User

Case 3: be familiar with the use of Tween and tweenevent

Note: clicking a tag to load a specific image description (in fact, it is a MC, but the coordinates are different). At the same time, there is a fade-away effect. If loading is not performed, loading may be a little slow.

Demo:
Http://www.live-my-life-with-yuyi.com/as3_cases/dynamic_with_events/

Code:

Initialize and assign values to some variables

Copy code The Code is as follows: Import Fl. transitions. Tween;
Import Fl. transitions. Easing .*;
Import Fl. transitions. tweenevent;
VaR homex: Number =-301;
VaR homey: Number = 110;
VaR newsx: Number =-17;
VaR newsy: Number =-777;
VaR aboutx: Number =-1354;
VaR abouty: Number =-445;
VaR xtween: tween;
VaR ytween: tween;
VaR intween: tween;
VaR outtween: tween;

First, import some classes to be used, and then define several coordinates. These coordinates are different positions of a large MC.

Then initialize the Tween class and listen to the Tween class.

Copy code The Code is as follows: xtween = new tween (main_mc, "X", strong. easeinout, main_mc.x, homex, 2, true );
Ytween = new tween (main_mc, "Y", strong. easeinout, main_mc.y, homey, 2, true );
Intween = new tween (main_mc.home_mc, "Alpha", none. easenone, 0, 1,. 5, true );
Outtween = new tween (main_mc.home_mc, "Alpha", none. easenone, 1, 0,. 5, true );
Xtween. addeventlistener (tweenevent. motion_finish, fadein );
Xtween. addeventlistener (tweenevent. motion_start, fadeout );
Home_btn.addeventlistener (mouseevent. Click, navigate );
News_btn.addeventlistener (mouseevent. Click, navigate );
About_btn.addeventlistener (mouseevent. Click, navigate );

After xtween is instantiated, ytween does not run immediately. If the stop action is found in the subsequent code. These parameters are not much different from as2.
Xtween and ytween implement the slow effect of MC, and intween and outtween implement the fade-out effect.
Here, only xtween is monitored, but ytween is not monitored. because both are performed at the same time, you can only listen to one.
Click listening for the three buttons.

The following are the most critical functions mentioned above.

Copy code The Code is as follows: function navigate (Event: mouseevent): void
{
If(event.tar get = home_btn)
{
Settween (homex, homey, main_mc.home_mc );
}
Else if(event.tar get = news_btn)
{
Settween (newsx, newsy, main_mc.news_mc );
}
Else
{
Settween (aboutx, abouty, main_mc.about_mc );
}
}
Function settween (tweenx: Number, tweeny: Number, tweenmc: movieclip): void
{
Xtween. Begin = main_mc.x;
Ytween. Begin = main_mc.y;
Xtween. Finish = tweenx;
Ytween. Finish = tweeny;
Tweenmc. Alpha = 0;
Intween. OBJ = tweenmc;
Xtween. Start ();
Ytween. Start ();

}
Function fadein (Event: tweenevent): void
{
Intween. Start ();
Outtween. OBJ = intween. OBJ;
}
Function fadeout (Event: tweenevent): void
{
Outtween. Start ();
}

Let's take a look at the navigate function. This is a function called by three buttons. It sets different settween values by judging different target. Names.
Let's take a look at settween. The tweenx and tweeny parameters are the target coordinates, while the tweenmc parameters are the target MC. By setting the begin, finish, and OBJ parameters, we can change the initial coordinates, target coordinates, and target objects of xtween and ytween, finally, call the start function to start the motion.

The role of the fadein function is to start intween and assign the intween object to outtween, so that the outtween can be used in the correct MC when it is called.
Package files

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.