Bonjour je ne sais pas si la
question a déjà été posée.
Après plusieurs recherches sur le net, j'ai trouvé
comment lancer un flash et le stopper gâce à Javascript.
Mon but est de
mettre une musique mp3 en fond d'un site internet. On peut le stopper et le
remettre grâce à un bouton.
Au départ, j'avais pensais tout faire en
flash mais le probème c'est lors du rechargement de la page puisque le site est
dynamique.
J'ai donc juste fait un flash de taille 1x1 px qui contient
juste un actionscript.
Voilà mon flash (ActionScript)
:
------------------------------------
code:
var mp3 = new Sound();
mp3.loadSound(song,1);
mp3.start();
stop();
J'ai
intégré ce flash dans une page contenant une IFRAME.
Comme ça j'évite le
rechargement complet de la page mais juste de la IFRAME.
Voici ma page
index :
--------------------------
code:
<html>
<head>
<script language="javascript" type="text/javascript">
var playsound = true;
</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no">
<object id="backsound" classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="0" height="0">
<param name="movie" value="song.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<param name="flashvars" value="song=test.mp3">
<param name="play" value="true">
<embed name="backsound" src="song.swf" quality="high" flashvars="song=test.mp3" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="0" height="0" play="true" swLiveConnect="true"></embed>
</object>
<iframe src="main.php" frameborder="0" width="100%" height="100%" scrolling="auto"></iframe>
</body>
Cette
page contient donc le flash et une IFRAME qui change à chaque clic.
Dans
ma page main.php :
-------------------------------
code:
<head>
<script language="javascript">
<!--
function mySwf()
{
if (navigator.appName.indexOf("Microsoft") != -1)
return parent.backsound;
else
return parent.document.embeds(0);
}
function initPlaySound(){
document.getElementById('imgSound').src='images/sound_on.gif';
document.getElementById('linkSound').href='java script:stopSound()';
document.getElementById('linkSound').title='<?php echo HEADER_STOP_SOUND; ?>';
}
function initStopSound(){
document.getElementById('imgSound').src='images/sound_off.gif';
document.getElementById('linkSound').href='javascript
laySound()';
document.getElementById('linkSound').title='<?php echo HEADER_PLAY_SOUND; ?>';
}
function initSound(){
if(parent.playsound){
initPlaySound();
}else{
initStopSound();
}
}
function playSound(){
parent.playsound = true;
mySwf().Play();
initPlaySound();
}
function stopSound(){
parent.playsound = false;
mySwf().StopPlay();
initStopSound();
}
//-->
</script>
</head>
...
<a id="linkSound" href="java script: stopSound();" ><img id="imgSound" src="images/sound_on.gif" border="0"></a>
...
<script language="javascript">initSound()</script>
Le
flash se lance bien mais impossible de le contrôler en Javascript.
Où est-ce
que ça bloque ?
D'avance merci.