自定义组件中的事件问题

发布于 2024-09-18 09:02:11 字数 811 浏览 6 评论 0原文

我刚刚开始使用自定义组件中的自定义事件。我还不太掌握它的窍门。

我有一个带有按钮的组件。单击时,我想调用主应用程序中的函数。

自定义组件:

<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute"  >


<mx:Metadata>
    [Event(name="goClick", type="mx.events.Event")]
</mx:Metadata>

<mx:Script>
        <![CDATA[

    private function onButtonClickHandler(event:MouseEvent):void {
        dispatchEvent(new Event("goClick"));
    }
        ]]>
</mx:Script>

      <mx:Button id="myGoButton" label="Go"  
          click="onButtonClickHandler(MouseEvent)"  />

</mx:Panel>

主应用程序:

<myFolder:MyComponent
    goClick="MyCoolFunction()">

不幸的是,我做错了。它说事件类型不可用。我需要更改或添加什么?我的猜测是我需要以某种方式声明 goClick?

谢谢你!

-拉克斯米迪

I'm just getting started with custom events in a custom component. And I don't quite have the hang of it, yet.

I've got a component with a button in it. When it's clicked, I want to call a function in the main app.

Custom Component:

<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute"  >


<mx:Metadata>
    [Event(name="goClick", type="mx.events.Event")]
</mx:Metadata>

<mx:Script>
        <![CDATA[

    private function onButtonClickHandler(event:MouseEvent):void {
        dispatchEvent(new Event("goClick"));
    }
        ]]>
</mx:Script>

      <mx:Button id="myGoButton" label="Go"  
          click="onButtonClickHandler(MouseEvent)"  />

</mx:Panel>

Main App:

<myFolder:MyComponent
    goClick="MyCoolFunction()">

Unfortunately, I'm doing something wrong. It says that the Event type is unavailable. What do I need to change or add? My guess is that I need to declare goClick in some way?

Thank you!

-Laxmidi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

巾帼英雄 2024-09-25 09:02:11

除非您创建了 mx.events.Event 这样的类,否则没有此类。将其更改为 flash.events.Event 就可以了。

如果您确实创建了“mx.events.Event”类,请确保您的调度事件是创建自定义类的实例,而不是 flash.events.Event。

No such class as mx.events.Event unless you created one. Change that to flash.events.Event and you'll be good to go.

If you did create an 'mx.events.Event" class, make sure that your dispatch event is create an instance of your custom class and not the flash.events.Event.

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