PDA

View Full Version : Change HTML background color from Flash??


MrMurk
02-12-2005, 12:20 AM
I need a little help on how to change the background of an HTML page containing a flash movie...from a button inside the flash movie...thanks in advance

Cota
02-12-2005, 02:29 AM
You can create a JavaScript function to change the background of the HTML page containing the flash movie. From within flash, you can call that JavaScript function with getURL("Javascript:FunctionName(); )

inhan
08-13-2005, 10:00 PM
I have been looking for this feature last 3 days with many methods of research in the Net. So here it is, working great:

on (release) {
getURL("javascript:document.body.background='new_bg_pic.jp g'");
}

inhan
08-13-2005, 11:10 PM
Sorry, the one i wrote was for changing background image. The right code for the button (only the button, no scripting elsewhere) is:
on (release) {
getURL("javascript:document.bgColor='#six_digit_color_code");
}
Here I've put some the codes:
http://www.aliinhan.com/sources/JScodes.html

Spiritmonger
08-29-2005, 09:45 PM
:cool:

Perfect and simple script

Thanks inhan, its was helpfull for me too !

Cheers

inhan
08-30-2005, 12:55 PM
anytime :)

aksands
02-15-2007, 03:27 PM
Changing the bg Image of my HTML via Flash is exactly what I want to do! Thank you for providing this script!

I've included the script provided by Inhan...but I'm not getting the expected results.

Please forgive me, but I am not experienced with javascript. Do i need to put a javascript function in my HTML for this to work?

CyanBlue
02-15-2007, 03:33 PM
How about this page??? Don't know about changing the background image, but you should be able to use the similar approach to do so... ;)

http://tutorials.flashvacuum.com/index.php?show=Change_Background_Color

aksands
02-15-2007, 06:00 PM
what would I change in this function to make it change the background image instead of the color?

function changeBgColor(newBgColor) {
if (window.document && window.document.bgColor) {
document.bgColor = newBgColor;
}
}

Thank you!!!

inhan
02-15-2007, 09:54 PM
I'm not sure if it would work on PC's too, but I modified the code and it works with Mac FF & Safari. If you want the image not to repeat, you have to add something to the code (with which I am not familiar).

In the html file, in the "head" section:
<script language="JavaScript">
<!--
function changeBgImg(newBgImg) {
//alert('new image is = ' + newBgImg);
document.body.background = newBgImg
}
-->
</script>

In the flash file:
bgImgages = new Array("1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg");
for (var i = 0; i<bgImgages.length; i++) {
this["color"+i+"_btn"].id = i;
this["color"+i+"_btn"].onRelease = function() {
getURL("javascript:changeBgImg('images/"+bgImgages[this.id]+"')");
};
}

aksands
02-16-2007, 12:38 AM
Thanks! I'll try working with this. I don't need the random part....just need to change the bgimage from a button in Flash, which you described how to do earlier on this post. I just didn't see how the javascript should be written.

I appreciate your help! This is a great forum!

inhan
02-16-2007, 12:45 AM
I'm glad if it works (I'm no pc user so I'm still not sure if it works on a pc).

xenxs
05-03-2007, 02:28 PM
Hey I managed to change the background image in HTML via Flash,
but would it be possible instead of changing an image, to change a
CSS?

Thanks in advance.

//xenxs

sunrising
11-22-2007, 12:42 AM
I tried this script and it seems to work great but it doesn't work when I publish the flash file in Version 8...? Any idea why it doesn't work on Flash 8?

cheekykid
10-16-2008, 03:29 AM
Hi there, I have similar problem about changing a particular html image via actionscript, anyone know know? thanks very much.