Copy link to clipboard
Copied
I was wondering if there is a way to directly control time in AS 3.0
I have some code such as:
thumb1.addEventListener(MouseEvent.ROLL_OVER, scaleUP)
function scaleUP(e:MouseEvent):void {
thumb1.scaleX = thumb1.scaleY = 1.5
}
Obviously, this instantly increases the scale of the thumbnail, but I was wondering if I could have it scale up over a period of time (2 - 3 seconds) so that the size increase is more gradual.
Thanks in advance!
without extra files:
import flash.events.Event;
var speed:Number = 5;
thumb1.addEventListener(MouseEvent.ROLL_OVER, scaleUP);
function scaleUP(e:MouseEvent):void
{
thumb1.removeEventListener(MouseEvent.ROLL_OVER, scaleUP);
addEventListener(Event.ENTER_FRAME,fScale);
}
function fScale(evt:Event)
{
thumb1.scaleX+=(1.5-thumb1.scaleX)/speed;
thumb1.scaleY = thumb1.scaleX;
if (Math.abs(1.5 - thumb1.scaleX) < 0.02)
{
removeEventListener(Event.ENTER_FRAME,fScale);
thumb1.scaleY = thumb1.scaleX = 1.5;
}
}
Copy link to clipboard
Copied
You want what is known is a tweening engine. There is the included Tween classes, but they are not good... Generally, it is recommended you use a third party tweening package - TweenLite/TweenMax is highly recommended and pretty much the best tweening engine around today.
http://www.greensock.com
Using TweenLite to tween your scale over two seconds - would be something like:
import com.greensock.TweenLite;
thumb1.addEventListener(MouseEvent.ROLL_OVER, scaleUP)
function scaleUP(e:MouseEvent):void {
TweenLite.to(thumb1, 2, {scaleX:1.5, scaleY:1.5});
}
Copy link to clipboard
Copied
without extra files:
import flash.events.Event;
var speed:Number = 5;
thumb1.addEventListener(MouseEvent.ROLL_OVER, scaleUP);
function scaleUP(e:MouseEvent):void
{
thumb1.removeEventListener(MouseEvent.ROLL_OVER, scaleUP);
addEventListener(Event.ENTER_FRAME,fScale);
}
function fScale(evt:Event)
{
thumb1.scaleX+=(1.5-thumb1.scaleX)/speed;
thumb1.scaleY = thumb1.scaleX;
if (Math.abs(1.5 - thumb1.scaleX) < 0.02)
{
removeEventListener(Event.ENTER_FRAME,fScale);
thumb1.scaleY = thumb1.scaleX = 1.5;
}
}
Copy link to clipboard
Copied
Nice!
Copy link to clipboard
Copied
Thank you all for your help. I've got it working now thanks to you guys!