...

View Full Version : Adding Flash to HTML with Javascript Flashobject



rossmiester
01-07-2012, 10:08 PM
Hi everyone, I have successfully added Flash to my page but I want the flash animation to be inside the <div id="main">. For some reason when I put the <div id="flashcontent"></div> inside the main div it doesn't show up on the page. Please help. My code is below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MikeJamesDesigns</title>
<link rel="stylesheet" type="text/css" href="cssEdit.css" />

<script type="text/javascript" src="js/flashobject.js"></script>

<script type="text/javascript">
var fo = new FlashObject("bannerISRAEL.swf", "animationName", "450", "60", "8", "#FFFFFF");
fo.addParam("allowScriptAccess", "sameDomain");
fo.addParam("quality", "high");
fo.addParam("scale", "noscale");
fo.addParam("loop", "true");
fo.write("flashcontent");

</script>

</head>

<body>

<!--<div class="tikiImage">
<img src="/Users/MikeJamesRossi/Desktop/cssEdit/images/tiki.png" alt="tikiTorch" height="1040px" width="1100px"/>
</div>-->

<div id="wrapper">

<div id="sitebranding">
</div><!--end of sitebranding div-->

<div id="navigation">
<a href="home">Home</a> | <a href="about">About</a> | <a href="news">News</a> | <a href="images">Images</a> | <a href="home">Faq</a> | <a href="contact">Contact</a>
</div><!--end of navigation div-->

<div id="main">

<div id="flashcontent"></div>

</div><!--end of main div-->

</div><!--end of wrapper div-->

</body>

</html>


My css file looks like this:

#flashcontent {
position: relative;
top: 500px;
left: 365px;
width: 60px;
height:px;
background-color:red;
z-index: ;
}


Any help would be greatly aprreciated!! Thanks Mike! :)

oVTech
01-08-2012, 10:03 AM
<script type="text/javascript">
var fo = new FlashObject("bannerISRAEL.swf", "animationName", "450", "60", "8", "#FFFFFF");
fo.addParam("allowScriptAccess", "sameDomain");
fo.addParam("quality", "high");
fo.addParam("scale", "noscale");
fo.addParam("loop", "true");
fo.write("flashcontent");
</script>



Try to add the script above after the div with id "flashcontent", or else try to wrap it in a window.onload like so:



<script type="text/javascript">
window.onload = function () {
var fo = new FlashObject("bannerISRAEL.swf", "animationName", "450", "60", "8", "#FFFFFF");
fo.addParam("allowScriptAccess", "sameDomain");
fo.addParam("quality", "high");
fo.addParam("scale", "noscale");
fo.addParam("loop", "true");
fo.write("flashcontent");
}
</script>

rossmiester
01-08-2012, 11:23 AM
OMG, I thought I did that before! IT WORKS!! I put the code under the div and now it works.

How come you have to have the code under the div in order for it to work? I didn't even know that the <script> tag could go in the <body> tag. I always thought that the <script> tag should always be in the <head> tag. Interesting.

Thanks so much!! I appreciate the help, took me hours trying to figure out why this wasn't working!! Cheers!! :)

oVTech
01-08-2012, 11:41 AM
How come you have to have the code under the div in order for it to work? I didn't even know that the <script> tag could go in the <body> tag. I always thought that the <script> tag should always be in the <head> tag. Interesting.




You can place script tags in the head and body but that depends on your application. In your case you must place the script under the div because the div where the script is writing to has to be first loaded by the browser.

Browsers read source-code from top to bottom. When placed in the head, the script tries to use a div that isn't yet loaded in the browser, therefore it fails. Because of this we use the window.onload trick to ensure that the html is loaded before we make any changes to it via a script, but placing the script after the markup works too.

rossmiester
01-10-2012, 09:30 AM
Thanks a bunch! Makes total sense!! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum