Sometimes I want to reference objects by thier instance names, and want to access some frames inside this objects (Movieclips), her’s how you mix the two;
// button animator
function animate_this(brother:SimpleButton) {
// add event listners to this button
brother.addEventListener(MouseEvent.MOUSE_OVER, animate_mc_over);
brother.addEventListener(MouseEvent.MOUSE_OUT, animate_mc_out);
brother.addEventListener(MouseEvent.MOUSE_DOWN, animate_mc_down);
brother.addEventListener(MouseEvent.MOUSE_UP, animate_mc_out);
var brother_name:String=brother.name;
var brother_name_regx:RegExp=/btn_/g;
var target_name:String=brother_name.replace(brother_name_regx,"mc_");
// animate the coresponding clip
function animate_mc_out(event:MouseEvent):void {
MovieClip(brother.parent.getChildByName(target_name)).gotoAndStop(1);
}
function animate_mc_over(event:MouseEvent):void {
MovieClip(brother.parent.getChildByName(target_name)).gotoAndStop(2);
}
function animate_mc_down(event:MouseEvent):void {
MovieClip(brother.parent.getChildByName(target_name)).gotoAndStop(3);
}
}