2012-04-04 45 views
0

我想創建一個DataGrid組件,並希望它在創建數據網格時將事件分派給主應用程序。但是,我得到的錯誤說無法在Flash Builder中的自定義組件中聲明自定義事件

"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> 

不知道如何解決這個問題?我感謝任何幫助。非常感謝。

回答

0

一對夫婦的事情,你可以改變/考慮:

1)派遣您的自定義事件,您需要使用Event類,或創建一個擴展Event自定義類,所以你可以派遣一個真正的Event對象。在你的情況下,W /只是一個自定義事件類型,使用Event類是這樣的:

dispatchEvent(new Event("dataGridComp"));

2)您所使用的creationComplete事件,將組件添加到舞臺前被分派。由不在顯示列表中的事件派發的事件不一定會被主應用程序聽到。