mechanicarts
mechanicarts

Reputation: 171

Display array of movieclips and dynamically update them?

So I have this Array, named combo. I want to fill it with movieclips according to the user clicks (if user clicks 1, then add "1" to the Array and display it on an area.

Problem is, I do not know how to do it.

For the record, I have 4 movieclips, fire, wind, earth and spirit. When the user clicks one of them, I want the Array to update. Array's max length is 6 and it is always checked against a "true_combo" Array.

My questions are:

1) How do I remove the oldest item in the Array if the length has reached 6?
2) How do I display the movieclips one next to another (smaller versions of the buttons, not new movieclips), according to Combo?
3) How do I dynamically update the movieclip list on the stage?

This is a stripped version of my current fla https://www.dropbox.com/s/17d9rgclz29ft1u/Untitled-1.fla

This is the code to check the combo against true combo:

function checkthis(e:Event)
{
    if(combo.length == truecombo.length)
    for(var o:int = 0; o < combo.length; o++) 
    {
        if(combo[o] == truecombo[o])
        {
            bravo.play();
        }
    }
}

Upvotes: 0

Views: 240

Answers (1)

Mark Knol
Mark Knol

Reputation: 10163

1
You can use the Array.shift() (remove first item in array) or Array.pop() (remove last item in array)

2 / 3
Use a for-loop and change the position of the items according the array. I assume the items in the array are references to the movieclips, then this would be functions you could use.

function add(clip:DisplayObject)
{
    if (this.combo.length >= 6) 
{
    // remove child and remove it from the list
    removeChild(this.combo.shift());
}
this.combo.push(clip);
this.addChild(clip);

    reorder();
}

function reorder()
{
   for(var i:int = 0; i < combo.length; i++)
   {
       combo[i].x = i * 50;
   }
}

update:
You can download an example of this implementation here (Flash CS6 file) or watch it here


update 2

function checkthis(e:Event)
{
    var isValid:Boolean = true;
    if(combo.length == truecombo.length)
    {
      for(var o:int = 0; o < combo.length; o++) 
      {
        if(combo[o] != truecombo[o])
        { 
            // if one item isnt the same it should fail.
            isValid = false;
        }
      }
    }
    if (isValid)
    {
        bravo.play();
    }
}

Upvotes: 1

Related Questions