在 Actionscript 中实现时,简单自定义事件发生 Flex 错误(但不是在 MXML 中)
我正在尝试学习如何在 Flex 中使用自定义事件。
我正在关注 Oliver Merk 的教程:
那么该自定义事件就会起作用。但是,如果我使用 ActionScript,则会收到错误 1119:通过静态类型 Class 的引用访问可能未定义的属性 ADD_PRODUCT。
我的活动: 在 events 子目录中,我有:
package events {
import flash.events.Event;
public class AddProductEvent extends Event {
public var productName:String;
public function AddProductEvent( type:String, productName:String ) {
super( type );
this.productName = productName;
}
override public function clone():Event {
return new AddProductEvent( type, productName );
}
}
}
在组件中,我有一个 radioButtonGroup
<mx:RadioButtonGroup id="choicesRadioButtonGroup" itemClick="onButtonClick()"/>
private function onButtonClick():void {
var myEventObj:Event = new AddProductEvent("addProduct", "Flex T-shirt");
dispatchEvent(myEventObj);
}
这是组件中的元数据和导入语句:
<mx:Metadata>
[Event (name="addProduct", type="events.AddProductEvent")]
</mx:Metadata>
import events.AddProductEvent;
在主应用程序中,我有:
import events.AddProductEvent;
private function onAddProduct( event:AddProductEvent ):void {
mx.controls.Alert.show('Attached data was ' + event.productName);
}
如果我在主应用程序中实现该组件像这样的应用程序:
<visualcomponent:PopWindow addProduct="onAddProduct(event)" />
然后一切正常。
如果我像这样在 actionscript 的主应用程序中实现该组件,则会收到错误:
public function clickHandler2(event:MouseEvent):void {
if(event.currentTarget.selected){popWindow = new PopWindow;
queryBuilder(event.currentTarget);
PopUpManager.addPopUp(popWindow, my_view, false);
PopUpManager.centerPopUp(popWindow);
popWindow.addEventListener(AddProductEvent.ADD_PRODUCT, onAddProduct);}
}
我在 addEventListener 行收到错误。我做错了什么?有什么建议吗?
谢谢。
-拉克斯米迪
I'm trying to learn how to use custom events in Flex.
I'm following Oliver Merk's tutorial found here: blog
The custom event works if I implement it using MXML in the main app. But, if I use actionscript, then I get error 1119: Access of possibly undefined property ADD_PRODUCT through a reference with static type Class.
My Event:
In the events subdirectory, I've got:
package events {
import flash.events.Event;
public class AddProductEvent extends Event {
public var productName:String;
public function AddProductEvent( type:String, productName:String ) {
super( type );
this.productName = productName;
}
override public function clone():Event {
return new AddProductEvent( type, productName );
}
}
}
In the component, I've got a radioButtonGroup
<mx:RadioButtonGroup id="choicesRadioButtonGroup" itemClick="onButtonClick()"/>
private function onButtonClick():void {
var myEventObj:Event = new AddProductEvent("addProduct", "Flex T-shirt");
dispatchEvent(myEventObj);
}
This is the metadata in the component and the import statement:
<mx:Metadata>
[Event (name="addProduct", type="events.AddProductEvent")]
</mx:Metadata>
import events.AddProductEvent;
In the main app, I've got:
import events.AddProductEvent;
private function onAddProduct( event:AddProductEvent ):void {
mx.controls.Alert.show('Attached data was ' + event.productName);
}
If I implement the component in the main app like this:
<visualcomponent:PopWindow addProduct="onAddProduct(event)" />
then everything works.
If I implement the component in the main app in actionscript like this, then I get an error:
public function clickHandler2(event:MouseEvent):void {
if(event.currentTarget.selected){popWindow = new PopWindow;
queryBuilder(event.currentTarget);
PopUpManager.addPopUp(popWindow, my_view, false);
PopUpManager.centerPopUp(popWindow);
popWindow.addEventListener(AddProductEvent.ADD_PRODUCT, onAddProduct);}
}
I get the error on the addEventListener line. What am I doing wrong? Any advice?
Thank you.
-Laxmidi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 AddProductEvent 类似乎没有公开名为 ADD_PRODUCT 的公共静态字符串,该字符串的值为“addProduct”,这正是您想要做的。
Your AddProductEvent class doesn't seem to expose a public static string called ADD_PRODUCT which has the value "addProduct" which is what it looks like you are trying to do.