Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Solved - Timers in Flash / ActionScript  (Read 2029 times)

0 Members and 1 Guest are viewing this topic.
Solved - Timers in Flash / ActionScript
« on: May 10, 2012, 02:58:44 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 57
Edit: problem solved.

I'm making a Flash movie and it relies heavily on Timers (sometimes setting Timers as high as 30,000 milliseconds).

First off, is this a bad idea?

Second, is one millisecond literally one millisecond?  Or does it depend on the computer calculating stuff and whatnot?
Basically, if the movie looks good (exactly how I want it) on my computer, then will the timing be affected if someone with a faster or slower computer than me tries to play the movie?  Or will it always turn out the way it looks? (note: I'm referring specifically to Timers... I already know that timing can be affected by image loading, etc.)
« Last Edit: May 12, 2012, 01:55:06 pm by dannyjenn »
Logged
Re: Timers in Flash / ActionScript
« Reply #1 on: May 11, 2012, 01:54:11 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 57
Now I'm having a problem... not sure if it has anything to do with the Timer or not.
Basically, I have an animation of an object moving across the screen from the left to the right.  But rather than using a tween, I am using ActionScript to changing the x position every 2 frames.  The reason for this is because the animation is supposed to loop, but it is supposed to speed up as time goes on, for about 30 seconds... and that would be very difficult to do on the timeline (if it's even possible).
So then I have a Timer set to a really high number (27900) and when it goes off it's supposed to stop the animation.

The problem is that for some reason, it doesn't always stop in the same position.  It's close, but extremely noticable (like, maybe 20 or so pixels apart each time I run it).
I have no idea what's causing this... there is no random aspect to the code or anything... it adds the exact same amount to the x every time the movie is run.  So I'm thinking either the 27900 milliseconds is not actually exactly 27.9 seconds each time, but is somehow changing by a fraction of a second each time the movie is run (causing the x to have a different amount added to it).

Does that sound reasonable... or could it be something else?  I don't think it's a loading issue because I'm preloading all my symbols / movie clips ahead of time.

If the problem is the Timer and can't be avoided... does anyone know a work-around for this?  Perhaps I could have a variable be incremented every frame and then stop the movie clip when the variable hits a certain number... would that work?
That, or I could try putting everything out on a 1000 or so frame timeline... but that's really a hassle (not to mention I don't really know how I could go about the speeding up thing)
Logged
Re: Solved - Timers in Flash / ActionScript
« Reply #2 on: May 17, 2012, 10:41:08 pm »
  • The king of Awesome
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 198
I think it's a timer issue, it may be best to code a custom timer using real time.
1 second = 60 miliseconds
1 frame = 1 mili seconds.

I would just do something like this.

var miliseconds, seconds;
miliseconds = 0;
seconds = 0;
frames = 0;

if (miliseconds < 60) then miliseconds +=1 else miliseconds = 0; seconds +=1 EndIF 

rule of thumb real time can be a !@#$% so I just say hmm if it looks good and works just go with it.

if miliseconds <= 60 {
miliseconds +=1
}
else {
  frames +=1
  seconds +=1
  miliseconds = 0
  sprite.x += 0.25;
}

This will move sprite x 0.25 every 1 second and to the human eyes it appears to work just fine, if timing is an issue I would seriously look up update code per frame. 
Logged
Re: Solved - Timers in Flash / ActionScript
« Reply #3 on: May 18, 2012, 01:46:45 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 57
Yeah, I just used variables (although I didn't even bother calculating out seconds... I just made a counter variable which increased by 1 every frame until I wanted it to stop).

My teacher said that the problem was probably a combination of 2 things:
- Flash not being able to move stuff fast enough / not keeping up with the Timer
- Possibly the Timer was causing it to stop between frames so it was ending up one frame off some of the time

Either way, it doesn't have that problem anymore after I got rid of the Timer and just used a counter variable.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.229 seconds with 45 queries.