Hey guys,
This is my first post (probably of many to come).
I am currently making a portfolio in AS3 for myself, and am coding the actionscript for the buttons (of which there are 5), and i was wondering what the most efficient way to do this is?
I could just make an event listener and function for each button, which I can do and works fine, it just doesn’t seem like the “smoothest” way to code it.
So instead I tried a switch statement (below), this works and seems a bit more efficient coding-wise, however I’ve a discovered a bug in that when i click on the same button once it works, if i click it a second time it goes to the next frame in the switch statement, and clicking it a third time brings it back to the correct frame. But clicking ‘home’ should always go to ‘home’ instead of ‘flash’, no matter how many times i click it…
menuMC.homeBTN.addEventListener(MouseEvent.CLICK, changeContent);
menuMC.flashBTN.addEventListener(MouseEvent.CLICK, changeContent);
menuMC.videoBTN.addEventListener(MouseEvent.CLICK, changeContent);
menuMC.threedBTN.addEventListener(MouseEvent.CLICK, changeContent);
menuMC.aboutBTN.addEventListener(MouseEvent.CLICK, changeContent);
menuMC.contactBTN.addEventListener(MouseEvent.CLICK, changeContent);
function changeContent(evt:MouseEvent):void {
var changeCon:String=evt.target.name;
switch (changeCon) {
case “homeBTN” :
contentMC.gotoAndPlay(“home”);
break;
case “flashBTN” :
contentMC.gotoAndPlay(“flash”);
break;
case “videoBTN” :
contentMC.gotoAndPlay(“video”);
break;
case “threedBTN” :
contentMC.gotoAndPlay(“3d”);
break;
case “aboutBTN” :
contentMC.gotoAndPlay(“about”);
break;
case “contactBTN” :
contentMC.gotoAndPlay(“contact”);
break;
default :
trace("content selection failed");
break;
}
}
So what I am asking is, how can this “bug” be avoided, and is there an even better way to code this?<br>