PDA

View Full Version : Adding methods to library buttons


DancingSamurai
06-27-2003, 04:33 PM
Hi, I'm trying to find an elegant way to attach the same onRelease method to every instance of a button symbol in my Flash MX library.

So I've created the library symbol, myButton, and clicked "Export for ActionScript". Not too sure what "Export in first frame does" but left in at the default (on). I placed a bunch of buttons where I wanted them.

Then I put this code in the buttons' parent (it's residing in a movie clip):


#initclip
function myButton(){};
myButton.prototype = new Button();
myButton.prototype.onRelease = function(){
//Code here
trace("myButton pushed!");
};

Object.registerClass("myButton", myButton);
#endinitclip


... which didn't work.

I solved the problem by nesting the button inside a movie clip and attaching actionscript to the button instance inside myButton_wrapper library symbol... but is there a more elegant way to do it?

sonic_2k_uk
06-28-2003, 01:58 AM
hi... you could attach a function to each of the buttons telling it to call another function... eg

insert this on each button


on (release) {
release();
}


and this in a frame on the stage


function release() {
gotoAndPlay(frame);
}


hope this helps!