# \[FMX04\] Automating color object variables for multi-level game

**URL:** https://forum.kirupa.com/t/fmx04-automating-color-object-variables-for-multi-level-game/252459
**Category:** flash
**Created:** [February 20, 2008, 11:51am UTC](https://forum.kirupa.com/t/fmx04-automating-color-object-variables-for-multi-level-game/252459 "2008-02-20T11:51:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![macgregor](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@macgregor](https://forum.kirupa.com/u/macgregor)
#### Post date: [February 20, 2008, 11:51am UTC](https://forum.kirupa.com/t/fmx04-automating-color-object-variables-for-multi-level-game/252459/1 "2008-02-20T11:51:24Z")

</div>

Hi, I’m trying to create a simple multi-level game with actionscript 2 (MX2004).  
In the game I have many box movie-clips which must be moved by the player to “Home”  
positions, when they are over a Home they change colour.  
I have achieved the colour change with setTransform (not setRGB as I want transparency in  
order that the boxes retain their detail)  
This is a snippet of the code for a level with 4 boxes in it:  
var numBoxes:Number = 4;  
var box\_color1:Color = new Color(box1);  
var box\_color2:Color = new Color(box2);  
var box\_color3:Color = new Color(box3);  
var box\_color4:Color = new Color(box4);  
[COLOR=seagreen]// Set the values for myColorTransform[/COLOR]  
var BlueT:Object = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:250, aa:100, ab:70};  
var OriginalT:Object = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100, ab:255};

[COLOR=seagreen]//Check whether over any ‘HOME’ and then set Home colour[/COLOR]  
for(i=1; i\<=numBoxes; i++)  
{  
if (this[“BoxHome” + i].hitTest(this[“box” + t])) [COLOR=seagreen]// ‘t’ is the box we’re pushing[/COLOR]  
{this[“box\_color” +t].setTransform(BlueT); home\_array[t] = 1; break;}  
else {this[“box\_color” +t].setTransform(OriginalT); home\_array[t] = 0;}  
}  
So the Boxes start off one colour (green) and when they are pushed over a “Home” area they  
change to a blue colour.  
This ALL works well - don’t know if it is the most efficient approach.  
My problem is each game levels has differing numbers of boxes, so for a level with 32  
boxes I would have to have 32 lines of  
var box\_color1:Color = new Color(box1);  
var box\_color2:Color = new Color(box2);  
.  
.  
.  
var box\_color32:Color = new Color(box32);

I have two problems with this - obviously it is inefficient, but more importantly I cannot,with this method, use the same code for all levels, with merely a change of  
numBoxes (the number of boxes on the level).  
I was hoping to do something like:  
var numBoxes:Number = 32;  
for(i=1;i\<=numBoxes;i++)  
{  
var [“box\_color” + i]:Color = new Color(boxi);  
}  
Which doesn’t work - the Left Hand Side is faulty.  
I’ve googled endlessly for days without success,  
I hope you can help.
