0
votes

I have added specific MovieClips from my stage to an array using;

var ItemArray:Array = new Array();


function loadItems():Array //loads/returns items into an array
{

    for(var i:int = 0; i<numChildren; i++) //loop number of children on stage
    {

        if(getChildAt(i).name.substr(0,4) == "item") //if child is an item

            {
            ItemArray[getChildAt(i).name.substr(5)] = getChildAt(i); //Add to Items:array as instance numbered
            }
    }

return ItemArray;    
}

Then when I hit a button it fires this function:

function playNextItem():void
{
        if(CurrentItem < ItemArray.length)
    {
        play.ItemArray[CurrentItem];
        CurrentItem++;
    }

}

Which plays the first moviclip of the array and adds +1 to a counter so the next time I hit the button it plays the next Movieclip in the array.

But I get this error:

/Users/nathanrichman/Desktop/Presso Idea/Presentation.as, Line 50, Column 7 1119: Access of possibly undefined property ItemArray through a reference with static type Function.

I've looked around and it seems like i'm creating the array all wrong and it can't read it as a Movieclip.

How do I add movieclips to an array and play.array[number]?

1

1 Answers

0
votes

On one hand, play() is a movieClip method, not the opposite!

The correct code isn't:

play.mc;

but:

mc.play();

On the other hand, you can do it simply like that:

var ItemArray:Array = [];

for (var i:int = 0; i < numChildren; i++)
{
    ItemArray[i] = MovieClip(getChildAt(i));
}

var CurrentItem:int = 0;

function playNextItem(e:MouseEvent):void 
{ 
    ItemArray[CurrentItem].play();
    CurrentItem++;
}
addEventListener(MouseEvent.MOUSE_UP, playNextItem);