使用加载程序添加图像并使图像成为带有事件处理程序的按钮

发布于 2024-12-12 02:56:15 字数 1106 浏览 0 评论 0原文

如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴我老 2024-12-19 02:56:15

在您的函数 spanishLoaded 中,您添加一个事件侦听器:

my_spanish.addEventListener (MouseEvent.CLICK, playSpanish);

playSpanish 函数将需要一个鼠标事件:

您有:

function playSpanish ()

这应该是:

function playSpanish (event:MouseEvent)

In your function spanishLoaded you add an event listener:

my_spanish.addEventListener (MouseEvent.CLICK, playSpanish);

playSpanish function will expect a mouse event:

You have:

function playSpanish ()

This should be:

function playSpanish (event:MouseEvent)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文