Such a stupid question.  I am trying to assign a listener to a custom 
component.  It broadcasts a simple event.  Here is a dumbed-down version of the 
code I am using:

<mx:Application applicationComplete="init()" 
xmlns:mx="http://www.adobe.com/2006/mxml";
xmlns:c="com.project.components.*">
        <mx:Script>
        <![CDATA[
                private function init():void
                {
                        myComponent.addEventListner("myEvent", onMyEvent);      
                }

                private function onMyEvent():void
                {
                        trace("onMyEvent heard.")
                }
        ]]>
        </mx:Script>
        <c:MyComponent id="myComponent"/>
</mx:Application>

<!--Here is a simplified version of the component: -->
<!--com/project/components/MyComponent.mxml: -->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"; >
        <mx:Script>
        <![CDATA[
                import flash.events.EventDispatcher;
                import flash.events.Event;

                private function broadcastClicked():void
                {
                        dispatchEvent(new Event("myEvent"))
                }
        ]]>
        </mx:Script>
        <mx:Checkbox click="broadcastClicked()"/>
</mx:Canvas>

However, I get a runtime error for the init() event that myComponent is null.  
I would have thought that calling it on applicationComplete would ensure that 
the instance of my component was there.  Why not and how instead do I add the 
listener for it?  Thankya
 

Jason Merrill 
Bank of America 
Global Technology & Operations & Global Risk L&LD 
eTools & Multimedia 

Join the Bank of America Flash Platform Developer Community  
<blocked::http://sharepoint.bankofamerica.com/sites/tlc/flash/default.aspx> 

Are you a Bank of America associate interested in innovative learning ideas and 
technologies?
Check out our internal  GT&O Innovative Learning Blog 
<blocked::http://sharepoint.bankofamerica.com/sites/ddc/rd/blog/default.aspx>  
& subscribe 
<blocked::http://sharepoint.bankofamerica.com/sites/ddc/rd/blog/_layouts/SubNew.aspx?List=\{41BD3FC9-BB07-4763-B3AB-A6C7C99C5B8D\}&Source=http://sharepoint.bankofamerica.com/sites/ddc/rd/blog/Lists/Posts/Archive.aspx>
 . 


Reply via email to