Jump to content
Search Community

Tween to frame label using "timeline time"

Nickbee test
Moderator Tag

Recommended Posts

I'm trying to figure out how to use tweenlite to replace the code I use for animated buttons:

 

stop();
btn.buttonMode = true; 
btn.addEventListener(MouseEvent.MOUSE_OVER, onOver);
btn.addEventListener(MouseEvent.MOUSE_OUT, onOut);


var overBtn:Boolean = false;
function onOver(e:MouseEvent):void {
   overBtn = true;
}
function onOut(e:MouseEvent):void {
   overBtn = false;
}

addEventListener(Event.ENTER_FRAME, onEnter);

function onEnter (e:Event):void {
   if(overBtn){
       this.nextFrame();
   }else {
       this.prevFrame();
   }
}

 

I figured if I used the tween to a frame label to mimic this effect without having to use Event.ENTER_FRAME).

 

but.... from what I understand I have to enter a time for the tweening to a frame label. Is there a work around for this? I'd like it to tween to a frame label from what ever point it is in the MC timeline.

 

Thanks

Link to comment
Share on other sites

Those are two very different questions.

 

First, to use TweenLite to do exactly the same thing as your existing code, you'd do:

 

stop();
TweenPlugin.activate([FramePlugin]); //just do this once to activate the "frame" feature in TweenLite.
btn.buttonMode = true;
btn.addEventListener(MouseEvent.ROLL_OVER, onOver);
btn.addEventListener(MouseEvent.ROLL_OUT, onOut);
var frameTween:TweenLite = new TweenLite(this, this.totalFrames, {frame:this.totalFrames, ease:Linear.easeNone, useFrames:true, paused:true});

function onOver(e:MouseEvent):void {
   frameTween.play();
}
function onOut(e:MouseEvent):void {
   frameTween.reverse();
}

 

However, if you want to tween to a particular frame label whenever the button is rolled over, it'd be as simple as this:

 

stop();
TweenPlugin.activate([FramePlugin]); //just do this once to activate the "frame" feature in TweenLite.
btn.buttonMode = true;
btn.addEventListener(MouseEvent.ROLL_OVER, onOver);

function onOver(e:MouseEvent):void {
   var endFrame:uint = getFrameLabelNumber("myLabel", this);
   TweenLite.to(this, Math.abs(endFrame - this.currentFrame), {frame:endFrame, ease:Linear.easeNone, useFrames:true});
}

function getFrameLabelNumber(label:String, mc:MovieClip):uint {
   var labels:Array = mc.currentLabels;
   var i:int = labels.length;
   while (i--) {
       if (labels[i].name == label) {
           return labels[i].frame;
       }
   }
   return mc.currentFrame;
}

 

Does that help?

Link to comment
Share on other sites

Thanks a ton! The first example of your code is exactly what I was looking to accomplish. I think I have one error though. In my movieclip I have this code:

 

stop();
import com.greensock.*;
import com.greensock.plugins.*;
TweenPlugin.activate([FramePlugin]); //just do this once to activate the "frame" feature in TweenLite.

btn.buttonMode = true;
btn.addEventListener(MouseEvent.ROLL_OVER, onOver);
btn.addEventListener(MouseEvent.ROLL_OUT, onOut);
var frameTween:TweenLite = new TweenLite(this, this.totalFrames, {frame:this.totalFrames, ease:Linear.easeNone, useFrames:true, paused:true});

function onOver(e:MouseEvent):void {
   frameTween.play();
}
function onOut(e:MouseEvent):void {
   frameTween.reverse();
}

 

and I get this error when publishing...

 

1120: Access of undefined property Linear.

 

any ideas? THANKS AGAIN!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...