This code is to turn an MC into a button with actionscript. But I have about 10 buttons and it seems ridiculous to use this code 10 times. Can I declare it as a function and pass it the names I want?
[SIZE=4][COLOR=Red]Original Code[/COLOR][/SIZE]
_root.mainButton.onRollOver = function() {
if(_root.currentlyLoaded != “main”){
_root.mainButton.gotoAndPlay(“over”); } }
_root.mainButton.onRollOut = function() {
if(_root.currentlyLoaded != “main”){
_root.mainButton.gotoAndPlay(“getBack”); } }
_root.mainButton.onRelease = function() {
if(_root.currentlyLoaded != “main”){
_root.mainButton.gotoAndPlay(“down”);
_root.currentlyLoaded = “main”;
_root.clearButton();
} }
I understand that the following code is not correct as far as syntax goes but that is what I want to achieve. Does anyone know how to do it?
[SIZE=4][COLOR=Red]Wanted code
[/COLOR][/SIZE]
function buttonCode() {
_root.enterHereButtontton.onRollOver = function() {
if(_root.currentlyLoaded != “enterHere”){
_root.enterHereButtontton.gotoAndPlay(“over”); } }
_root.enterHereButtontton.onRollOut = function() {
if(_root.currentlyLoaded != “enterHere”){
_root.enterHereButtontton.gotoAndPlay(“getBack”); } }
_root.enterHereButtontton.onRelease = function() {
if(_root.currentlyLoaded != “enterHere”){
_root.enterHereButtontton.gotoAndPlay(“down”);
_root.currentlyLoaded = “enterHere”;
_root.clearButton();
} }
}
buttonCode(enterHere = main);
buttonCode(enterHere = bio);
buttonCode(enterHere = contact);
// etc…