在 Actionscript 中实现时,简单自定义事件发生 Flex 错误(但不是在 MXML 中)

发布于 2024-09-26 01:25:31 字数 2330 浏览 0 评论 0原文

我正在尝试学习如何在 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 技术交流群。

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

发布评论

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

评论(1

独﹏钓一江月 2024-10-03 01:25:31

您的 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.

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