Question : Flash AS3. Checking the index value

I feel I am extremely close to a solution with this but its not quite there. I am trying to check if a movie clip (green_mc) is at the top of a stack of movie clips:
When green_mc is the first in the stack the if, else statement is not picking it up
Here is the complete snippet:
Many thanks
Neil
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
var index:int = getChildIndex(green_mc) // get the z-position of green_mc 
var num:int = numChildren -1; // get the amount of children and subtract it by one    
 
greenButton.addEventListener ( MouseEvent.CLICK, clickGreen	 )
function clickGreen( evt ):void {
	
if(index == num){ 
addChild (green_mc)
green_mc.x = 400;
green_mc.alpha = 1
	
}else{
    addChild (green_mc)
	green_mc.x = -70
	var myTween4:Tween = new Tween(green_mc, "alpha", Strong.easeOut, 0, 1, 2, true);
}
}
 
	setChildIndex(green_mc, 7);
	var myTween4:Tween = new Tween(green, "alpha", Strong.easeOut, 0, 1, 2, true);
}
}
Open in New Window Select All

Answer : Flash AS3. Checking the index value

I found the solution to my question (posted bellow). It was a case of including the var elements inside the function to make it all work.
For those who may need to find out the z.index of a child the code bellow works beautifully.
N
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
greenButton.addEventListener ( MouseEvent.CLICK, clickGreen	 )
function clickGreen( evt ):void {
var index:int = getChildIndex(green_mc) // get the z-position of green_mc 
var num:int = numChildren -1; // get the amount of children and subtract it by one  
 
if(index == num){ 
addChild (green_mc)
green_mc.x = 400;
green_mc.alpha = 1
	
}else{
    addChild (green_mc)
	green_mc.x = -70
	var myTween4:Tween = new Tween(green_mc, "alpha", Strong.easeOut, 0, 1, 2, true);
}
}
Open in New Window Select All
Random Solutions  
 
programming4us programming4us