How would I make an image I load using AS3’s loader class into a button with an event handler on it? Below is what I have started. And below that is my error I get when I click the message.
AS:
//call function that starts loading my image
callButtons();
function callButtons():void {
var spanish_url = root_path + "spanish.png";
var spanish_loader = new Loader();
spanish_loader.load (new URLRequest(spanish_url));
//on load complete call the spanishLoaded function
spanish_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, spanishLoaded);
}
//add loaded image to my main_container set x,y and turn it into a button.
function spanishLoaded (e:Event):void {
var my_spanish:Loader = Loader(e.target.loader);
my_spanish.x = 1062;
my_spanish.y = 620;
main_container.addChild(my_spanish);
my_spanish.addEventListener (MouseEvent.CLICK, playSpanish);
}
function playSpanish (){
trace("IN SPANISH");
}
the error I am getting when I click the spanish.png on the stage is: ArgumentError: Error #1063: Argument count mismatch on MyVideoPlayer_CS4_fla::MainTimeline/playSpanish(). Expected 0, got 1.
I NEEDED TO ADDED evt:MouseEvent
In your function
spanishLoadedyou add an event listener:playSpanishfunction will expect a mouse event:You have:
This should be: