Jump to content
GreenSock

Troglodit

Tween frames forward only?

Recommended Posts

Hello!

 

I need to tween 10 frames lenght MovieClip from frame 5 to frame 2 in three seconds. When I write

 

TweenLite.fromTo(mc, 3, {frame:5},{frame:2});  

 

Frames change like this: 5,4,3,2.

How to play this movie with normal direction:5,6,7,8,9,10,1,2 ?

Link to comment
Share on other sites

If you want to wrap it like that, you'd need to do two tweens. Tuck them into a TimelineLite to make it easy to control the entire thing as a whole. I'll break apart the math to make it a bit easier...

 

var maxFrame:Number = 10;
var startFrame:Number = 5; 
var endFrame:Number = 2;
var framesTotal:Number = (maxFrame - startFrame) + endFrame;
var ratio:Number = (maxFrame - startFrame) / framesTotal;
var durationTotal:Number = 3;

var t:TimelineLite = new TimelineLite();
t.append( TweenMax.fromTo(mc, durationTotal * ratio, {frame:startFrame}, {frame:maxFrame, ease:Linear.easeNone}) );
t.append( TweenMax.fromTo(mc, durationTotal * (1 - ratio), {frame:1}, {frame:endFrame, ease:Linear.easeNone}) );

 

Or you could do it with an onUpdate...

 

var obj:Object = {frame:5};
TweenLite.to(obj, 3, {frame:12, ease:Linear.easeNone, onUpdate:applyFrame}); //purposely overshoot to 12
function applyFrame():void {
   var frame:Number = Math.floor(obj.frame % mc.totalFrames);
   mc.gotoAndStop(frame);
}

Link to comment
Share on other sites

Thank you! But about this solution I already know, and it is too hard because I need to make several thousends of tweens like that :( Well I will use this solution but I think it would be great to have more simple way to do this

Link to comment
Share on other sites

This is the perfect situation for building your own plugin. In fact, I went ahead and whipped one together for you (see attached). You could use it like this:

 

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;

TweenPlugin.activate([FrameForwardPlugin]);

mc.gotoAndStop(10);
TweenLite.to(mc, 5, {frameForward:5, ease:Linear.easeNone});

 

Again, the new plugin is in the attached zip in the com.greensock.plugins package. I also built a FrameBackwardPlugin.

 

Enjoy!

Link to comment
Share on other sites

  • 2 weeks later...

How would I go about converting this new AS3 frameForward plugin to work with AS2? I've had a go with the following but it doesn't seem to actually do anything? Any advice would be gratefully received!

 

Thanks,

Dan

 

class com.greensock.plugins.FrameForwardPlugin extends TweenPlugin {
	/** @private **/
	public static var API:Number = 1.0; //If the API/Framework for plugins changes in the future, this number helps determine compatibility

	/** @private **/
	private var _start:Number;
	/** @private **/
	private var _change:Number;
	/** @private **/
	private var _max:Number;
	/** @private **/
	private var _target:MovieClip;
	/** @private Allows FrameBackwardPlugin to extend this class and only use an extremely small amount of kb (because the functionality is combined here) **/
	private var _backward:Boolean;

	/** @private **/
	public function FrameForwardPlugin() {
		super();
		this.propName = "frameForward";
		this.overwriteProps = ["frame","frameLabel","frameForward","frameBackward"];
		this.round = true;
	}

	/** @private **/
	public function onInitTween(target:Object, value:Object, tween:TweenLite):Boolean {
		if (typeof(target) != "movieclip" || isNaN(value)) {
			return false;
		}
		_target = MovieClip(target);
		_start = _target.currentFrame;
		_max = _target.totalFrames;
		_change = (typeof(value) == "number") ? Number(value) - _start : Number(value);
		if (!_backward && _change < 0) {
			_change += _max;
		} else if (_backward && _change > 0) {
			_change -= _max;
		}
		return true;
	}

	/** @private **/
	public function set changeFactor(n:Number){
		var frame:Number = (_start + (_change * n)) % _max;
		if (frame < 0.5 && frame >= -0.5) {
			frame = _max;
		} else if (frame < 0) {
			frame += _max;
		}
		_target.gotoAndStop( int(frame + 0.5) );
	}
}

Link to comment
Share on other sites

There were a few problems with your code, like using currentFrame/totalFrames instead of _currentframe/_totalframes and int() is only for AS3, but I went ahead and ported AS2 versions of FrameForwardPlugin and FrameBackwardPlugin and posted them here. I'll put 'em into the main AS2 zips online soon as well.

 

Enjoy.

Link to comment
Share on other sites

That's great! thanks for the speedy response, and the awesome plugin!

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.
×