views:

28

answers:

1

Hello everyone,

I just have a one quick question on Timer and TimerEvent (flash.events.TimerEvent & flash.utils.Timer) of Adobe Flex.

I am currently working on a project wherein I need to occasionally change speed, stop and play an swf animation (loaded to a loader and instantiated as a ByteArray).

Example, I have a moving car (swf animation) running at 40kph. Then I have a button which will change the speed by increments of 40kph. SO basically, whenever I hit the button, the playing car should change speed by the increment. The difficult part is, I already had this working in Adobe Flex but it doesn't change the speed yet. I mean, it only moves by the keyframe interval I set when I created the swf file on flash (which is, to say, 30 frame interval per keyframe).

So in short, I just need to make the speed change depending on how many increments I asked it to change. A colleague told me to use Timer and TimeEvent of Flex but I can't seem to quite get the hang of it since I'm still new to the ActionScript world.

I hope someone can help me. Thanks :)

A: 

You need to animate the car from the code. The following code speeds up wheels until 120 km/h:

private var car:MovieClip;
private var speed:Number; // from 0 to 120

private function enterFrameHandler(event:Event):void
{
    if (speed < 120)
        speed++;

    car.wheel1.rotation += speed;
    car.wheel2.rotation += speed;
}

The idea is to calculate animation parameters for every new frame "on the fly".

Maxim Kachurovskiy