Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Calling javascript function to open SWF

Guest
Aug 08, 2006 Aug 08, 2006
When the Captivate presentation ends, I'm trying to open another SWF in the same browser window.

I have put the following code in the HTML document:

<script type="text/javascript">
<!--
function changeMovie(filename)
{
document.getElementById('Captivate1').movie=filename;
alert(document.getElementById('Captivate1').movie);
}
//-->
</script>

I am able to call the function from the Captivate file successfully because the alert window pops up with the name of the movie. I just can't get it to play. Can anyone help me on this?

Not to be rude or anything, but I should note that:

1) this is not my idea--it is my boss' idea, and any attempts to tell me that this is something not worth doing will unfortunately fall, not on deaf ears, but on ears connected to hands that have no freedom to choose how this project is completed. This is my master's bidding, and I must do what he says.

2) I know very little JavaScript. This code was given to me by another guy on the project. So if you have advice for changing the code, please be as specific as possible.

I would be very grateful for any help that you can offer.
879
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 08, 2006 Aug 08, 2006
Hi PotatoBug,

I use this function all the time (although in a different manner.) The only caveat is that you can only call a javascript from this, you can't put in the entire script and have it work. I have a large javascript include file that contains ll the js scripts I use. I use a include statement to include that file in all the html file generated by Captivate. I can then call any of those scripts from anywhere I want.

So I can get the picture:
When you publish your Captivate project (call it "myproject.cp") you select:
Publish -> Preferences ->Movie End Options -> Execute Javascript
Click ellipsis button:
In the white field you type in: javascript: changeMovie(filename)
(Where (filename) is the name of the other SWF file like "myactionfile.swf")

When the file is Published you get two files:
myprojectfile.htm
myprojectfile.swf

Then in the head of the HTML file (myprojectfile.htm) that you created you place this script:

<script type="text/javascript">
<!--
function changeMovie(filename)
{
document.getElementById('Captivate1').movie=filename;
alert(document.getElementById('Captivate1').movie);
}
//-->
</script>

Is this the way you are calling the javascript?

TPK
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 08, 2006 Aug 08, 2006
Yes, TPK that is precisely the way I am calling the javascript. The alert window works fine (I put it in there as a test), but the next SWF file doesn't load.

terrence wood, what I am trying to do is load another SWF in the same browser window when the first one ends. Hopefully that makes sense...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 08, 2006 Aug 08, 2006
Two non javascript methods:
Movie End Options -> Action ->> Open URL or file

Button -> On Success ->> Open URL or file

A method to load a new movie without completly reloading the page.

1. Create two 200x200 movies - m1 and m2 - add some content.
2. Create a button in m1 set Exectue Javascript ->> loadMovie('m2.htm');
3. Publish html and swfs to the same folder.
4. Open m1.htm and replace all the code with the following (up to and including </html>):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>m1</title>
<script type="text/javascript">
var xmlHttp

function loadMovie(url)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("movieContainer").innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}

return objXMLHttp
}

</script>
</head>
<body>
<div id="movieContainer">
<!-- captivate generated code -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=" http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="200" height="200" id="Captivate1" align="middle">
<param name="allowScriptAccess" value="sameDomain">
<param name="movie" value="m1.swf">
<param name="quality" value="high">
<param name="menu" value="false">
<param name="loop" value="0">
<param name="bgcolor" value="#f3f3f3">
<embed src="m1.swf" name="Captivate1" quality="high" bgcolor="#f3f3f3" width="200" height="200" name="menu" align="middle" allowScriptAccess="sameDomain" loop="0" type="application/x-shockwave-flash" menu="false" pluginspage=" http://www.macromedia.com/go/getflashplayer">
</object>
<!-- end Captivate code -->
</div>
</body>
</html>

5. Open m2.htm and replace the code with the following:
<!-- Captivate generated code -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=" http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="200" height="200" id="Captivate1" align="middle">
<param name="allowScriptAccess" value="sameDomain">
<param name="movie" value="m2.swf">
<param name="quality" value="high">
<param name="menu" value="false">
<param name="loop" value="0">
<param name="bgcolor" value="#f3f3f3">
<embed src="m2.swf" name="Captivate1" quality="high" bgcolor="#f3f3f3" width="200" height="200" name="menu" align="middle" allowScriptAccess="sameDomain" loop="0" type="application/x-shockwave-flash" menu="false" pluginspage=" http://www.macromedia.com/go/getflashplayer">
</object>
<!-- end Captivate generated code -->

6. Open m1.htm in you browser, click the button to load m2

How it works:
Simply put AJAX lets you load parts of an html file in the current window. The code to be replaced is within the div id="movieContainer". The code in the file you want to load should be only the code you need, not an entire HTML file.

Call it from Captivate with loadMovie('URL') where URL is the name of the html file.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 09, 2006 Aug 09, 2006
LATEST
Thanks, terrence wood! Your solution worked excellently. I appreciate you taking the trouble to make the directions specific, so I could understand them.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 08, 2006 Aug 08, 2006
Can you clarify - Are you trying to load the movie into the same browser window without reloading the HTML?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources