简体   繁体   中英

Change speed of movieclip dynamically in flex

I have a movieclip created of a wheel that needs to roll on the ground. The speed of lateral movement of the wheel, is provided by the user and the wheel needs to rotate such that, it looks like rolling vs slipping on the ground

I essentially need the wheel to rotate faster/ slower based on user input- how can this be achieved

using actionscript, not frame based animation.

import flash.events.MouseEvent;
import flash.events.Event;

var moveBy:Number = 2;
var rotateBy:Number = 2;

// enter frame loop
this.addEventListener(Event.ENTER_FRAME, function(e:Event)
{
    wheel.x += moveBy; 
    wheel.rotation += rotateBy;
});

I did this sample in flash with a movieclip on the stage named wheel. But you can load an image or sprite and use the same actions on it. Adjust the moveBy, rotateBy to speed up or slow down the animation. To reverse it's direction and rotation use negative numbers.

Don't let the clip play at all. Control it with gotoAndStop() based on input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM