Solved

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

Posted on 2006-06-29
6
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

617 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