Coral3
asked on
Using JavaScript to interact with Flash
Hello,
My ultimate goal is to load my Flash banner last after all of my images and HTML have finished loading, while still allowing SWFObject flash detection to work. Here's a description of the SWFObject I'm using:
http://code.google.com/p/swfobject/wiki/documentation
I am using the static publishing method.
I've researched the various ways to force the Flash movie to load last, but I haven't been able to get any of them to work. One suggestion that had promise was to use two SWF movies. The first SWF is embedded into my document, and it has two keyframes, with a "stop();" in the first, and the second keyframe loads the main movie I want. Using Java Script, I tell Flash to play the movie "onLoad", thereby going to the keyframe which loads my movie after everything else has loaded. It worked very well when I used the conventional way to embed flash into HTML, using both <object> and <embed> tags. But since SWFObject doesn't embed Flash this way, I believe it's interfering with this, and therefore it only seems to work in IE. I attached the code below, and you can see an example here:
http://www.livingwaterscommunitychurch.org/example.html
Another clever idea I read was to comment out the part of the HTML I wanted to be loaded last (in this case the Flash div), and then write a function that erases the comments "onLoad", thereby loading my Flash last. Here's a quote about how to implement this idea:
"Try to put the object tag (<object type="application/x-shockw ave-flash" etc.....</object>) containing the .swf file inside a div.
Name the div "myFlash" for arguments sake.
Comment out the object tag as follows:
<div id="myFlash"><!--<object type="application/x-shockw ave-flash" ...</object>--></div>
Next: add to the body tag <body onLoad="javascript:reWrite Flash();" ...
then paste this Javascript function::
<script language="javascript" type="text/javascript">
function reWriteFlash(){
var myHTML = document.getElementById("m yFlash").i nnerHTML;
myHTML = myHTML.replace("<!--","");
myHTML = myHTML.replace("-->","");
document.getElementById("m yFlash").i nnerHTML = myHTML;
}
</script>
What this does is on the event "onLoad" (once all HTML is loaded), comments out the object tag and, hence, starts rendering the object and loads the flash file."
When I tried to do this, I failed utterly, so either I don't know how to properly write the code, or something is wrong with the idea itself (it's probably the former).
Any help with this would be greatly appreciated. If anyone can show me how to properly implement either of these solutions, or if there's another simpler idea that would allow my Flash to load last without interfering with the SWFObject (assuming it's possible), I'm open to any ideas.
Thanks in advance,
~Coral
My ultimate goal is to load my Flash banner last after all of my images and HTML have finished loading, while still allowing SWFObject flash detection to work. Here's a description of the SWFObject I'm using:
http://code.google.com/p/swfobject/wiki/documentation
I am using the static publishing method.
I've researched the various ways to force the Flash movie to load last, but I haven't been able to get any of them to work. One suggestion that had promise was to use two SWF movies. The first SWF is embedded into my document, and it has two keyframes, with a "stop();" in the first, and the second keyframe loads the main movie I want. Using Java Script, I tell Flash to play the movie "onLoad", thereby going to the keyframe which loads my movie after everything else has loaded. It worked very well when I used the conventional way to embed flash into HTML, using both <object> and <embed> tags. But since SWFObject doesn't embed Flash this way, I believe it's interfering with this, and therefore it only seems to work in IE. I attached the code below, and you can see an example here:
http://www.livingwaterscommunitychurch.org/example.html
Another clever idea I read was to comment out the part of the HTML I wanted to be loaded last (in this case the Flash div), and then write a function that erases the comments "onLoad", thereby loading my Flash last. Here's a quote about how to implement this idea:
"Try to put the object tag (<object type="application/x-shockw
Name the div "myFlash" for arguments sake.
Comment out the object tag as follows:
<div id="myFlash"><!--<object type="application/x-shockw
Next: add to the body tag <body onLoad="javascript:reWrite
then paste this Javascript function::
<script language="javascript" type="text/javascript">
function reWriteFlash(){
var myHTML = document.getElementById("m
myHTML = myHTML.replace("<!--","");
myHTML = myHTML.replace("-->","");
document.getElementById("m
}
</script>
What this does is on the event "onLoad" (once all HTML is loaded), comments out the object tag and, hence, starts rendering the object and loads the flash file."
When I tried to do this, I failed utterly, so either I don't know how to properly write the code, or something is wrong with the idea itself (it's probably the former).
Any help with this would be greatly appreciated. If anyone can show me how to properly implement either of these solutions, or if there's another simpler idea that would allow my Flash to load last without interfering with the SWFObject (assuming it's possible), I'm open to any ideas.
Thanks in advance,
~Coral
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.registerObject("bandwidth", "8.0.0");
</script>
<script type="text/javascript">
<!--
// F. Permadi May 2000
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 // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
{
return document.getElementById(movieName);
}
}
function PlayFlashMovie()
{
var flashMovie=getFlashMovieObject("loader");
flashMovie.Play();
//embed.nativeProperty.anotherNativeMethod();
}
//-->
</script>
<style type="text/css">
body {
margin:0px 0px;
padding:0px;
text-align:center;
}
#flash{
position:relative;
margin:0px auto;
padding:0px;
text-align:center;
z-index: 1;
width: 200;
height: 200;
}
</style>
</head>
<body onLoad="PlayFlashMovie();">
<div id="flash">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="200" height="200" id="loader">
<param name="movie" value="loader.swf" />
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<param name="swliveconnect" value="true" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="loader.swf" width="200" height="200">
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<param name="swliveconnect" value="true" />
<!--<![endif]-->
<div id="alternate" align="center"><a href="index.html"><img src="clear.gif" alt="Home" title="Home" width="735" height="159" border="0"/></a></div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</div>
</body>
</html>
Hi, basically you have to use javascript and html to embed flash object in your page.
Follow the best practices and you're good to go.
First have a look at this link:
Proper Flash embedding: FlashObject Best Practices:
http://blog.deconcept.com/2005/03/31/proper-flash-embedding-flashobject-best-practices/
And this will be more important:
Web standards compliant Javascript Flash detect and embed
http://blog.deconcept.com/2004/10/14/web-standards-compliant-javascript-flash-detect-and-embed/
Even the links show how to add variables to your flash object using javascript.
Hope it helped.
Enjoy Coding!Hi, basically you have to use javascript and html to embed flash object in your page.
Follow the best practices and you're good to go.
First have a look at this link:
Proper Flash embedding: FlashObject Best Practices:
http://blog.deconcept.com/2005/03/31/proper-flash-embedding-flashobject-best-practices/
And this will be more important:
Web standards compliant Javascript Flash detect and embed
http://blog.deconcept.com/2004/10/14/web-standards-compliant-javascript-flash-detect-and-embed/
Even the links show how to add variables to your flash object using javascript.
Hope it helped.
Enjoy Coding!
Follow the best practices and you're good to go.
First have a look at this link:
Proper Flash embedding: FlashObject Best Practices:
http://blog.deconcept.com/2005/03/31/proper-flash-embedding-flashobject-best-practices/
And this will be more important:
Web standards compliant Javascript Flash detect and embed
http://blog.deconcept.com/2004/10/14/web-standards-compliant-javascript-flash-detect-and-embed/
Even the links show how to add variables to your flash object using javascript.
Hope it helped.
Enjoy Coding!Hi, basically you have to use javascript and html to embed flash object in your page.
Follow the best practices and you're good to go.
First have a look at this link:
Proper Flash embedding: FlashObject Best Practices:
http://blog.deconcept.com/2005/03/31/proper-flash-embedding-flashobject-best-practices/
And this will be more important:
Web standards compliant Javascript Flash detect and embed
http://blog.deconcept.com/2004/10/14/web-standards-compliant-javascript-flash-detect-and-embed/
Even the links show how to add variables to your flash object using javascript.
Hope it helped.
Enjoy Coding!
ASKER
Thanks, techExtreme. That's what the SWFObject is all about, embedding Flash in the page.
http://blog.deconcept.com/swfobject/
I said at the beginning how I'm using the SWFObject, so I guess I'm not really sure what you mean.
http://blog.deconcept.com/swfobject/
I said at the beginning how I'm using the SWFObject, so I guess I'm not really sure what you mean.
ASKER
Sigh, my "solution" doesn't work afterall. :( I'm going to have repost this question.
techExtreme, SWFObject both embeds and detects flash all in one simple solution, which is what I want. I'd rather not use the very bulky detection kit made by Macromedia if I can help it.
techExtreme, SWFObject both embeds and detects flash all in one simple solution, which is what I want. I'd rather not use the very bulky detection kit made by Macromedia if I can help it.
ASKER
techExtreme, I just realized that SWFObject is basically an updated version of FlashObject (developed by the same person).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Good that you found answer. Hope I'll be able to help you in your future queries.
ASKER
Thank you for trying to help me, even if it wasn't the solution it was greatly appreciated. :)
ASKER
~Coral
Open in new window