自定义组件中的事件问题
我刚刚开始使用自定义组件中的自定义事件。我还不太掌握它的窍门。
我有一个带有按钮的组件。单击时,我想调用主应用程序中的函数。
自定义组件:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您创建了 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.