smansakra
07-12-2011, 11:38 AM
i have code below
btn_home.addEventListener(MouseEvent.CLICK, goto_home);
btn_contact.addEventListener(MouseEvent.CLICK, goto_contact);
btn_about.addEventListener(MouseEvent.CLICK, goto_about);
function goto_home(event:MouseEvent):void{
this.gotoAndStop(2);
}
function goto_contact(event:MouseEvent):void{
this.gotoAndStop(3);
}
function goto_about(event:MouseEvent):void{
this.gotoAndStop(4);
}
What i want to know is how to simplify above code like below
var myframe:int;
btn_home.addEventListener(MouseEvent.CLICK, gotoframe(2));
btn_contact.addEventListener(MouseEvent.CLICK, gotoframe(3));
btn_about.addEventListener(MouseEvent.CLICK, gotoframe(4));
function gotoframe(myframe):void{
this.object_okie.gotoAndStop(myframe);
}
UNFORTUNATELY that code doesn't work anymore.
can somebody help me?
IT WILL BE SO HARD FOR ME IF I MAKE 10 buttons, thanks
btn_home.addEventListener(MouseEvent.CLICK, goto_home);
btn_contact.addEventListener(MouseEvent.CLICK, goto_contact);
btn_about.addEventListener(MouseEvent.CLICK, goto_about);
function goto_home(event:MouseEvent):void{
this.gotoAndStop(2);
}
function goto_contact(event:MouseEvent):void{
this.gotoAndStop(3);
}
function goto_about(event:MouseEvent):void{
this.gotoAndStop(4);
}
What i want to know is how to simplify above code like below
var myframe:int;
btn_home.addEventListener(MouseEvent.CLICK, gotoframe(2));
btn_contact.addEventListener(MouseEvent.CLICK, gotoframe(3));
btn_about.addEventListener(MouseEvent.CLICK, gotoframe(4));
function gotoframe(myframe):void{
this.object_okie.gotoAndStop(myframe);
}
UNFORTUNATELY that code doesn't work anymore.
can somebody help me?
IT WILL BE SO HARD FOR ME IF I MAKE 10 buttons, thanks