Archive for September, 2009
Mixing getChildByName and gotoAndStop
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);
}
}
Dynamic text inside buttons and masks
When working in flash and programing as3, you have to think of the whole project from start to finish befor you write the first line of code or draw the first pixel in your timeline!
I’m the sort of guys who start a project by spliting it to parts/steps, but I found this methode not working good, lets examin this scenario toghter;
- in the beging of the project, the client didn’t tell if the site will be multilangual, so I created buttons on the timeline and animated the frames using masks.
- when the project is finished and working, the client come again and ask me to make the project multilangual, that means the texts inside buttons should be dynamic!
i taught it’s easy, but I was wrong, I discouvered that dynamic text inside buttons to be able to work, ther should be ;
* textfields should always be in the first keyframe, also the button containg this textfield or parent buttons should be in the first frame
* ther should be no timeline masks over the button, if you want masking create them dynamicly
that’s a big probleme since i created many buttons on the timeline, so i have to redo the whol stuff!!
AS3 is a language that takes to to the next level in flash authoring/programing; before as3, we really don’t care about creating buttons or creating movieclips and turning them to buttons, but now, you should think a lot befor going to the next step.