5 Replies - 918 Views - Last Post: 12 May 2011 - 11:30 PM

#1 nitin.tkarale  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 25-February 09

Why timer missmatch in action script?

Posted 11 May 2011 - 11:44 PM

I done Draw Tool in flash with action script. In this tool we are using two timer one is 1000 ms (1 sec)and other is 50 ms means (50*20 == 1000ms(1 sec)). When we draw some line, rectangle, pencil, circle its storing value(co-ordinates (x,y,timercount)) in xml then we redraw this xml file same redraw as it is when we are draw.

But we draw some drawing with smoothly 50ms timer it is differ to 1 sec in ms.

we draw drawing of 5 min. but in redraw it is differ between two timer.

why should it come differ two timer? please give me a solution those timer are come timer count same with ms per sec.

some codes are for reference in bellow.......


var timer:Timer = new Timer(50);
timer.addEventListener("timer", timerFun);

var myTimer:Timer = new Timer(1000);
myTimer.addEventListener("timer", myTimerFun);

var timerCount:int;

myTimer.start();
timer.start();


function timerFun(event:TimerEvent):void
{
	timerCount = myTimer.currentCount;
}

function myTimerFun(event:TimerEvent):void
{
	txt.text = ""+timer.currentCount;
	txt1.text = ""+timerCount;
	
	if(timerCount % 60 == 0) {
		txt2.appendText("\n"+timer.currentCount);
		txt3.appendText("\n"+timerCount);
	}
}




///output


(50 ms timer)

(ms/sec)
1180
2200
3380
4680
5534


(1000 ms timer)
60
120
180
240
300

This post has been edited by lordofduct: 12 May 2011 - 06:43 AM
Reason for edit:: Please use code blocks


Is This A Good Question/Topic? 0
  • +

Replies To: Why timer missmatch in action script?

#2 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Why timer missmatch in action script?

Posted 12 May 2011 - 01:26 AM

1. Don't open duplicate topics. That won't help getting answers any better :)

2. That is not how you use CODE tags. Correct way is :
Posted Image

3. Its not clear what exactly you want to say. May be you can try being more specific.
Was This Post Helpful? 0
  • +
  • -

#3 NiteFlame  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 34
  • Joined: 11-June 10

Re: Why timer missmatch in action script?

Posted 12 May 2011 - 05:25 AM

i can say i completely understand what hes/shes asking but i think its around the lines of

"why is it that when i make 2 times one set at 1000ms and one set to a equation that equals 1000ms and trace both outputs that i get 2 different times"

if that is the question sadly i dnt have an answer, but i have had a similar problem with my fighter pilot game where i set plains to come out every second and they come out every 1-5 sounds and the only concussion i can come to is that maybe timer isn't based on the system clock.

but looking over your code you dnt have a equation for your 50ms other than in your question so thats most likely why you have different outputs

This post has been edited by NiteFlame: 12 May 2011 - 05:29 AM

Was This Post Helpful? 0
  • +
  • -

#4 Prototypical  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 137
  • Joined: 20-April 11

Re: Why timer missmatch in action script?

Posted 12 May 2011 - 08:39 PM

I don't know if I am completely following the question, but keep in mind that the timer doesn't start ticking again until the code in the event handler has finished executing.

So, for example if you had a 50ms timer(repeating), and the event handler took 500ms to complete, then the next time the event handler would be 50ms from then. So, in 550 ms, the handler will have only been executed twice.

That most likely explains the differences you are seeing. Keep in mind that concatenating strings and appending to text fields is not instant. String operations are much slower.
Was This Post Helpful? 0
  • +
  • -

#5 nitin.tkarale  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 25-February 09

Re: Why timer missmatch in action script?

Posted 12 May 2011 - 10:47 PM

Actually my topic is i using 50ms timer. When it run why its not counter 1200 per minutes after periodically? means counter 20/sec (60*20 = 1200). It is differ every sec means sometimes it comes 17/sec , sometimes it comes 19/sec , 20/sec, 15 /sec. Why is not come counter 20/sec every sec when 50ms timer using?
Was This Post Helpful? 0
  • +
  • -

#6 Prototypical  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 137
  • Joined: 20-April 11

Re: Why timer missmatch in action script?

Posted 12 May 2011 - 11:30 PM

If you read my explanation, I believe it answers your question.


Based on what I wrote above, in a second the 50/ms timer might only fire off 17 or 18 times.

Basically any time spent executing the timer event handler and/or the variance in the framerate of the player, is what you are not taking into account and is what is causing your variance.

I'll agree that it's not what one would expect, but I'm telling you, that is the way it is.

Remember, we are talking about 50ms, 1/20th of a second. A slow computer or intense graphics causing a lower framerate, could reduce the amount of times that a timer fires off.

What is the framerate for your .swf set at ? 30fps ? 25 fps ?

Add this code to your timerFun function and you'll see what I mean :

for (var index:int = 1; index < 100; index++)
     {
	var curClip:MovieClip = new MovieClip;
	var g:Graphics = curClip.graphics;
	g.clear();
	g.beginFill(Math.random() * 0xFFFFFF);
	g.drawCircle(300 + Math.random() * 100,300 + Math.random() * 100 , 40);
        addChild(curClip);
     }



there is simply a slight variance in the framerate of the player, and that is what you are seeing. If you set the framerate of the player to 60fps (and removed the code I just gave you of course) -- you will see that it's more consistent.

This post has been edited by Prototypical: 12 May 2011 - 11:37 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1