adding flash on load

W

windandwaves

Hi Folk

I am trying to add flash onload

This is the function I came up with:

function makeflash(name, width, height) {
//if (!DHTML) return;
name = 'v/' + name + '.swf';
var box = document.createElement('flasher')
var obj = createflashObject(name, width, height);
box.appendChild(obj);
obj.appendChild(createParam('movie', name));
obj.appendChild(createParam('quality', 'high'));
obj.appendChild(createParam('bgcolor', '#000000'));
return box;
}



function createflashObject(name, width, height) {
var obj = document.createElement('object');
obj.setAttribute('type', 'application/x-shockwave-flash');
obj.setAttribute('data', name);
obj.setAttribute('width', width);
obj.setAttribute('height', height);
return obj;
}

function createParam(n, v) {
var el = document.createElement('param');
el.setAttribute('name', n);
el.setAttribute('value', v);
return el;
}

It does not give any errors, but it is not working either.

my html looks as follows:

....header here
<body onload="makeflash('abc.swf', 100, 100);">
<div id="flasher"></div>
....etc...

I should probably use getelementbyid rather than createlement, but that does
not seem to work either

any help greatly appreciated.

Thank you
 
V

VK

windandwaves said:
var box = document.createElement('flasher')

AFAIK there is not such HTML element. You maybe wanted to say:

var box = document.createElement('OBJECT');
box.id = 'flasher';

?
 
W

windandwaves

VK said:
AFAIK there is not such HTML element. You maybe wanted to say:

var box = document.createElement('OBJECT');
box.id = 'flasher';

?

You are so right. However, we create the object element further down.

I have added this instead:

var box = new getObj("flasher");

where getObj returns the object ()

function getObj(name) {
if (document.getElementById) {
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
}
}

Now the error is box.appendChild is not a function.

I am not sure how to proceed.

Can you help
 
R

RobG

windandwaves said:
You are so right. However, we create the object element further down.

I have added this instead:

var box = new getObj("flasher");

where getObj returns the object ()

function getObj(name) {
if (document.getElementById) {
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
}
}

That could be better written as:

function getObj(name)
{
this.obj = null;
this.style = null;

if (document.getElementById) {
this.obj = document.getElementById(name);
}

if (this.obj && this.obj.style){
this.style = this.obj.style;
}
}

Now the error is box.appendChild is not a function.

No, it's not. box is a instance of your - getObj - object, and you
haven't defined an appendChild method for it. I think what you really
want to do is call the appendChild method of the element referenced by
box.obj (if there is one), i.e.:

box.appendChild(obj);


should be:

box.obj.appendChild(obj);


or:

box.obj && box.obj.appendChild && box.obj.appendChild(obj);
 
W

windandwaves

RobG said:
That could be better written as:

function getObj(name)
{
this.obj = null;
this.style = null;

if (document.getElementById) {
this.obj = document.getElementById(name);
}

if (this.obj && this.obj.style){
this.style = this.obj.style;
}
}



No, it's not. box is a instance of your - getObj - object, and you
haven't defined an appendChild method for it. I think what you really
want to do is call the appendChild method of the element referenced by
box.obj (if there is one), i.e.:

box.appendChild(obj);


should be:

box.obj.appendChild(obj);


or:

box.obj && box.obj.appendChild && box.obj.appendChild(obj);

I changed my function to this now and IT IS WORKING!

function getObj(name) {
this.obj = null;
this.style = null;
if (document.getElementById) {
this.obj = document.getElementById(name);
if (this.obj && this.obj.style){
this.style = this.obj.style;
}
}
else if (document.all) {
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers) {
this.obj = document.layers[name];
this.style = document.layers[name];
}
}


/**
* Create a flash object
*/

function makeflash(name, width, height) {
//if (!DHTML) return;
name = 'v/' + name + '.swf';
var box = document.getElementById("flasher");
var obj = createflashObject(name, width, height);
box.appendChild(obj);
obj.appendChild(createParam('movie', name));
obj.appendChild(createParam('quality', 'high'));
obj.appendChild(createParam('bgcolor', '#000000'));
return box;
}



function createflashObject(name, width, height) {
var obj = document.createElement('object');
obj.setAttribute('type', 'application/x-shockwave-flash');
obj.setAttribute('data', name);
obj.setAttribute('width', width);
obj.setAttribute('height', height);
return obj;
}

function createParam(n, v) {
var el = document.createElement('param');
el.setAttribute('name', n);
el.setAttribute('value', v);
return el;
}

However, not in IE. Does anyone know how to get this baby going in IE?

I am basically trying to get this, but only after the page has been loaded.
The reason for this is that I use some other functions onload and i want
those to be carried out first as the flash is almost 1 meg and takes a while
to load....

<object type="application/x-shockwave-flash" data="v/index.swf"
width="875" height="215">
<param name="movie" value="v/index.swf" />
<param name="bgcolor" value="#000" />
<a title="You must install the Flash Plugin for your Browser in order
to view this movie"
href="http://www.macromedia.com/shockwave/download/alternates/">get the
required <q>plug-in</q>: Macromedia Flash</a>
</object>


TIA

- Nicolaas
 
W

windandwaves

RobG said:
That could be better written as:

function getObj(name)
{
this.obj = null;
this.style = null;

if (document.getElementById) {
this.obj = document.getElementById(name);
}

if (this.obj && this.obj.style){
this.style = this.obj.style;
}
}



No, it's not. box is a instance of your - getObj - object, and you
haven't defined an appendChild method for it. I think what you really
want to do is call the appendChild method of the element referenced by
box.obj (if there is one), i.e.:

box.appendChild(obj);


should be:

box.obj.appendChild(obj);


or:

box.obj && box.obj.appendChild && box.obj.appendChild(obj);

Email me (javascript at ngaru.com) to see an example...

Thank you.

- Nicolaas
 
R

RobG

windandwaves wrote:
[...]
I changed my function to this now and IT IS WORKING!

function getObj(name) { [...]
}

This function is not called, so it isn't used.
/**
* Create a flash object
*/

function makeflash(name, width, height) {
//if (!DHTML) return;
name = 'v/' + name + '.swf';
var box = document.getElementById("flasher");

Despite the feature testing you added to getObj(), you bypass it
completely here by using a direct call to getElementById.

But that is irrelevant to why it won't work in IE (i.e. IE 5+).


[...]
 
W

windandwaves

RobG said:
windandwaves wrote:
[...]
I changed my function to this now and IT IS WORKING!

function getObj(name) { [...]
}

This function is not called, so it isn't used.
/**
* Create a flash object
*/

function makeflash(name, width, height) {
//if (!DHTML) return;
name = 'v/' + name + '.swf';
var box = document.getElementById("flasher");

Despite the feature testing you added to getObj(), you bypass it
completely here by using a direct call to getElementById.

But that is irrelevant to why it won't work in IE (i.e. IE 5+).


[...]

Hi Rob

Yes, sorry, that was the main focus of my project. I am still a JS
beginner, but this time I am trying to get a flash file to load "onload".
the reason I am doing this is because I want to display the rest of the page
ASAP and the flash file is rather large.

Thanks for your help

- Nicolaas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,048
Members
48,769
Latest member
Clifft

Latest Threads

Top