This is a sample using Javascript to Flash communication. The sample uses Javascript to detect the position of the mouse in the browser window (not only when it is over flash content), and conveys those coordinates to the .swf. The graphic is rotated within the .swf using the passed mouse coordinates to orient the graphic towards the mouse.

This sample uses browser detection and was tested on Mozilla 1.0.6 and IE 6.0.29... on WinXP. It will currently only work properly with the .swf in the upper left corner of a browser window, but it could work in any position on the page if the .swf were placed on a div layer and the math in the .swf that calculates the rotation of the graphic were updated.

Resources used in creating this sample:
Macromedia
osflash.org

LA Flash Extension User Group
CodeLifter
 


In both browsers, the Javascript to Flash communication interferes with the .swf's updateAfterEvent() call, causing the .swf to stop refreshing while the mouse is moving. There are some quirks specific to different browsers:

IE
- The Javascript onmousemove event handler is continuously called (see status bar in your browser, below), but the coordinates of the mouse only seem to be sent when the mouse stops moving or when the mouse leaves or enters the browser window.

Firefox
- The status bar isn't updated in this sample, probably because of browser incompatibility.
- The .swf seems to update much faster, as is seen in the counter that updates much faster and the animation that achieves a much higher refresh rate. This doesn't seem to be a result of the Javascript to Flash communication, as in both browsers the Javascript communication to Flash only occurs when the mouse pauses.
- If the browser window is resized so that scrollbars appear, the communication stops working. When the window is resized so that the scrollbars disappear, it starts working again.

For sourcefiles used in this sample, email info at roguish.com. If you like this sample, check out this Flash Video Comparison: FlashVideoFAQ.com