change background color with as3

Hi experts,
I need something either a movie, button, or graphic to change color when I click it (toggle function). I want to create 10 squares and being able to click on anyone, and change the color from red to green and viceversa. If possible enter information when its clicked.
I am using AS3 and Flash 9

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

var total:uint = 10;
var maxWidth:uint = 40;
var maxHeight:uint = 40;
var gap:uint = 10;

for(var i:uint = 0; i < total; i++){
	var rect:Sprite = new Sprite();
	rect.x = i * (maxWidth + gap);
	rect.addEventListener(MouseEvent.CLICK, changeColor);
	drawRect(rect, 0x000000);

function changeColor(event:MouseEvent):void{
	drawRect(event.currentTarget as Sprite, 0xFF0000);

function drawRect(rect:Sprite, color:Number):void{
	var g:Graphics =;
	g.lineStyle(1, 0x000000, 1);
	g.beginFill(color, 1);
	g.drawRect(0, 0, maxWidth, maxHeight);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I forgot to call g.clear() before lineStyle
if you want to change the color of an existing object and not necessarily draw one as dgofman's example, you can use colorTransform.
heres a very good explanation with example.
crescueAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.