In this case, Application.application.addEventListener... won't work.
This will, though:
parentApplication.addEventListener("appEvent", appEventHandler);
-Eddie
--- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> But you can dispatch an event from Application and listen for it in
a
> component. Code in the component:
>
> Application.application.addEventListener("EventDispatchecInMainapp",
> listenerInThisComponent);
>
>
>
> Tracy
>
> ________________________________
>
> From: [email protected]
[mailto:[EMAIL PROTECTED] On
> Behalf Of Scott Melby
> Sent: Tuesday, September 30, 2008 8:03 PM
> To: [email protected]
> Subject: Re: [flexcoders] how do I send a custom event from an
> application to a component?
>
>
>
> Rather than sending an event to a component, what you do is declare
a
> public function in your component, then call it from the
application.
>
> so... in myComp
>
> public function someFunction(var param1:type):void
> {
> //do stuff
> }
>
> and out in your main code you need to give your myComp an id...
> id="myComp". Then in your button click handler call
> myComp.someFunction(blah);
>
> hth
> Scott
>
> luvfotography wrote:
>
> Hi, I'm able to send a custom event from a component to an
> application, but how do I send a custom event from the
> application to
> a component?
>
> example code:
> mycomp.mxml:
>
> <?xml version="1.0" encoding="utf- 8"?>
> <!--this is myapp.mxml-- >
> <mx:Application xmlns:mx="http://www.adobe. com/2006/ mxml
> <http://www.adobe.com/2006/mxml> "
> layout="absolute"
> xmlns:comp=" *" xmlns:events= "flash.events. *"
> creationComplete= "init()">
> <mx:Metadata>
> [Event(name= "appEvent" , type="flash. events.Event" )]
> </mx:Metadata>
> <mx:Script>
> <![CDATA[
> import mx.controls. Alert;
>
> private function init():void {
> addEventListener( "compEvent" ,compEventHandle r);
> }
>
> private function compEventHandler( e:Event): void {
> Alert.show(" event received from component");
> }
>
> private function sendEvent(e: Event):void {
> var myappEvent:Event = new Event("appEvent" , true,true);
> dispatchEvent( myappEvent) ;
> }
> ]]>
> </mx:Script>
> <comp:mycomp />
> <mx:Button label="send event to component" id="appbutton"
> click="sendEvent( event)" />
> </mx:Application>
>
> component:
> <?xml version="1.0" encoding="utf- 8"?>
> <!--this is mycomp.mxml- ->
> <mx:Canvas xmlns:mx="http://www.adobe. com/2006/ mxml
> <http://www.adobe.com/2006/mxml> " width="400"
> height="300" creationComplete= "compInit( )">
>
> <mx:Metadata>
> [Event(name= "compEvent" , type="flash. events.Event" )]
> </mx:Metadata>
>
> <mx:Script >
> <![CDATA[
> import mx.controls. Alert;
> private function compInit():void {
> addEventListener( "appEvent" ,appEventHandler );
> }
> private function appEventHandler( e:Event): void {
> Alert.show(" event received from application" );
> }
> private function sendEvent(e: Event):void {
> var mycompEvent: Event = new Event("compEvent" , true,true);
> dispatchEvent( mycompEvent) ;
> }
> ]]>
> </mx:Script>
> <mx:Button id="mybutton" x="200" label="send event to
> application"
> click="sendEvent( event)" />
> </mx:Canvas>
>
> thanks!
>