Countdown Clock

  • user warning: Got error 28 from storage engine query: SELECT node.nid AS nid, node_revisions.body AS node_revisions_body, node_revisions.format AS node_revisions_format, node.title AS node_title, RAND() AS _random FROM node node LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid WHERE (node.type in ('quote')) AND (node.status <> 0 OR (node.uid = 0 AND 0 <> 0) OR 0 = 1) ORDER BY _random ASC LIMIT 0, 1 in /var/www/jg-soft.com/modules/acquia/views/includes/view.inc on line 755.
  • user warning: Got error 28 from storage engine query: SELECT node.nid AS nid, node_data_field_images.field_images_fid AS node_data_field_images_field_images_fid, node_data_field_images.field_images_list AS node_data_field_images_field_images_list, node_data_field_images.field_images_data AS node_data_field_images_field_images_data, node_data_field_images.delta AS node_data_field_images_delta, node.type AS node_type, node.vid AS node_vid, RAND() AS _random FROM node node LEFT JOIN content_field_images node_data_field_images ON node.vid = node_data_field_images.vid INNER JOIN term_node term_node ON node.vid = term_node.vid LEFT JOIN term_node term_node2 ON node.vid = term_node2.vid AND term_node2.tid = 41 WHERE (node.status <> 0 OR (node.uid = 0 AND 0 <> 0) OR 0 = 1) AND (node.type not in ('project')) AND (node_data_field_images.field_images_list <> 0) AND (term_node.tid = 13) AND (term_node2.tid IS NULL) ORDER BY _random ASC LIMIT 0, 1 in /var/www/jg-soft.com/modules/acquia/views/includes/view.inc on line 755.
AttachmentSize
countdown_animation.fla91 KB

Today I, Jason Gordon, created my first production flash applet. It's very simple, but the applet is a great beginner's example for how to create a timeline effect animation and use basic action script. Below I'll describe the application in terms of its component parts.

I. Animations

  1. First I created 3 textfields and entered a word in each one, "LIVE.", "RIGHT.", "NOW.", respectively.
  2. Then, for each textfield, I inserted a timeline effect on it. The effect was a fade in transition lasting 24 frames (1sec @ 24fps).
  3. I then lined up all the frames so that live animated, when finished, right animate, and when finished now animated.
  4. On the last frame for each of these layers I added a keyframe and to this keyframe i attached an actionscript action. The code was just stop();

II. Countdown

The countdown was a bit less tricky, honestly. I've done countdowns in code a few times in the past, so the code part wasn't new. Attaching the actionscript was a trick. I didn't realize I just had to click the stage somewhere and start typing! Man..tricky son of bitch you are, flash.

For the countdown I created a layer and added 2 textfields to it. In the first textfield i typed "Countdown: ". The second I made a dynamic textfield, and named it result. Below is the actionscript I wrote to implement the countdown:

  1. timer();
  2.  
  3. // Make this happen again, once a second
  4. var timeint:Number = setInterval(timer, 1000);
  5.  
  6. function timer() {
  7. var showStart:Date = new Date("Fri Sep 11 2009 9:00:00 AM");
  8. var now:Date = new Date();
  9. var countdown:Number = (showStart.time - now.time) / 1000;
  10.  
  11. var out:String = "";
  12.  
  13. // Determine remaining days
  14. out = String(int(countdown / 86400)) + "days ";
  15. countdown = countdown % 86400;
  16.  
  17.  
  18. // Determine remaining hours
  19. out += String(int(countdown / 3600)) + "hrs ";
  20. countdown = countdown % 3600;
  21.  
  22. // Determine remaining minutes
  23. out += String(int(countdown / 60)) + " mins ";
  24. countdown = countdown % 60;
  25.  
  26. // Determine remaining seconds
  27. out += String(int(countdown)) + "sec";
  28. result.text = String(out);
  29. };

And here is the final product:

Thanks Mark! As to your

Thanks Mark!

As to your question about triggering an event...I'm not quite sure yet. When I find out I'll modify the post here with an update on what I found.

I found this to be really

I found this to be really useful in learning to create a reliable countdown timer. One thing i was wondering though is how would you use it to trigger an event, or a message for example when it hits 0. I figured just using an if statement that compares the showStart.time == now.time  would do the trick, but i don't seem to be getting any output using this method ? Any ideas.

Thanks for the code tips by the way :)

M