Hi guys,
I've been looking into a similar problem.... I have a mc that I need to smoohtly zoom in and out of and after days (kid you not, I spent like 2 weeks on this now) of searching I came across tweenmax.... even so I couldn't for the life of me figure it out, but the latest code posted by greensock cleared some stuff up.
I tweaked it to make it work for my purposes, it's in AS2 + my coding skills aren't great so I expect it contains some duplicate and redundant statements, but it works!
this is an extract from my original project, just has the zoom in/out functionality.
you will need a mc and 2 buttons on stage.
main code:
import com.greensock.TweenMax;
import com.greensock.easing.*;
FastEase.activate([Linear, Quad, Strong]); //not sure if this helps with the default tween?
//any comments on fastEase would be appreciated:)
_global.base=this;
var isMouseDown:Boolean = false;
var speed:Number = 1.1;
var maxScale:Number = 100; //maximum scaleX allowed
var minScale:Number = 25; //minimum scaleX allowed
// this is because I'm inserting a bitmap that starts off displayed at 25%
mc._xscale=mc._yscale=25;
var duration:Number = 0;
var CurrentScale:Number = mc._xscale;
var newScale:Number=0;
this.onMouseDown = function() { isMouseDown = true; }
this.onMouseUp = function() { isMouseDown = false; }
////////////////////////////////////////////////////////////////////////////
//TWEENS
tweenzoomin=function(){
TweenMax.to(mc, duration, {_xscale:maxScale, _yscale:maxScale, useFrames:true});
} //no easing defined - found that default works best..
tweenzoomout=function(){
TweenMax.to(mc, duration, {_xscale:minScale, _yscale:minScale, useFrames:true});
}//no easing defined - found that default works best..
zoomease=function(){
TweenMax.to(mc, duration, {_xscale:newScale, _yscale:newScale, ease:Quad.easeOut, useFrames:true});
}
////////////////////////////////////////////////////////////////////////////
killall = function(){//found it necessary to kill all tweens in the project file, though this might work without it
TweenMax.killAll(false, true, true);
}
////////////////////////////////////////////////////////////////////////////
Zoomin button
on(press){
this.onEnterFrame = function() {
if(isMouseDown){
currentScale = mc._xscale;
if(currentScale<(maxScale-15)){//easeing kicks in at 85% of scale
duration = Math.abs( (maxScale - currentScale)/ speed );
tweenzoomin();
}
else
{
killall();
newScale = maxScale
duration = 8; //8fps
zoomease();
}
}
}
}
on(release, releaseOutside){
delete onEnterFrame;
killall();
currentScale = mc._xscale;
if (mc._xscale < maxScale) {
newScale = Math.min( maxScale, currentScale + 3);
duration = 12 //12fps
zoomease();
}
}
zoomout button
on(press){
this.onEnterFrame = function() {
if(isMouseDown){
currentScale = mc._xscale;
if(currentScale > (minScale+15)){//easeing kicks in below 40% of scale(40 to 25)
duration = Math.abs( (currentScale-minScale)/ speed );
tweenzoomout();
}
else
{
killall();
newScale = minScale
duration = 8 //8fps
zoomease();
}
}
}
}
on(release, releaseOutside){
delete onEnterFrame;
killall();
currentScale = mc._xscale;
if (mc._xscale > minScale) {
newScale = Math.max( minScale, currentScale - 3);
duration = 12 //12fps
zoomease();
}
}