...

View Full Version : How to use javascript to detect if Flash is playing??



sleep_z6
06-08-2004, 01:59 PM
Hi, I am new here~ :D
and is anyone here can tell me how to use “document.demo.IsPlaying()” to detect if Flash is playing???
I only know how to use javascript to control Flash play or stop...
but I don't know how to use that to detect it...
so please please please tell me how to do it... :confused:
thank you!!! :)

jbot
06-08-2004, 03:08 PM
there is no Flash API for JS, tho there is one the other way round.

now, what you code do is to get the Flash movie to write out to a JS variable or a hidden field in the HTML. if it this var is set to true, then it's playing. so, you just use JS to check against the hidden field or var.

quite easy in theory really.

your best choice of action is to look up the Flash help as to how to interact with HTML and JS.

btw: my Flash is not that good, so the above is theoretical.

glenngv
06-10-2004, 07:56 AM
http://www.quirksmode.org/js/flash_call.html

sleep_z6
06-10-2004, 12:26 PM
OH~
Thank you for help me out~!!!
Thank you very much!!! :D

sleep_z6
06-11-2004, 02:33 PM
oh oh...
there is still something wrong in my code...
but I tried and tried...
still don't know where the problem is.... :(
so is here any one can help me out...??
thanks very much!!!!
my code:
function IsFlashPlaying()
{
if (document.demo)
{
if (document.demo.Play)
document.demo.Play();
else
alert('The Flash is not playing')
}
else
alert('Can\'t find the Flash movie')

} :confused:

glenngv
06-14-2004, 05:41 AM
What happened when you execute that function? Did the flash movie play? Or the "Flash is not playing" or "Can't find the flash movie" message was displayed? Please be specific. :rolleyes:

But the idea I was thinking when I linked you to that site is this:
When the flash starts to play, you call this in flash:

getURL('javascript:setFlashPlaying(true)')

When flash stops, you call

getURL('javascript:setFlashPlaying(false)')


Then in javascript, you have this:

var flashIsPlaying=false;
function setFlashPlaying(flag){
flashIsPlaying=flag;
}

So to detect if flash is playing, you just check the value of the flashIsPlaying variable.

sleep_z6
06-15-2004, 01:39 PM
How about this I wrote :
function checkPlay()
{
if (doucment.demo.IsPlaying)
alert("is Playing");
else
alert("is not Playing");
}

and
<input type="button" value="Check Playing" onClick="checkPlay()">

But I don't know what's wrong in my code...while I click the button...it shows the error message...but I couldn't find where the problem is....
is anybody can tell me what's the problem in??
thanks very much!!!!!!!!! :)

glenngv
06-16-2004, 06:40 AM
if (doucment.demo.IsPlaying)

You have a typo there but I don't think (not sure as I don't know Flash,) it has a built-in IsPlaying property or method? If it is a method, there should be () at the end.

If indeed it doesn't have that property/method, try using the code in the link I posted and modify it to add a flag


var isFlashPlaying=false;
function tryPlayFlash()
{
if (document.themovie)
{
if (document.themovie.Play) {
document.themovie.Play();
isFlashPlaying=true;
}
else
alert('Cannot communicate with ActionScript');
}
else
alert("Can't find the Flash movie");
}

function tryStopFlash()
{
if (document.themovie)
{
if (document.themovie.Stop) {
document.themovie.Stop();
isFlashPlaying=false;
}
else
alert('Cannot communicate with ActionScript');
}
else
alert("Can't find the Flash movie");
}

You will call those functions to play and stop the Flash and then monitor the isFlashPlaying variable. The only problem with that is if the user uses the menu in the flash to play/stop it. I don't know if it (through ActionScript) has event handler that detects if it's playing or stopping.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum