# Change \<body background\> from within flash

**URL:** <https://forum.kirupa.com/t/change-body-background-from-within-flash/11313>\
**Category:** Uncategorized\
**Created:** [January 15, 2003, 12:35pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313 "2003-01-15T12:35:06Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![sense](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@sense](https://forum.kirupa.com/u/sense)\
**Post date:** [January 15, 2003, 12:35pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/1 "2003-01-15T12:35:06Z")

</div>

hi, is there a script that alows you to change the backgroundimage you use in your html from within flash?

Hope i’m being clear here…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 11:56am UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/2 "2003-01-19T11:56:57Z")

</div>

_bumpercars_

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 1:03pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/3 "2003-01-19T13:03:49Z")

</div>

Here goes:

You’re going to need some functions to place in your head tag.

```php
<script language="JavaScript1.2" type="text/javascript">

function ChangeBgImg(imgs) {
    bdy[0].style.backgroundImage = 'url('+imgs+')';
}

function ChangeBgImgInit() {
    bdy = document.getElementsByTagName("body");
    bdy[0].style.width = "100%";
    bdy[0].style.height = "100%";
    bdy[0].style.margin = "0px";
    bdy[0].style.backgroundImage = 'url(1.jpg)';
}

onload=ChangeBgImgInit;
</script>

```

Now you’re going to need to call the ChangeBgImg(imgs) function from within flash. Here’s a simple button that will change the background image.

```php
on(release) {
	getURL("javascript: ChangeBgImg('2.jpg')");
}

```

All you need do now is place your images in the same folder as the swf and html file, for simplicity and create some more buttons, for example, to change the background image with flash!

If you look at the onload bit, after the second function is defined, this loads the first background image you want i.e. 1.jpg. In the above flash button example image 2.jpg replaces the background.

The width, height and margin has been set to fix a NS6 bug.

These functions were create by Made by Martial Boissonneault © 2001 [http://getElementById.com/](http://getElementById.com/). He gives them freely if he’s mentioned with a comment.

Hope this helps

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 2:02pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/4 "2003-01-19T14:02:11Z")

</div>

thanks a lot… exactly what I’m looking for.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 2:51pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/5 "2003-01-19T14:51:31Z")

</div>

Glad to of helped, I wanted to know that same thing the other day. ICQ me if you need any help with it 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 5:42pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/6 "2003-01-19T17:42:33Z")

</div>

Wow man - that’s a great bit of code.

thanks a lot for that!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 6:17pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/7 "2003-01-19T18:17:10Z")

</div>

Or you can try this…

Between your head tags in your HTML file try this…

```php
<SCRIPT LANGUAGE="JavaScript">
<!--
function changeColor(color){
document.bgColor = color;
}
-->
</SCRIPT>

```

Then you can call that in Flash with…

```auto
on (release){
getURL("javascript:changeColor('#E6E6E6')");
}

```

You can change #E6E6E6 to whatever you want.

PS: Java script is supposed to read Javascript (no space in between)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 6:39pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/8 "2003-01-19T18:39:47Z")

</div>

```php
on(release) {
	getURL("javascript: ChangeBgImg('2.jpg')");
} 

```

Yea, make sure that javascript has no spaces in it. Thanks lost. ■■■■ typos.

The JavaScript above has no typos though, just checked through it and and did a quick test again.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 6:40pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/9 "2003-01-19T18:40:41Z")

</div>

Yeah the board adds that space for some reason… I have no clue why.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 6:46pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/10 "2003-01-19T18:46:45Z")

</div>

I just posted the above with the, php tags, which I copied and pasted from the Actions Panel Text editor. The text \<b\>javascript\</b\> was just like that. When I put the copied and pasted code from the Flash ActionScript editor and post it as php here at the forum it splits \<b\>javascript\</b\> into \<b\>java script\</b\>.

This is weird. This definately happen, I just check what I copied and pasted from. Try this your self. Has anyone got any idea how or why this happens? I’ve had this happen before on a previous post. :x

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 6:47pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/11 "2003-01-19T18:47:31Z")

</div>

Refer to my previous post…lol.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 6:48pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/12 "2003-01-19T18:48:48Z")

</div>

How did you know what I was going to post and post before me.

lol

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 6:51pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/13 "2003-01-19T18:51:02Z")

</div>

wow lostinbeta! great code, it’s a “keeper” 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 6:52pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/14 "2003-01-19T18:52:39Z")

</div>

marc: telepath 😉

subquark: thanks 🙂 And I assume your footer never stops “loading” as I am on cable and have just realized that I have never seen it NOT loading…lol.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 7:39pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/15 "2003-01-19T19:39:05Z")

</div>

hahaha, I was thinking the same thing 🙂

Thanks for the code lost - very nice…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 19, 2003, 7:43pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/16 "2003-01-19T19:43:04Z")

</div>

No problem man 🙂 Glad you guys like it. I once created a full out RGB selector for your background. Kinda like the swatch panel in Photoshop.

I deleted it though, it was lame IMO. It really served no purpose for me.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 11:11am UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/17 "2003-01-22T11:11:32Z")

</div>

just to let you know… it works like a charm.

thanks alot !

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 22, 2003, 1:56pm UTC](https://forum.kirupa.com/t/change-body-background-from-within-flash/11313/18 "2003-01-22T13:56:35Z")

</div>

cool :cool:
