For Loop + Custom Function + Dynamic Var

(download)

 
cat.addEventListener(MouseEvent.CLICK, clickCat); 
cat.buttonMode = true; 
 
function clickCat(evt:MouseEvent){ 
	buildNav(SubBox, 5, 50); 
} 
 
function buildNav(box:Class, num:Number, pos:Number) { 
 
	for (var i:int = 0; i<num; i++) { 		var nav:MovieClip = new box; 		nav.x = pos + (nav.width + 10) * i; 		nav.y = pos; 		addChild(nav); 		nav.addEventListener(MouseEvent.CLICK, showSub); 		nav.buttonMode=true; 	} } var subNav:MovieClip = new SubBox; function showSub(evt:MouseEvent) { 	subNav.x = evt.currentTarget.x; 	subNav.y = evt.currentTarget.y + evt.currentTarget.height + 5; 	addChild(subNav); } 
>