AS3.0 example learning familiar with the use of tween and tweenevent _flash as

Source: Internet
Author: User
Case 3: Familiar with the use of tween and tweenevent

Description: Click on the tag to load a specific picture description (in fact, is a MC, but the coordinates are different), but also gradually fade effect, did not do loading, may be a bit slow to join the membership.

Demonstrate:
http://www.live-my-life-with-yuyi.com/as3_cases/dynamic_with_events/

Code:

Initialize, assigning values to some variables

Copy Code code 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 you import some classes that need to be used, and then you define a few coordinates, which are different locations for a large MC.

It then initializes the tween class and listens to the tween class.

Copy Code code 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);

Instantiating Xtween,ytween does not run immediately, if the following code finds a stop action. These parameters are not much different from AS2.
Xtween and Ytween are the implementation of the slow effect of MC, Intween and Outtween are the realization of the fading effect.
Here only listens to the Xtween and does not monitor the Ytween, because these two are simultaneously carries on, therefore listens for one to be OK.
Finally, the click of the 3 button is monitored.

And then there are some of the most critical functions mentioned above

Copy Code code as follows:

function navigate (event:mouseevent): void
{
if (Event.target = = home_btn)
{
Settween (HOMEX,HOMEY,MAIN_MC.HOME_MC);
}
else if (Event.target = = 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, which is a function called by 3 buttons to set different Settween by judging different target.name.
To see Settween, the parameter Tweenx and Tweeny are target coordinates, TWEENMC is the target MC, by setting the Begin,finish,obj parameters to change the Xtween and ytween of the initial coordinates, the target coordinates, the action object, Finally, the start function is called to start the motion.

The role of the Fadein function is to make the Intween start, and to give the intween the role of the object Outtween, so that Outtween is invoked when it can function on the correct MC.
Packaging 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.