COMMUNICATING WITH JAVASCRIPT:
DIGITAL WATCH EXAMPLE
One of the more wonderful Flash capability is its ability to communicate
with JavaScript. This example is intended to shows how
JavaScript can send variables to a Flash 4 movie.
Case study: Digital Watch
To write a Flash program that display's the current time. Use JavaScript to fetch the current time and send it to Flash.
For something that must be run continuously like a clock, JavaScript
is ideal. Both Flash movie and JavaScript are run on the client
side. Once they're loaded, they are executed on the user's
machine, and thus won't burden the server machine.
There's two main approach to this: Method A) Have Flash calls JavaScript. Method B) Have JavaScript calls Flash.
In either case, there has to be a way to update the clock in real time.
This document illustrates Method B.
Method B)
Pseudo code:
JavaScript Side:
- setup a loop to execute every 1 second (or less)
- JavaScript: get the current time
- send data to the Flash movie
Flash Side:
- update the time whenever JavaScript sends a new data