如何使用AS3的加载器类将图像加载到带有事件处理程序的按钮上?以下是我的开始。下面是我点击邮件时收到的错误。
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");
}
当我点击舞台上的spanish.png时,我得到的错误是:ArgumentError: Error #1063: Argument count mismatch on MyVideoPlayer_CS4_fla::MainTimeline/playSpanish(). Expected 0, got 1.
我需要添加evt:MouseEvent
答案 0 :(得分:1)
在您的函数spanishLoaded
中添加一个事件监听器:
my_spanish.addEventListener (MouseEvent.CLICK, playSpanish);
playSpanish
函数会发生鼠标事件:
你有:
function playSpanish ()
这应该是:
function playSpanish (event:MouseEvent)