Flash CS3 - AS3 Counter






Copy and paste this AS3 code to the first frame of your flash CS3 document. You don't need to create anything on the stage

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


}

}

}

}

Comments

Unknown said…
nice script.... can it be made to move faster...

Work from home India
bluedawg said…
I thnk to changethe speed you just need to change this line...

var time:int = 1000;

Popular posts from this blog

AS3 - Access objects from external SWF files

Flash CS3 - XML Guestbook (AS3)

Flash CS4 - 3D Rotating Menu