Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to use javascript to detect if Flash is playing??

    Hi, I am new here~
    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...
    thank you!!!

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts

  • #4
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hi

    OH~
    Thank you for help me out~!!!
    Thank you very much!!!

  • #5
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question oh oh...

    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')

    }

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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.

    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.

  • #7
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question is anything wrong in my code???

    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!!!!!!!!!

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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
    Code:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •