Javascript - find swfobject on included page and call javascript function
I’m using the following script on my website to play an mp3 in flash. To instantiate the flash object I use the swfobject framework in a javascript function. When the function is called the player is created and added to the page.
The rest of the website is in php and the page calling开发者_StackOverflow this script is being included with the php include function. All the other used scripts are in the php 'master'-page
var playerMp3 = new SWFObject("scripts/player.swf","myplayer1","0","0","0");
playerMp3.addVariable("file","track.mp3");
playerMp3.addVariable("icons","false");
playerMp3.write("player1");
var player1 = document.getElementById("myplayer1");
var status1 = $("#status1");
$("#play1").click(function(){
player1.sendEvent("play","true");
$("#status1").fadeIn(400);
player4.sendEvent("stop","false");
$("#status4").fadeOut(400);
player3.sendEvent("stop","false");
$("#status3").fadeOut(400);
player2.sendEvent("stop","false");
$("#status2").fadeOut(400);
});
$("#stop1").click(function(){
player1.sendEvent("stop","false");
$("#status1").fadeOut(400);
});
$(".closeOver").click(function(){
player1.sendEvent("stop","false");
$("#status1").fadeOut(400);
});
$(".accordionButton2").click(function(){
player1.sendEvent("stop","false");
$("#status1").fadeOut(400);
});
$(".accordionButton3").click(function(){
player1.sendEvent("stop","false");
$("#status1").fadeOut(400);
});
$(".turnOffMusic").click(function(){
player1.sendEvent("stop","false");
$("#status1").fadeOut(400);
});
});
I have a play-button with the id ‘#play1’ and a stop-button with the id ‘#stop1’ on my page. A div on the same page has the id ‘#status1’ and a little image of a speaker is in the div. When you push the playbutton, the div with the speaker is fading in and when you push the stopbutton, the div with the speaker is fading out, very simple. And it works as I want it to do.
But the problem is, when a song is finished, the speaker doesn’t fade out. Is there a simple solution for this? I already tried using the swfobject framework to get the flash player from the page and call the ‘IsPlaying’ on it, but I’m getting the error that ‘swfobject’ can’t be found. All I need is a little push in the right direction or an example showing me how I can correctly get the currently playing audio player (in flash), check if it’s playing and if finished, call a javascript function to led the speaker-image fade-out again. Hope someone here can help me
The 'swfobject not found' error is often due to mixing up SWFObject 1.5 and 2.x syntax (2.x is a complete rewrite and not backwards-compatible). See http://learnswfobject.com/advanced-topics/detecting-swfobject-version/
The code you posted uses SWFObject 1.5 syntax, which means all references to the SWF should be accessed via your player1
variable, as you've written.
RE: the fading, is the speaker icon part of your SWF? You can't 'fade out' a SWF using CSS/JavaScript. In this case you'd have two options:
Fade IN a HTML-based mask OVER the SWF which gives the appearance of fading out the SWF. This can be achieved with a DIV styled to look like your background. Here's a tutorial for placing HTML elements over SWFs.
Alter your SWF to fade out the speaker icon using an internal ActionScript function, and invoke the function using ExternalInterface.
No, the image is not a part of the swf and i don't have the .fla file, so i cannot put any code in flash.
My question is; is there a piece of javascript that says to the .swf file: fade the speaker image (which is in a div on the page) out when a song is finished.
Btw, Rob is my brother and he's helping with this problem.
Because lack of time we've decided to run a JS timer in the background with a length equal to the length of the mp3 playing in flash. In time i'll rewrite the code to the swfobject 2.x syntax. Any suggestions to this problem are still welcome!
精彩评论