Events Can';t在Flash Builder的自定义组件中声明自定义事件

Events Can';t在Flash Builder的自定义组件中声明自定义事件,events,flex4,flash-builder,Events,Flex4,Flash Builder,我正在尝试创建一个datagrid组件,并希望它在创建datagrid时向主应用程序发送一个事件。然而,我在说 "Type was not found or was not a compile-time constant:dataGridComp" "Call to a posibly undefined methoud dataGridComp" 我的组件 <?xml version="1.0" encoding="utf-8"?> <s:Group xmlns:fx=

我正在尝试创建一个datagrid组件,并希望它在创建datagrid时向主应用程序发送一个事件。然而,我在说

"Type was not found or was not a compile-time constant:dataGridComp"

"Call to a posibly undefined methoud dataGridComp"
我的组件

<?xml version="1.0" encoding="utf-8"?>

<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"

         xmlns:s="library://ns.adobe.com/flex/spark"

         xmlns:mx="library://ns.adobe.com/flex/mx">



    <fx:Metadata>   //declare my event

        [Event(name="dataGridComp", type="flash.events.Event")]

    </fx:Metadata>



    <fx:Script>

        <![CDATA[

            import mx.events.FlexEvent;



            protected function dataGrid_creationCompleteHandler(event:FlexEvent):void

            {

                // TODO Auto-generated method stub

                 var e:dataGridComp = new dataGridComp("dataGridComp"); //problem here

                dispatchEvent(e);   //want to dispatch my event object when the datagrid is created

            }



        ]]>

    </fx:Script>



    <s:DataGrid id="dataGrid" editable="true" x="51" y="34" width="734" height="153"

                creationComplete="dataGrid_creationCompleteHandler(event)" requestedRowCount="4">

      ........

      ..........

    </s:DataGrid>

</s:Group>

//宣布我的活动
[事件(name=“dataGridComp”,type=“flash.events.Event”)]
........
..........

你知道怎么解决这个问题吗?谢谢你的帮助。非常感谢

您可以改变/考虑以下几点:

1) 要分派自定义事件,需要使用
事件
类,或创建扩展
事件
的自定义类,以便分派真实的
事件
对象。在您的情况下,仅使用自定义事件类型,使用
event
类,如下所示:

dispatchEvent(新事件(“dataGridComp”)

2) 您正在使用的creationComplete事件在将组件添加到阶段之前被调度。由不在显示列表中的内容发送的事件不一定会被主应用程序听到