使用加载程序添加图像并使图像成为带有事件处理程序的按钮
如何使用 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: MyVideoPlayer_CS4_fla::MainTimeline/playSpanish() 上的参数计数不匹配。预期为 0,结果为 1。
我需要添加 evt:MouseEvent
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的函数
spanishLoaded
中,您添加一个事件侦听器:playSpanish
函数将需要一个鼠标事件:您有:
这应该是:
In your function
spanishLoaded
you add an event listener:playSpanish
function will expect a mouse event:You have:
This should be: