Can't declare custom event in custom component in Flash Builder

Go To


I am trying to create a datagrid component and want it to dispatch an event to the main application when datagrid is created. However, I got errors saying

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

"Call to a posibly undefined methoud dataGridComp"

my component

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

<s:Group xmlns:fx=""



    <fx:Metadata>   //declare my event

        [Event(name="dataGridComp", type="")]





            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




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

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





Any idea how to solve this? I appreciate any help. Thanks a lot.

2012-04-04 00:03
by Rouge


A couple of things that you can change/consider:

1) To dispatch your custom event, you need to use the Event class, or create a custom class that extends Event, so you can dispatch a real Event object. In your case, w/ just a custom event type, use the Event class like this:

dispatchEvent( new Event("dataGridComp") );

2) The creationComplete event you are using, is dispatched before the component is added to the stage. Events dispatched by something that is not on the display list won't necessarily be heard by your main application.

2012-04-04 06:47
by Sunil D.