I’m getting an error whilst trying to add an event listener to a class of a Button on my stage.
1061: Call to a possibly undefined method addEventListener through a reference with static type Class.
On my stage i have a Button with the instance name stopBtn, this is also exported to an actionscript class called classes.stopBtn (stopBtn.as in a folder called ‘classes’). The button is on the first keyframe in the main timeline, in a layer with other buttons on that layer
The error is on line 10 of the stopBtn.as file:
package classes {
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.display.MovieClip;
public class stopBtn extends SimpleButton {
public function stopBtn() {
stopBtn.addEventListener(MouseEvent.CLICK, stopButtonFunction);
}
function stopButtonFunction(event:MouseEvent):void {
MovieClip(root).trackPosition = 0;
MovieClip(root).mySoundChannel.stop();
MovieClip(root).playPause.gotoAndPlay(2);
}
}
}
I have found many threads for the error code 1061 but non of them seem to relate to my problem!
I have tried to ensure all event types are imported by using
Import flash.events.*; but this makes no difference.
You code should be like