Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-26-2009, 11:55 PM   #1
as3 and flash newby
Join Date: Oct 2008
Posts: 13
Default changing html body bgcolor with flash n java

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.
cwaidelich is offline   Reply With Quote
Old 02-27-2009, 08:58 AM   #2
Senior Member
Wispa's Avatar
Join Date: Mar 2006
Posts: 107

Here's a small function that should get you going:

HTML Code:
<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.
Wispa is offline   Reply With Quote
Old 02-27-2009, 01:48 PM   #3
Banned by AS.org Staff
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073

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.
atomic is offline   Reply With Quote
Old 02-28-2009, 03:17 PM   #4
tadster's Avatar
Join Date: Feb 2009
Location: Texas
Posts: 2,111

you can have the flash change the background color all by itself:

ActionScript Code:
AS3 code ... import flash.external.*; ... var JStodo:XML= <script> <![CDATA[ function (thiscolor) { function changecolor(tothis) { window.document.getElementsByTagName('body')[0].style.backgroundColor=tothis; }; changecolor(thiscolor); } ]]> </script>; ... 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.
tadster is offline   Reply With Quote
Old 03-06-2009, 01:59 PM   #5
as3 and flash newby
Join Date: Oct 2008
Posts: 13

First off all, thanks for your help.

Ill try it out and report later.

Originally Posted by tadster View Post
Java and JavaScript are two completely differnt things.
Ok, I know this is not a Java forum, but: ??????
cwaidelich is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating ever changing variables sent from HTML to Flash Head In A Pan ActionScript 2.0 0 06-17-2007 04:50 AM
Some Flash Video Converter Tools Compare terry117 Detention 7 05-18-2006 02:08 AM
full width from flash (not html or java) zenaibar ActionScript 2.0 10 12-20-2005 08:05 PM
Telling flash to goto a certain page from html. high1memo HTML and JavaScript 1 05-04-2005 08:33 PM
Using Flash as menu navigation for HTML. JNB HTML and JavaScript 16 01-20-2005 02:44 PM

All times are GMT. The time now is 01:40 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.