# HTML Background color Change via AS 2.0

**URL:** <https://forum.kirupa.com/t/html-background-color-change-via-as-2-0/263003>\
**Category:** flash\
**Created:** [June 11, 2008, 8:00pm UTC](https://forum.kirupa.com/t/html-background-color-change-via-as-2-0/263003 "2008-06-11T20:00:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wahiche](https://avatars.discourse-cdn.com/v4/letter/w/da6949/32.png) [@wahiche](https://forum.kirupa.com/u/wahiche)\
**Post date:** [June 11, 2008, 8:00pm UTC](https://forum.kirupa.com/t/html-background-color-change-via-as-2-0/263003/1 "2008-06-11T20:00:19Z")

</div>

OK I have been looking for a solution for this problem of changing my background color of my HTML page via AS 2.0 (but using JavaScript). I came across many examples but all of them work in versions of Flash player 6 or lower. I am wondering if anyone knows how to make it work in Flash 8 or 9 and for AS2.0.

Here is a link to a site that has a great working copy with the wrong flash player version and using AS 1.0.

[http://tutorials.flashvacuum.com/index.php?show=Change\_Background\_Color](http://tutorials.flashvacuum.com/index.php?show=Change_Background_Color)

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 12, 2008, 12:51am UTC](https://forum.kirupa.com/t/html-background-color-change-via-as-2-0/263003/2 "2008-06-12T00:51:19Z")

</div>

Add the following script to your HTML page:

```auto
<script type="text/javascript">
function changeBgColor(newBgColor) {
      if (window.document && window.document.bgColor) {
          document.bgColor = newBgColor;
      }
}
</script>

```

Now add this script (and the appropriate buttons) to your FLA:

```auto
import flash.external.ExternalInterface;
function callJavascript(newBgColor):Void {
	// call external function ("function_name", parameter to pass to function_name)
	ExternalInterface.call("changeBgColor", newBgColor);
}
my_btn1.onRelease = function() {
	// change background to black
	callJavascript("#000000");
};
my_btn2.onRelease = function() {
	// change background to red
	callJavascript("#FF0000");
};

```

---

<div class="post-metadata">

**Author:** ![wahiche](https://avatars.discourse-cdn.com/v4/letter/w/da6949/32.png) [@wahiche](https://forum.kirupa.com/u/wahiche)\
**Post date:** [June 12, 2008, 4:20pm UTC](https://forum.kirupa.com/t/html-background-color-change-via-as-2-0/263003/3 "2008-06-12T16:20:56Z")

</div>

Thanks for this. But for some reason it does not work. Could you possible create the fla and html page and show me what I am doing wrong, and why it wont work.

Ok I found 1 thing wrong with this solution already. It is not for AS2.0 it is for AS1.0. I also have tried to use the getURL() method but that does not work either.

So if anyone knows how I can get this to work with AS2.0 and Flash 8 or 9. Please let me know.

Thanks

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 12, 2008, 7:20pm UTC](https://forum.kirupa.com/t/html-background-color-change-via-as-2-0/263003/4 "2008-06-12T19:20:43Z")

</div>

It works. And it’s AS2.0

---

<div class="post-metadata">

**Author:** ![wahiche](https://avatars.discourse-cdn.com/v4/letter/w/da6949/32.png) [@wahiche](https://forum.kirupa.com/u/wahiche)\
**Post date:** [June 12, 2008, 7:55pm UTC](https://forum.kirupa.com/t/html-background-color-change-via-as-2-0/263003/5 "2008-06-12T19:55:14Z")

</div>

I am not saying that it won’t work but I wanted to send you the files I have created and maybe you can tell me what I am doing incorrectly.

> [@glosrfc;2341671](#):
>
> It works. And it’s AS2.0

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 12, 2008, 8:33pm UTC](https://forum.kirupa.com/t/html-background-color-change-via-as-2-0/263003/6 "2008-06-12T20:33:15Z")

</div>

Not in CS3 format you won’t. These are in F8

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 13, 2008, 9:11pm UTC](https://forum.kirupa.com/t/html-background-color-change-via-as-2-0/263003/7 "2008-06-13T21:11:19Z")

</div>

That’s perfect…works like a dream…just what I was looking for…thanks!

---

<div class="post-metadata">

**Author:** ![wahiche](https://avatars.discourse-cdn.com/v4/letter/w/da6949/32.png) [@wahiche](https://forum.kirupa.com/u/wahiche)\
**Post date:** [June 13, 2008, 9:30pm UTC](https://forum.kirupa.com/t/html-background-color-change-via-as-2-0/263003/8 "2008-06-13T21:30:03Z")

</div>

Ok this made no sense. But I still cannot get it to work. So in the next couple of days I am going to send you my fla that I am using and teh HTML page. maybe you can let me know why it is still not working.

> [@glosrfc;2342426](#):
>
> That’s perfect…works like a dream…just what I was looking for…thanks!
