Note this has to be done in ActionScript 2 due to my audience player restricted to flash player 8.
I'm trying to build a simple class that extends the base Movieclip class. I'm then applying this class to a movieclip in the library using the properties panel and giving it the class name in there. That much is working fine, and I'm able to use my class and methods etc. on that object after I've attached the movieclip tot he stage using attachMovie. What I can't seem to get to work is the button that I have within the movieclip. Originally I had a button set up within the library movieclip, however I can't seem to target that within my class. What I would like to do is simply set up a simple getURL type of thing within the button, but it doesn't seem to work.
I tried just assigning the onMouseDown handler within the class rather than a button, and that did work, but happened wherever I clicked on the stage rather than just over the graphic area. This had the effect of triggering all the other handlers on any other instances of the class that I had on the stage, so they all fire off at once. However, using onRollOver and onRollOut did work as I expected.
I've also tried setting up another button in the library and using this.attachMovie with my class to attach it, but I still can't seem to get a handle for it.
I've created a very simple test script to try and illustrate what I'm trying to do:-
class Test extends MovieClip {
public function Test() {
// constructor code
this.attachMovie("theButton" , "myButton" , _root.getNextHighestDepth() )
this.myButton.onMouseDown = clickMe;
this._x = Math.random() * 800;
this._y = Math.random() * 400;
}
public function clickMe() {
trace("I have been clicked"+this._name);
}
}
So, the question is, how do I attach (or have present in the movieclip) a button, that I can provide an onMouseDown or onMouseUp type handler for that button that will only work if I click on the actual button? What am I doing wrong here ... I've tried loads of different ideas, but nothing seems to be working. Remember it's AS2 not AS3. Thanks.
this.myButton.onRelease = clickMe;
? and you don't have any click events on instances ofTest
do you? (side note: use this.getNextHighestDepth(), not _root, get the next depth of what you're attaching to) – zamnuts