6 Replies Latest reply on Aug 3, 2011 5:46 PM by fahnesjh

    1180: Call to a possibly undefined method dispatchEvent - NOT static function

    d:n:k Level 1

      Hi there... I am trying to fire an event from a model...

       

      <code>

      package testapp.mate.models
      {
          import mx.collections.ArrayCollection;
          import testapp.mate.events.*;
          import flash.events.Event;

       


          public class AppModel
          {

       

              [Bindable(event="getNameEvent")]
              public var name:String;

       

              [Bindable(event="getEmailEvent")]
              public var email:String;

       

              [Bindable(event="onFireEvent")]
              public var wasFired:String;

       

              [Bindable(event="testDgEvt")]
              public var dgGrid:ArrayCollection;

       

              public function AppModel()
              {
              }

       

              public function storeName(namein:String):void
              {
                  this.name = namein;
                  var getNameEvt:EchoEvent = new EchoEvent(EchoEvent.GET_NAME_EVENT);
                  dispatchEvent(getNameEvt);
              }

       

              public function storeEmail(emailin:String):void
              {
                  this.email = emailin;
                  var getEmailEvt:EchoEvent = new EchoEvent(EchoEvent.GET_EMAIL_EVENT);
                  dispatchEvent(getEmailEvt);
              }

       

              public function storeWasFiredStatus(statusin:String):void
              {
                  this.wasFired = statusin;
                  var getFiredEvt:EchoEvent = new EchoEvent(EchoEvent.ON_FIRE_EVENT);
                  dispatchEvent(getFiredEvt);
              }

       

              public function storeDg(dg:Array):void
              {
                  dgGrid = new ArrayCollection(dg);
                  var getDataEvt:TestDgEvent = new TestDgEvent(TestDgEvent.GET_DATA_EVENT);
                  dispatchEvent(getDataEvt);
              }
          }
      }

      </code>

       

      Now I keep getting an error:

       

      "1180: Call to a possibly undefined method dispatchEvent."

       

      Now from what I have been googling, this comes up a lot if a function is static. However mine is not.

       

      Ideas?

       

      D

        • 1. Re: 1180: Call to a possibly undefined method dispatchEvent - NOT static function
          Gregory Lafrance Level 6

          Your class does not have a dispatchEvent() method. If you intend to use the Flex dispatchEvent() method simply extend UIComponent:

           

          public class AppModel extends UIComponent

           

          You will need to import mx.core.UIComponent.

           

          If this post answered your question or helped, please mark it as such.

          1 person found this helpful
          • 2. Re: 1180: Call to a possibly undefined method dispatchEvent - NOT static function
            d:n:k Level 1

            I did that, and now i have another error:

             

            1152: A conflict exists with inherited definition flash.display:DisplayObject.name in namespace mx.core:IFlexDisplayObject public.

             

             

            here is what i have for code now:

             

            <code>

            package testapp.mate.models
            {
                import mx.collections.ArrayCollection;
                import testapp.mate.events.*;
                import mx.core.UIComponent;


                public class AppModel extends UIComponent
                {

                    [Bindable(event="getNameEvent")]
                    public var name:String;

                    [Bindable(event="getEmailEvent")]
                    public var email:String;

                    [Bindable(event="onFireEvent")]
                    public var wasFired:String;

                    [Bindable(event="testDgEvt")]
                    public var dgGrid:ArrayCollection;

                    public function AppModel()
                    {
                    }

                    public function storeName(namein:String):void
                    {
                        this.name = namein;
                        var getNameEvt:EchoEvent = new EchoEvent(EchoEvent.GET_NAME_EVENT);
                        dispatchEvent(getNameEvt);
                    }

                    public function storeEmail(emailin:String):void
                    {
                        this.email = emailin;
                        var getEmailEvt:EchoEvent = new EchoEvent(EchoEvent.GET_EMAIL_EVENT);
                        dispatchEvent(getEmailEvt);
                    }

                    public function storeWasFiredStatus(statusin:String):void
                    {
                        this.wasFired = statusin;
                        var getFiredEvt:EchoEvent = new EchoEvent(EchoEvent.ON_FIRE_EVENT);
                        dispatchEvent(getFiredEvt);
                    }

                    public function storeDg(dg:Array):void
                    {
                        dgGrid = new ArrayCollection(dg);
                        var getDataEvt:TestDgEvent = new TestDgEvent(TestDgEvent.GET_DATA_EVENT);
                        dispatchEvent(getDataEvt);
                    }
                }
            }

            </code>

            • 3. Re: 1180: Call to a possibly undefined method dispatchEvent - NOT static function
              msakrejda Level 4

              Your model should probably not extend UIComponent (since it's not really a UI component; it's a model). If you'd like event dispatch from your model, extend EventDispatcher itself.

               

              --
              Maciek Sakrejda
              Truviso, Inc.
              www.truviso.com
              Truviso is hiring: http://www.truviso.com/company-careers.php?i=87

              • 4. Re: 1180: Call to a possibly undefined method dispatchEvent - NOT static function
                Barna Biro Level 3

                Yes, extending EventDispatches is way better then extending UIComponent. Beside that, I have no idea why are you declaring bindable objects. You are just creating an unnecessary overhead with no benefit. Also, why aren't you simply defining a protected/private variable of type EchoEvent and reuse it instead of instantiating the EchoEvent each time with a different reference...

                • 5. Re: 1180: Call to a possibly undefined method dispatchEvent - NOT static function
                  d:n:k Level 1

                  I had gone this way due to a recommendation (on a different forum post) for another issue I was having (bindings not updating). I was not sure why I had to do it this way, but in working through it all, and this was the code I came up with. Now in all honsty, I had taken the code backwards and gotten rid of all of this. My original issue was becasue I was clearing a text field, instead of clearing the var in my data model... so binding wasn't working for the next call. Anywys - that is OT as it is what led to this issue. Either way, I have stripped out this code, and it is a moot point (for me).

                  I wanted to thank all for the ansers and help though.

                   

                  Message was edited by: d:n:k

                  • 6. Re: 1180: Call to a possibly undefined method dispatchEvent - NOT static function
                    fahnesjh Level 1

                    I had the same issue when using dipatchEvent in a class that wasn't extending a specific display object like a MovieClip or a Sprite once the class was extended the dipatchEvent worked. Not sure why.