Home arrow Flash arrow Page 4 - Dynamic Flash Part 1: Counting Users Online
FLASH

Dynamic Flash Part 1: Counting Users Online


New to Flash? Come join Ben in this, the first of many weekly Flash articles, as he shows us how to use Flash and PHP to show a count of users on your web site.

Author Info:
By: Aaron Schaap
Rating: 4 stars4 stars4 stars4 stars4 stars / 10
August 16, 2002
TABLE OF CONTENTS:
  1. · Dynamic Flash Part 1: Counting Users Online
  2. · The Basics Of Dynamic Flash
  3. · Whose Online Using Flash
  4. · Whose Online Using Flash (contd.)
  5. · Conclusion

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Dynamic Flash Part 1: Counting Users Online - Whose Online Using Flash (contd.)
(Page 4 of 5 )

Ok, now that we have our dynamic file we can create our flash movie to display the number of users online, without refreshing the page. We will manipulate our Flash movie to refresh every 20 seconds, which will call up the count.php file again, thus getting a refreshed value for the number of users online.

Create a new flash movie called 'count.fla' with dimensions of 200x80. When we’re done you will need to upload it to your web server.

Create some text called 'Active Users:'. Create another text field and change its properties to dynamic text. Call the var 'Count':



Ok, so now we have two text fields: one static, and one dynamic. Up in the timeline properties, select frame 1:



Open the Actions box and add the following code:

loadVariablesNum("count.php?RND="+random(999), 0);

This will load the variable contents of the count.php file and tell us how many users are online. Remember that we append the random number so that we don't receive Flash's cached version of count.php. Our movie is nearly complete and will display the number of users online, however it doesn't yet display that number on the fly. To do this we need to create a loop using the timeline. We want it to reload the count.php file every 20 seconds. Bbecause there are 12 frames per second, we need to add a command to frame 240.

Firstly, select frame 240 and hit F6. This will create a key frame so that we can add a new action. Now that we have our key frame created, make sure it's selected and add the following to the action properties:

gotoAndPlay(1);

This will tell the movie to loop, causing it to check the PHP file again. Save your work and hit Ctrl+F12. Close the browser.

Goto the directory where you saved your movie to and grab the following files: count.php, count.html, count.swf. Upload them to your server and then run count.html in your. It should display as Active Users: 1.

Now, jump to another computer or ask a friend to visit your site and load up the count.php file in their browser. Do not refresh the page -- It will defeat the purpose of using flash.

Once your friend has loaded the page, wait 20 seconds and the flash movie should automatically update, showing you the number of people on your site!

Follow the link below to see an example flash movie showing how many people are currently browsing the DevArticles web site.


blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials