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.