2 Replies Latest reply on Jun 1, 2009 12:48 PM by Miggl

    How to Access Custom Event using AS3?

    Miggl Level 1

      Hi All,

       

      Maybe it's that its Monday morning and my brain is still foggy, but I can't seem to figure out how to set custom events using AS3.

       

      I have a custom GridRow itemRenderer, and have declared the event using the appropriate metatags.

      Then I create the GR item dynamically using AS3 instantiation, but the event is not available for selection in the intellisense drop-down.

       

      Let's take the following as an example:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Grid
           xmlns:mx="http://www.adobe.com/2006/mxml"
           xmlns:renderers="com.brassworks.renderers.*"
           creationComplete="componentInit();"
      >
           <mx:Script>
                <![CDATA[
                     private function componentInit():void
                     {
                          newRow     :MyRow     = new MyRow();
                          //newRow.myEvent is not an available option to set
                     }
                ]]>
           </mx:Script>
      </mx:Grid>
      

       

      Then the itemRenderer:

      <?xml version="1.0" encoding="utf-8"?>
      <GridRow 
           xmlns:mx="http://www.adobe.com/2006/mxml"
           xmlns:classes="com.brassworks.components.classes.*"
           creationComplete="componentInit();"
      >
           <mx:Metadata>
                [Event(name="myEvent", type="flash.events.Event")]
           </mx:Metadata>
           <mx:Script>
                <![CDATA[
                     private function itemChanged(event:Event):void
                {
                     Alert.show("test");
                     this.dispatchEvent(new Event("myEvent"));
                }
                ]]>
           </mx:Script>
           
           <mx:GridItem>
                <mx:TextInput
                     change="itemChanged"
                />
           </mx:GridItem>
      </GridRow>
      

       

      How do I go about setting the handler method for custom events on instantiated items? Do I need to do this via the AddEventListener() method? Does this mean that events aren't exposed in ActionScript like they are in MXML? (In MXML all I have to do is <MyRow myEvent="handler(event)" />.)

       

      Thanks!

      -Mike