Adding dynamic div tag and flash object

Hi all,

I am trying to create a JS file through which I make necessary things run without defining them every time from scratch.

But I am getting error like ‘[COLOR=Red]Object doesn’t support this property or method[/COLOR]’ and don’t know what’s the problem and one more thing is

The flash object connects to a webservice and receives the result from the service.

Could I write all necessary functions to embed flash object and write response to the Document which comes from flash ??

my JS file code :


//creates script tag which includes swfobject.js file to create flash object...
function include(file)  
 {  
   var script  = document.createElement('script');  
   script.src  = file;  
   script.type = 'text/javascript';  
   script.defer = true;     
   document.getElementsByTagName('head').item(0).appendChild(script);     
 }


// Div tag which holds flash content...
 function createDiv()
 {
        var dv = document.createElement("div");
        dv.id = "flashcontent";
        document.body.appendChild(dv);     
}


// script element to create flash object...
function runScript(){
    var script = document.createElement('script');
    script.type = 'text/javascript';  
    script.defer = true;
    script.innerHTML = "var sl = new SWFObject('webservice.swf', 'single', '300', '300', '8');
                           sl.write('flashcontent');"
    document.getElementsByTagName("body").appendChild(script);    
}


// writes responce from flash to the Document...
function writeResponce(s){
    document.write(s);
}


include("swfobject.js"); 

createDiv();

runScript();


Thanks in advance…
pandu :slight_smile:

Can you either provide a link or download Firebug for Firefox and tell us what object doesn’t support what property or method? Thanks.

Thnx for the reply…

When I am using [COLOR=SeaGreen]document.body.appendChild(dv);[/COLOR] method I am getting this Error “[COLOR=Red]Object doesn’t support this property or method[/COLOR]”;

I think the error is because I am executing the function there itself in the JS file rather than in the document.

Any ideas?
pandu :slight_smile:

If you are not calling this from an html file, than there is no body to append it to. If that’s what you mean. Otherwise it shouldn’t be an issue, you can call appendChild from an included js file no problem. If the first is true, you need to create a document with your script and append the elements to it.

Hi actionAction, Thnx for your reply…

  I figured out the bug.  It is becoz of calling [COLOR="Red"]appendChild [/COLOR]method before body tag is defined in HTML form.

So I made it run [COLOR=“Red”]appendChild(dv)[/COLOR] after some time using [COLOR=“Red”]setInterval [/COLOR]function. Its working fine.

But my Total theme is :

      [COLOR="Red"]I want to run these functions anywhere I want by just adding single JS file to a simple HTML form. [/COLOR]

what I mean is : adding [COLOR=“Green”]<script type=“text/javascript” src=http://…/control.js"></script>[/COLOR] in any HTML form should give me the result. this [COLOR=“Blue”]control.js[/COLOR] file will contain all necessary functions.

the updated script for [COLOR=“Blue”]control.js[/COLOR] file is below:


// Creates DIV and Script tags....
function createDiv()
{
	var dv = document.createElement("div");
	dv.id = "flashcontent";
	document.body.appendChild(dv);
	var newscript = document.createElement("script");
	newscript.type = "text/javascript";
	newscript.src = "http://www.mydomain.com/swfobject.js";
	newscript.defer = true;
	newscript.onload = runScript();
	document.body.appendChild(newscript);
}


// Inserts flash object...
function runScript()
{
	var s = new SWFObject("webservice.swf", "single", "300", "300", "8");
	s.write("flashcontent");	
}


// SetInterval function.......
var interval = setInterval(myfun, 100);


function myfun(){
	createDiv();
	clearInterval(interval);
}



function writeResponce(s){
	document.write(s);
}


Now what I am doing here is I am including SWFObject.JS file from my domain and calling its function SWFObject to insert flash object.

But I am getting error here like : ‘[COLOR=“Red”]SWFObject is undefined[/COLOR]’. As you see I am including the file swfobject.js which contains this function. So what goes wrong??

BTW, when I used it locally, means swfobject.js, control.js, my HTML form are in same folder this works great.

Can’t I access the function of a JS file if it is included from other domain ?? is this a problem…?

sorry for a long description…

Thnx…
pandu :slight_smile:

use setTimeout, not setInterval

Hi,

I don’t have problems with setInterval function as it works fine.

My problem is with executing a function within a JS file which is inserted thru [COLOR=SeaGreen]src [/COLOR]element of Script tag from another domain.

I mean in this case is [COLOR=DarkRed]SWFOBJECT.JS[/COLOR] file which restricts usage of its function “[COLOR=Blue]SWFObject[/COLOR]”.

[COLOR=Red]Can’t we execute a function of JS file inserted from other domain in the calling HTML form ??[/COLOR]

Any ideas?

Thanks again…
pandu :slight_smile:

Hi all,

   I found the bugs and solved. The problem is I am accessing the function before it is loading. So I written an onload function to check for loaded content and then executed the JS function. Its working fine now.

But I have a last problem. I am having a function which writes the Args to the Document.

I am using [COLOR=Magenta]ExternalInterface [/COLOR]in Flash to call this function and sending result as Args. (the result comes from webservice).

My Problem here is the [COLOR=Red]writeResponce()[/COLOR] function is not executing although the function exists in the current Document.

I even checked, if the function is available for current Document by creating a [COLOR=Blue]button [/COLOR]and and this function as [COLOR=Blue]onclick [/COLOR]event.

Here is the function :


function writeResponce(s)
{
     if(s != undefined && s)
          document.write(s);
}

Thanks…
pandu :slight_smile: