I hope this isn’t faux pas, but I’m making the transition from AS2 to AS3 and was wondering if I’m on the right track with this class. One question in particular I have is, I’m storing a reference (I think it’s just a reference and not a copy) of “curTab” in order to keep track of the currently selected tab in this UI navigation. Is this using unnecessary memory and is there a better way to do this?
package cardmaker {
import flash.display.*;
import flash.events.*;
public class Navigation extends MovieClip {
private var navRoot:MovieClip = StaticVars.MovieRoot.nav_mc;
private var curTab:Object;
public function Navigation():void {
var i:int = navRoot.numChildren;trace(i);
while (i--){
var btn:Object = navRoot.getChildAt(i);
btn.addEventListener(MouseEvent.MOUSE_OVER, onNavBtnMouseOver);
btn.addEventListener(MouseEvent.MOUSE_OUT, onNavBtnMouseOut);
btn.addEventListener(MouseEvent.CLICK, onNavBtnClick);
// Focus first tab
if(i==0)
focus_tab(btn);
}
}
private function onNavBtnMouseOver(evt:MouseEvent){
evt.target.buttonMode = true;
evt.target.gotoAndStop('on');
}
private function onNavBtnMouseOut(evt:MouseEvent){
if(curTab != evt.target)
evt.target.gotoAndStop('off');
}
private function onNavBtnClick(evt:MouseEvent){
blur_tabs();
focus_tab(evt.target);
}
public function focus_tab(tab:Object):void {
curTab = tab;
MovieClip(tab).gotoAndStop("on");
}
public function blur_tabs():void {
var i:int = navRoot.numChildren;trace(i);
while (i--){
MovieClip(navRoot.getChildAt(i)).gotoAndStop("off");
}
}
}
}