Question:

I'm trying to implement an odometer in a flash movie with actionscript 3?

by  |  earlier

0 LIKES UnLike

Right now I've got a 7-digit odometer, its 7 instances of a "numbers" movie clip placed on my background art. This "numbers" movieclip has 11 frames... a "-" for an unused digit, and the rest of the frames go 1,2,3,4,5,6,7,8,9,0.

I'm having a hard time figuring out how to animate it from one reading to another.

It is going to increment in random values input into my increaseReading() function... i.e. it might be told to go up by 20,589 miles... and I'll need it to roll to that point. Any ideas?

 Tags:

   Report

1 ANSWERS


  1. Copy and paste this code to the first frame of ur flash document CS3 | As3

    you don't need to create anything on the stage

    you can find a running example of this program in my Flash-blog

    http://flash-workshop.blogspot.com/2008/...

    import fl.transitions.Tween;

    import fl.transitions.TweenEvent;

    import fl.transitions.easing.*;

    var counter:int = 0;

    var MyFormat :TextFormat = new TextFormat;

    MyFormat. bold= true;

    MyFormat. font= "Arial";

    MyFormat. size= 50;

    MyFormat. color= 0x000000;

    function createShape() : MovieClip {

    var shape = new MovieClip();

    var shapeBG = new MovieClip();

    var shapeMask = new MovieClip();

    var shapeText = new TextField();

    shapeText. defaultTextFormat=MyFormat;

    shapeText. text="0";

    shapeText. autoSize =TextFieldAutoSize.CENTER;

    shapeText. selectable = false;

    shapeText. name = "shapeText";

    shapeText. y = -5;

    shapeText. x = 10;

    shapeText. mask = shapeMask;

    shapeText. name = "shapeText";

    shapeBG. graphics. beginFill (0xE6E6E6, 1);

    shapeBG. graphics. drawRoundRect (0, 0, 50, 50, 25, 25);

    shapeBG. graphics. endFill();

    shapeBG. name =  "shapeBG";

    shapeMask. graphics. beginFill (0x00CCCC, 1);

    shapeMask. graphics. drawRoundRect (0, 0, 50, 50, 25, 25);

    shapeMask. graphics. endFill ();

    shapeMask. name = "shapeMask";

    shape. addChild (shapeBG);

    shape. addChild (shapeMask);

    shape. addChild (shapeText);

    shape. name = "shape";

    return shape;

    }

    var distance:int = 60;

    var shape1 = createShape();

    addChild (shape1);

    shape1.x =distance*2;

    shape1.y =10;

    var shape2 = createShape();

    addChild (shape2);

    shape2. x = distance*1;

    shape2. y = 10;

    var shape3= createShape();

    addChild (shape3);

    shape3 .x = distance*0;

    shape3 .y = 10;

    var time : int = 1000;

    var MyTimer: Timer = new Timer (time);

    MyTimer. addEventListener (TimerEvent. TIMER, runOdometer);

    MyTimer. start();

    var target1 = shape1. getChildAt(2);

    var target2 = shape2. getChildAt(2);

    var target3 = shape3. getChildAt(2);

    function runOdometer(e:TimerEvent):void {

    positionFn (target1, target1.y, -40);

    if (++counter> 9) {

    positionFn (target2, target2. y, -40);

    if (int (target2. text) ==9) {

    positionFn (target3, target3. y, -40);

    }

    }

    }

    function positionFn (TweenMC:TextField, Start:int, Stop:int) : void  {

    var tween_handler = new Tween (TweenMC, "y", None. easeInOut, Start, Stop, time/(time*6), true);

    tween_handler.addEventListener (TweenEvent. MOTION_FINISH, UpdateStatus ) ;

    }

    function positionFn2 (TweenMC:TextField, Start:int, Stop:int) : void {

    var tween_handler = new Tween(TweenMC, "y", None. easeInOut, Start, Stop, time/(time*6), true);

    }

    function UpdateStatus(e:TweenEvent) {

    target1.text = counter;

    positionFn2 (target1, 32, -5);

    if (counter>9) {

    target2. text = int (target2.text)+1;

    positionFn2 (target2, 32, -5);

    counter = 0;

    if (int (target2. text )>9) {

    target2. text="0";

    target3. text=int(target3.text)+1;

    positionFn2 (target3, 32, -5);

    if (int(target3. text) > 9) {

    target3. text ="0";

    }

    }

    }

    }

    Anil

    anilkumarnd@gmail.com

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.