• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Controlling time in Actionscript 3.0

Community Beginner ,
Sep 29, 2010 Sep 29, 2010

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!

TOPICS
ActionScript

Views

683

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Sep 29, 2010 Sep 29, 2010

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;
}
}

Votes

Translate

Translate
Guest
Sep 29, 2010 Sep 29, 2010

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});

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 29, 2010 Sep 29, 2010

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;
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 29, 2010 Sep 29, 2010

Copy link to clipboard

Copied

Nice!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 30, 2010 Sep 30, 2010

Copy link to clipboard

Copied

LATEST

Thank you all for your help. I've got it working now thanks to you guys!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines