View Full Version : changing html body bgcolor with flash n java

02-26-2009, 11:55 PM
hi there,

i thought i just post my question about my problem, maybe somebady can help. To be honest, I did some google about the problem, but as I know so little about java I just did get it. I tryed out some code, but it is very dificult to follow some blog's advice (no ofense pls) if you dont understand a line of code of what the author is saying.

I have to chnage the body bgcolor of my html page constantly, everytime my flashproject loads another page. I dont want to have my flash project to play on a black bg. That would look very nasty for this project.

Can somebody walk me through? Pls be advice that I have no idea of java.

Thx to anyone out there.

02-27-2009, 08:58 AM
Here's a small function that should get you going:

<script type="text/javascript">
function ChangeBackgroundColor(hex){
document.getElementsByTagName('body')[0].style.backgroundColor = hex;
window.onload = ChangeBackgroundColor('#990000')

Basically, the getElementsByTagName returns an array of all the tags with the specified name. We then use javascript to give the first (and only) body tag an inline style with the passed hex value.

The window.onload makes the function run when the window opens.

Hope this helps.

02-27-2009, 01:48 PM
Link removed.

I look at code as others look at the sunset!
An expert is someone who learns more and more about less and less,
and eventually knows everything about nothing.

02-28-2009, 03:17 PM
you can have the flash change the background color all by itself:

AS3 code
import flash.external.*;
var JStodo:XML=
function (thiscolor) {

function changecolor(tothis)

ExternalInterface.call(JStodo, '#FF0000');

Doing so you can keep the call to change the background color in the flash, that way,
in your case, you can set up a function in your flash that would change the background color whenever it loads a new page.

I don't know what your using to make your swf, so i can't really walk you threw the code, the above example would be for a pure AS3 solution.

now, why don't your different pages define a bgcolor for themselves in the HTML?
are you not talking about HTML pages?

Also to be clear, the above example uses JavaScript inside AS3, the example Wispa gave you, which will work as well, is JavaScript inside HTML, Java and JavaScript are two completely differnt things.

03-06-2009, 01:59 PM
First off all, thanks for your help.

Ill try it out and report later.

Java and JavaScript are two completely differnt things.

Ok, I know this is not a Java forum, but: ??????