Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 152
  • Last Modified:

Is it possible to make flash applet to remember its state?

Hi all...

I have a web page that has some flash applets in it. One of them plays a sound that is possible to stop by pressing a bottom present inside the flash.

The page contains some sections that when they are clicked, the whole page is refreshed with an ID parameter in the query string. Suppose a visitor presses the button in the applet to stop the sound, when he selects a section and the page is refreshed, the flash will start playing the sound again.

How can I make the page to remember that the visitor has pressed the off sound button? maybe with an event that is sent to the page from the flash and captured using JavaScript? other suggestion?

Any help would be greatly appreciated
Thanks

Jaime
0
skel
Asked:
skel
  • 3
1 Solution
 
furmigaCommented:
You can call your swf again with a param like my_swf.swf?play_song=false& and inside your swf you will put a conditional if(play_song==true){...}

If the movie that will reload the whole page is not the one with the sound you can dynamically insert in your page a javascript that changes the form and then process the new call for your swf.

Now, lemmi know how you are reloading the page. Are you calling an ASP or something?
0
 
skelAuthor Commented:
Thanks "furmiga" for your answer. The part to restore the sound state will be solved with what you say, but, how can the page know that the user clicks the OFF button in the SWF? The SWF has to send an event to the page when the sound is turned OFF.

The page is actually a PHP page, but that doesn't matter because what I have to do is only by mean of JavaScript.

Jaime
0
 
furmigaCommented:
Hey Jaime i'm not that good with HTML / Javascript but I made something that can be insteresting.

1 - Create a new swf file. (let the name of the file be Untitled-1.fla as default)

2 - In the first frame add this:
play_song="true" // Just for test. This will be passed by your php file later.

3 - Create a simple button and add this:
on(release)
{
      if(music_value.text == "true")
      {
            music_value.text = "false"
            play_song="false"
      }
      else
      {
            music_value.text = "true"
            play_song="true"
      }
}

4 - Create a Dynamic text field with the instance name "music_value".

5 - all set. Now save your fla in somewhere "Untitled-1.fla" as default and publish it.

6 - In the Untitled-1.html change the whole code for this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<script language="JavaScript">
<!--
function getFlashMovieObject(movieName)
{
  if (window.document[movieName])
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName];
  }
  else
  {
    return document.getElementById(movieName);
  }
}
function ReceiveDataFromFlashMovie()
{
      var flashMovie=getFlashMovieObject("myFlashMovie");
      var message=flashMovie.GetVariable("/:play_song");
      document.controller.Data.value=message;
}
//-->
</script>


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled-1</title>
</head>
<body bgcolor="#000000">
<!--url's used in the movie-->
<!--text used in the movie-->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="50" height="50"
id="myFlashMovie"
align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="Untitled-1.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#000000" />
<embed src="Untitled-1.swf" quality="high" bgcolor="#000000" width="50" height="50"
name="myFlashMovie"
align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<form name="controller" method="POST">
  <p>
  <center>
  <b><font color="#0099CC">JavaScript Controller<br>
  &nbsp;<br>
  Form Data: <input type="text" name="Data" size="30" value="Click to see the stats of the Audio">
  <input type="button" value="Receive Data" name="ReceiveData" onClick="ReceiveDataFromFlashMovie();"><br>
  </center>
  </p>
  <p>&nbsp;
  </p>
</form>
</body>
</html>

7 - Now run. As you can see the javascript function retrieves the "play_song" variable inside the flash. What you have to do now and i'm sorry but as I said, im not good with HTML / PHP, is reload the PHP sending the variable to it. "my_php.php?play_song=the_result_of_your_javascript_here&". In the PHP you will test it and load the swf with that param I told you before "my_swf.swf?play_song=true_or_false&".

Well I hope it helps :)

Ralph
0
 
furmigaCommented:
The only condition of this code that might not work is for Mac users running IE. For all others, this code runs just fine (Mozilla, IE, Netscape, Opera) running on both OS's. The browser must be JavaScript enabled as well.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now