Timer in AS3:-
- 1. Create one dynamic text named as ‘timer’.
- 2. Go to action layer and write action script code.
- 3. i.e., create one integer variable ‘timer’ assigned as 10.
- 4. Create one timer object called ‘MyTimer’. And start the object by using start() function
- 5. Create one enterframe event and format time function for (mm:ss)
- 6. And send that format to dynamic text by using .currentCount
- 7. Press Ctrl+Enter to check the output.
var square:MovieClip = new MovieClip();
var loader_txt:TextField = new TextField();
addChild(loader_txt);
addChild(square);
//square.graphics.lineStyle(3,0x00ff00);
square.graphics.beginFill(0x0000FF);
square.graphics.drawRect(0,0,150,15);
square.graphics.endFill();
square.x = stage.stageWidth/2-square.width/2;
square.y = stage.stageHeight/2-square.height/2;
var myTimer:Timer=new Timer(1000,10);
this.addEventListener(Event.ENTER_FRAME, loading);
myTimer.start();
function loading(e:Event):void {
var total:Number=5;
var loaded:Number=myTimer.currentCount;
square.scaleX=loaded/total;
loader_txt.text = ((loaded/total)*100)+ "%";
if (total==loaded) {
play();
this.removeEventListener(Event.ENTER_FRAME, loading);
}
}
var myTimer:Timer=new Timer(1000,10);
this.addEventListener(Event.ENTER_FRAME, loading);
myTimer.start();
function loading(e:Event):void {
var total:Number=10;
var loaded:Number=myTimer.currentCount;
bar_mc.scaleX=loaded/total;
loader_txt.text = ((loaded/total)*100)+ "%";
if (total==loaded) {
play();
this.removeEventListener(Event.ENTER_FRAME, loading);
}
}
No comments:
Post a Comment