PDA

View Full Version : Arrays w/ Nested MC's and Removal


Navy_Spitfire
12-20-2010, 02:32 AM
I have a movieclip (ground) with several nested movieclips (g1, g2, g3, etc..). I'm trying to make it so that when the player touches the movieclip, depending on what nested MC they are on, it gets removed from the stage until everything is gone.

Now, rather then make 10 different functions for each nested movieclip to test if it's being touched individually (and take appropriate action), can I put the nested movieclips into an array and make one function that checks which nested mc is being touched and then removes it? If so, how would I begin to do so?

Navy_Spitfire
12-20-2010, 02:53 PM
For example this is what I am thinking it would look like:

public var allSplitGround:Array = [splitGround.i1,splitGround.i2,splitGround.i3,split Ground.i4,splitGround.i5,splitGround.i6,splitGroun d.i7];


public function hitting(event:Event):void
{
for(var i:uint = 0; i <= allSplitGround.length; i++)
{
if(player.hitTestObject(allSplitGround[i])) //splitGround.i1
{
//do something
}

raikado
12-22-2010, 02:07 PM
public var allSplitGround:Array = [splitGround.i1,splitGround.i2,splitGround.i3,split Ground.i4,splitGround.i5,splitGround.i6,splitGroun d.i7];


public function hitting(event:Event):void
{
for each(var i:MovieClip in allSplitGround)
{
if(player.hitTestObject(i)) //splitGround.i1
{
//do something
index:int = allSplitGround.indexOf(i)
allSplitGround.splice(i, 1)
}

I think this should it.

Reedited the code, it should work now:p

Navy_Spitfire
12-22-2010, 04:28 PM
Thanks, I'll try it out next time.