Click to See Complete Forum and Search --> : document.write


Shawn
02-27-2004, 12:01 PM
Ok....anyone know why this isn't writing the Flash content to my layer? If I replace it with some image HTML it works, but with Flash, nothing appears?


document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' );
document.write ('codebase=
"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"
width="350" height="300">');
document.write ('<param name="movie" value="cannonshoot.swf">');
document.write ('<param name="quality" value="high">');
document.write ('<param name="wmode" value="transparent">');
document.write ('<embed src="cannonshoot.swf"
width="350" height="300" quality="high" pluginspage=
"http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" wmode="transparent">');
document.write ('</embed></object>');

Kor
02-27-2004, 12:29 PM
Try using .innerHTML method instead of .write

Shawn
02-27-2004, 12:37 PM
Hmmm... I tried document.innerHTML instead and just get an error that object does not suport this property or method.

Shawn
02-27-2004, 12:39 PM
It might be heplful to make sure you know that this document.write is coming right after a layercreating script command. If I take what you see there and copy and paste it in a javascript tag in the body of an HTML document, it writes the flash file just fine. Also if I replace the flash file content with some other HTML like an image, it works fine in the layer. But trying to write it on a layer with Flash does not seem to be working?

Kor
02-27-2004, 12:56 PM
<div id="bla"></div>


and use

<script>
function writeF(){
document.getElementById('bla').innerHTML = 'all the FLASH tags here";
}
window.onload=writeF;
</script>

beware about the empty spaces when inserting the HTML tags into the innerHTML value. If there is another simple quote ', mark it with a back slash like: /'

Kor
02-27-2004, 12:58 PM
sorry
'all the FLASH tags here';

Shawn
02-27-2004, 01:01 PM
Thanks man! Your a lifesaver.

Shawn
02-27-2004, 01:04 PM
Yea, I caught that missing quote. The actual script is something I made up for a reusable create layer function, so the info for the document write is a variable I pass it. I've got to make all my javascript portabale for my job so all a customer has to do is instert a javascript tag with src= blah blah. Otherwise I've wrote to layers before by just jumping out of the script and doing the html, then jumping back in the script for Flash. But yea, this worked great, thanks.

Kor
02-27-2004, 01:18 PM
You could have used document.write either, but it is an old heavy intricate seqeunce of:
document open ...document.write...document.close, or something like that

On the other hand, written on body, document.write can not help you passing different values... It is simply loaded once, and "died there for ever" :D

fredmv
02-27-2004, 03:15 PM
You should really be using pure DOM functionality as opposed to document.write and moreover, why are you creating this with JavaScript in the first place?

Shawn
02-27-2004, 03:48 PM
Are you asking why I am creating this with javascript as opposed to HTML? If so, this particlar section of code I have listed here is a small part to the bigger whole of the program. I've got a program that creates a layer with an flash animation that is movables across the screen and some other layer stuff going on. At the same time the code I'm writing is not for me, but for the company I work for and it needs to be as easy to install as possible, so they can just put in a Javascript tag with the src= pointing to my file so I'm trying to keep all of it in the Javascript file.

fredmv
02-27-2004, 03:49 PM
Was just curious as there may have been a more practical solution. Note, however, using pure DOM functionality would still be better...

Shawn
02-27-2004, 03:54 PM
I'm sorry, but what exactly do you mean by pure DOM functionality?

fredmv
02-27-2004, 04:06 PM
Very sorry for the lack of clarity; I shouldn't just assume you to know what that means. What I mean is, using built-in functions of the DOM (Document Object Model) to dynamically generate this source code and append it to the document. For instance, instead of writing it like you currently have, you'd do it like this:<script type="text/javascript">
//<![CDATA[
onload = function()
{
var o = document.createElement('object'), p1 = document.createElement('param'), p2 = document.createElement('param'), p3 = document.createElement('param'), e = document.createElement('embed');

o.setAttribute('classid', 'clsid:27CDB6E-AE6D-11cf-96B8-444553540000');
o.setAttribute('codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0');

p1.setAttribute('movie', 'cannonshoot.swf');
p2.setAttribute('quality', 'high');
p3.setAttribute('wmode', 'transparent');

e.setAttribute('src', 'cannonshoot.swf');
e.setAttribute('width', '350');
e.setAttribute('height', '300');
e.setAttribute('quality', 'high');
e.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer/');
e.setAttribute('type', 'application/x-shockwave-flash');
e.setAttribute('wmode', 'transparent');

o.appendChild(p1);
o.appendChild(p2);
o.appendChild(p3);
o.appendChild(e);

document.body.appendChild(o);
}
//]]>
</script>

Shawn
02-27-2004, 04:13 PM
ahh yes, very nice. I'm kinda doing a three part job here with graphic design/flash animation/javascript in the project, but I will definetelly look into coding that way in the future. It does seem like a lot better way of doing things.

Shawn
02-27-2004, 04:15 PM
I've coded objects that way before just to get information on attributes or change them, but haven't really thought of doing it to create the object from scratch. Would make it a lot easier to refer to though.

Shawn
02-27-2004, 07:37 PM
Actually I have been looking at your full DOM code in more depth, and it is a little different than what I expected. Anyway, yes I'm back again with problems. Using innerHTML worked fine until I got to the point where I needed to create another layer, then it seemed to overide all the other layers. I'm not even positive if it is creating the content on a layer. Regardless, I tried using the object type code to create my layers and I'm getting errors. Here is more of my code if anyone feels like helping a guy out. This is the function I made to create layers and I pass the content to it usually which is the html content of the layer. Just to test out the object code though, I have hardcoded it in and changed the original into comments.
function createLayer (name, xpos, ypos, content, flash) {
//***********************************************************************************


if (NS4) {
document.write('<LAYER NAME="'+name+'" LEFT="'+xpos+'" TOP="'+ypos+'">');
}

if ((IE) || (NS6)) {
document.write(' <div id="'+name+'" style="position:absolute; left: '+xpos+
' ; top: '+ypos+
' ;"> ' );
}

//*************************************************************************************
if (content) {
/*
if (flash) {
function writeF(){
document.getElementById(name).innerHTML = content;
}
this.onload=writeF;
}
else {
document.write (content);
}
}*/

onload = function()
{
var o = document.createElement('object')
p1 = document.createElement('param')
p2 = document.createElement('param')
p3 = document.createElement('param')
e = document.createElement('embed');

o.setAttribute('classid', 'clsid:27CDB6E-AE6D-11cf-96B8-444553540000');
o.setAttribute('codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0');

p1.setAttribute('movie', 'cannonshoot.swf');
p2.setAttribute('quality', 'high');
p3.setAttribute('wmode', 'transparent');

e.setAttribute('src', 'cannonshoot.swf');
e.setAttribute('width', '350');
e.setAttribute('height', '300');
e.setAttribute('quality', 'high');
e.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer/');
e.setAttribute('type', 'application/x-shockwave-flash');
e.setAttribute('wmode', 'transparent');

o.appendChild(p1);
o.appendChild(p2);
o.appendChild(p3);
o.appendChild(e);

document.body.appendChild(o);
}
}

fredmv
02-27-2004, 07:49 PM
I anticipated there would be some errors simply because I didn't test the code before providing it. Could you perhaps be a little bit more specifc as to what exactly you're getting for an error?

Shawn
02-27-2004, 08:00 PM
Yea, I'm surpised you took the time to write all that up, let alone debug it. Thanks for the help on that.

Well, before I was getting an error of something like object does not support that type for the o.appendChild(p1); line. But as of now I've been messing with it so much that all I'm getting is a } expected error pointing toward the last line of the code, so I'll see if I can work that out and let you know where the problems lies in this...

Shawn
02-27-2004, 08:04 PM
Ok, found my missing }....now on to the real stuff:
I'm getting an invalid argument error pointing to around thise lines:

o.appendChild(p1);
o.appendChild(p2);
o.appendChild(p3);

Shawn
02-27-2004, 08:05 PM
Is this for HTML or just XML...just curious, because I have only begun to learn XML.

Shawn
02-27-2004, 08:22 PM
what do you know...I changed all the o's in the area of the error to document.body like the last line and it worked? Is that supposed to work like that?
Hmmm...yea, this nice little layer creation function, and a few others I made to move layers around worked fine until I had to bring Flash into the picture. Now to see if I can make this new code a universal function again.

Shawn
02-27-2004, 08:48 PM
Hmmmm...well, complications arise again. It looks like doing it this way, it's either not created on a layer or the layer doesn't work the same, because the previous way it let me make the Flash on top of stuff...now it seems to put it in-line like normal HTML. Plus there is some odd little square with a dot in it next to my flash now? Grrr...all I was trying to do is have a cannon shoot on one layer and when it does a cannonball that is on another layer will be repositioned around to shoot across the screen. Would have been done by now if not for using Flash instead of all images....thanks for all your help though.

Shawn
03-04-2004, 02:28 AM
You know there fredmv, I did some serious studying on the DOM after this...well, after I found out that I have to completely place a flash file on the page in the HEADER tag with an onload= command and I think adding objects with createElement and appendChild is the only way it's going to work....but.....
Your script was right and IE is wrong. IE will error out if you try to append the param tags into the object. Netscape will handle it fine. As a matter of fact, I've been round and round this thing and the only way I can place Flash this way in IE is to leave out the object tag altogether and just use the embed? Which to me seems more backward than anything because Netscape was the user of the embed tag, not IE!! So, very weird....anyway I can create it the 'right' way and it works in Netscape and then I have to use only embed in IE. This presents very big problems, because now I am not able to access the flash file by name if I create it with just the embed in IE. I need to access it by name because I need to send it a command to play after something else has loaded. I also need flash to talk to javascript to tell it when it has reached a certain frame. Well, I can post my script so far if anyone cares to see, but here is the real question.
How to create Flash in IE with DOM objects and be able to send commands to the Flash file. This will work in Netscape, but I haven't got it to work in IE.

Shawn
03-04-2004, 02:10 PM
Ok, well I did it....I don't know how but I did it. I even read an article on the net by some Javascript Professor that said it wasn't possible. I'll see if I can post more detailed information once I figure out really what it is that I did ha ha. The main thing is that IE will not access the object tag with embed appended to it....IE needs to create a flash object with the embed tag!!! Now, how do you go about putting the params for wmode/transparent and naming the thing.....Well, here's what I got. It works and it really shouldn't:

Obj = document.createElement("embed","wmode");
Obj.setAttribute("src",swf);
Obj.setAttribute("width",250);
Obj.setAttribute("height",300);
Obj.setAttribute("wmode", "transparent");
Obj.setAttribute ("id",flashID);
layer.appendChild(Obj);

So I guess I kind of created a um...embed tag and wmode in one...or sorta. I really don't understand it myself but at least the damn thing works! I can even talk to the flash movie with the flashID name through javascript and send commands to javascript with getURL ("javascript myfunction()") in actionscript. Plus this is all loaded in the head of the document which means just one line of code to load the source and I'm playing with layers with transparent Flash now in both IE and Netscape...YEA!

fredmv
03-04-2004, 04:25 PM
Sorry for not getting to this sooner — I haven't really been keeping up with this thread as much as I should. Anyway, great to hear you got it working&hellip; :cool:

Shawn
03-04-2004, 04:28 PM
Hey, not your job! You got me thinking in another direction though, and that helped a lot!

fredmv
03-04-2004, 04:30 PM
Not my job, though I try to handle it as if it is! Good to see you're happy with the way things turned out. :D

California
03-09-2004, 12:55 PM
Creating multiple html pages

i was trying read the threads of this topic, which i thought it ight be very usefull for my project but the thread looks way beyond my level

Can anyone help me . . .

---------------------------------------------------------
Do I have to create four html pages, Or is it possible to access different swf in one html page.
----------------------------------------------------------

I am attaching the ZIP file, if anyone have some time can you please take a look at the source code and create a sample link or explain how it should work. I just need one sample html link accessing the swf. Please help


I am that good in javascript so please help, thanks

Shawn
03-09-2004, 08:32 PM
What your looking for could probably be accomplished easier by creating only one Flash movie with multiple parts or one flash movie that loads other movies into it. You can control flash movies with javascript. For instance if you have one flash movie with the different parts you need on seperate frames, you could paste the following script I put together into the <HEAD> of your html file:


<script language="JavaScript" type="text/JavaScript">

/*-----------------------Controlling Flash Movies Functions-------------------------------*/

/*
Function Description
Access the movie object depending on the browser
Accepts:
Required:
- movieName : The id name of the embedded Flash movie
*/
function thisMovie(movieName) {
if (navigator.appName.indexOf ("Microsoft") !=-1) {
return window[movieName];
} else {
return document[movieName];
}
}
/*
Function Description
Check to see if movie is loaded
Accepts:
Required:
- movieName : The id name of the embedded Flash movie
*/
function movieIsLoaded (movieName) {
if (typeof(movieName) != "undefined") {
return movieName.PercentLoaded() == 100;
} else {
return false;
}
}
/*
Function Description
Skip to a specified frame and begin play
Accepts:
Required:
- movieName : The id name of the embedded Flash movie
- frame : The frame number to skip to in the movie
*/
function playMovie (movieName, frame) {
if (movieIsLoaded (thisMovie(movieName))) {
thisMovie (movieName).GotoFrame (frame);
thisMovie (movieName).Play();
}
}

</script>


Then after inserting your flash movie and giving it an id param to know what to call it, put this in your link and play the apropriate frame with it:

onClick = "playMovie (5)"

I just kinda typed this up so their might be errors and I'm also not sure of your knowledge of Flash or javascript, so let me know if this helps.