Another alternative would be something like this.,...
1. Add Metadata tag in your component with the name of your event.
      <mx:Metadata>
            [Event(name="login", type="flash.events.Event")]
      </mx:Metadata>
2. Catch that event in your component
        <Login x="333" y="56"  login="handleTestEvent(event)"/>
3. Add AS to handle the event.

   public function handleTestEvent(eventObj:Event):void {

            mx.controls.Alert.show(eventObj.currentTarget,'Test');

                  }


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
layout="absolute" applicationComplete="onComplete()">
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;

            [Bindable]
            public var status:String = "";

            public function onComplete():void {
                status += "Add Event Listener...\n";

Application.application.addEventListener("test",onTestEvent);
            }

            public function onTestEvent(event:Event):void {
                Application.application.status += "Test Event
occured...\n";
            }

            public function dispatchTextEvent():void {
                var event:Event = new Event("test");
                dispatchEvent( event );
                status += "Event Dispatched...\n";
            }

           public function handleTestEvent(eventObj:Event):void {

            mx.controls.Alert.show(eventObj.currentTarget,'Test');

                  }
        ]]>
    </mx:Script>

    <mx:Button x="66" y="56" label="Login1" click="dispatchTextEvent()" />
    <mx:TextArea x="66" y="123" width="393" height="243" text="{status}"/>
    <Login x="333" y="56"  login="handleTestEvent(event)"/>
</mx:Application>





<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">
<mx:Metadata>
      [Event(name="login", type="flash.events.Event")]
</mx:Metadata>
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            public function loginUser():void
            {
                var event:Event = new Event("login");
                dispatchEvent( event );

                Application.application.status += "Dispatch login
event...\n";
            }

            ]]>
    </mx:Script>
    <mx:ControlBar>
        <mx:Button label="Login2" click="loginUser()" />
    </mx:ControlBar>
</mx:Canvas>


|---------+----------------------------->
|         |                             |
|         |  "Doug Lowder"              |
|         |  <[EMAIL PROTECTED]>   |
|         |  Sent by:                   |
|         |  flexcoders@yahoogroups.com |
|         |  04/20/2006 05:22 PM        |
|         |  Please respond to          |
|         |  flexcoders                 |
|         |                             |
|---------+----------------------------->
  >-----------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                             |
  |      To: flexcoders@yahoogroups.com                                                                                         |
  |      cc:                                                                                                                    |
  |      Subject:  [flexcoders] Re: flex newbie - dispatchEvent question - Part 2                                               |
  >-----------------------------------------------------------------------------------------------------------------------------|




Hmm, the code you posted for Login.mxml dispatches a "login" event,
not "test", so that's one thing to be aware of.  You'll need to add
the listener to the Login object, which you can do by giving the
Login component an id (<Login id="loginComponentId" ...>) and then
calling something similar to:

loginComponentId.addEventListener("login", onLoginEvent).

Doug

--- In flexcoders@yahoogroups.com, Andrea Varga <[EMAIL PROTECTED]> wrote:
>
> Well, this worked, but in the Cairngorm framework this was correct
and
> the problem is somewhere else.
> Below is my new little test.
> This time the button that does the dispatchEvent is not in the
> application, but inside another component
>
> The  Main.mxml code is almost the same as before, just the Login
> component is new.
> The button with Login1 has the same code as the Login2 button
inside the
> Login component (both dispatch a "test" event).
> But the Application catches just the Login1 event.
> What am I mmissing this time?
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
> layout="absolute" applicationComplete="onComplete()">
>     <mx:Script>
>         <![CDATA[
>
>             [Bindable]
>             public var status:String = "";
>
>             public function onComplete():void {
>                 status += "Add Event Listener...\n";
>
> Application.application.addEventListener("test",onTestEvent);
>             }
>
>             public function onTestEvent(event:Event):void {
>                 Application.application.status += "Test Event
occured...\n";
>             }
>
>             public function dispatchTextEvent():void {
>                 var event:Event = new Event("test");
>                 dispatchEvent( event );
>                 status += "Event Dispatched...\n";
>             }
>         ]]>
>     </mx:Script>
>
>     <mx:Button x="66" y="56" label="Login1"
click="dispatchTextEvent()" />
>     <mx:TextArea x="66" y="123" width="393" height="243"
text="{status}"/>
>     <Login x="333" y="56" />
> </mx:Application>
>
> The Login.mxml code:
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">
>     <mx:Script>
>         <![CDATA[
>             public function loginUser():void
>             {
>                 var event:Event = new Event("login");
>                 dispatchEvent( event );
>                 Application.application.status += "Dispatch login
> event...\n";
>             }
>
>             ]]>
>     </mx:Script>
>     <mx:ControlBar>
>         <mx:Button label="Login2" click="loginUser()" />
>     </mx:ControlBar>
> </mx:Canvas>
>
>
> [EMAIL PROTECTED] wrote:
>
> >Try changing
> >
> >
> >public function onTestEvent()
> >to
> >public function onTestEvent(event:Event)
> >
> >
> >  You should add event:Event in your listener.
> >
> >
> >
> >
>






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links











---------------------------------------------------------------------------
This e-mail message (including attachments, if any) is intended for the use
of the individual or entity to which it is addressed and may contain
information that is privileged, proprietary , confidential and exempt from
disclosure.  If you are not the intended recipient, you are notified that
any dissemination, distribution or copying of this communication is
strictly prohibited.  If you have received this communication in error,
please notify the sender and erase this e-mail message immediately.
---------------------------------------------------------------------------




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to