Solved

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

Posted on 2006-06-29
6
142 Views
Last Modified: 2011-08-18
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
Comment
Question by:skel
  • 3
6 Comments
 
LVL 7

Expert Comment

by:furmiga
ID: 17010219
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
 

Author Comment

by:skel
ID: 17010274
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
 
LVL 7

Accepted Solution

by:
furmiga earned 50 total points
ID: 17011473
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
 
LVL 7

Expert Comment

by:furmiga
ID: 17011538
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now