2 Replies Latest reply on Jun 18, 2007 4:17 AM by karel_s

    DispatchEvent error

      Hi all,

      i'm having a form with a save button, some fields and a datagrid with files to be uploaded.
      When i press save, i want the record to be saved and the files uploaded.
      In the save button handler i'm dispatching an event for the upload button

      private function Bewaarclicked():void{
      // here needs to be some code for saving form data

      // press upload button
      var result:Boolean = upload_btn.dispatchEvent(new Event(MouseEvent.CLICK));

      This is the error i get.

      TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@4640449 to flash.events.MouseEvent.
      at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.core::UIComponent/dispatchEvent()
      at Upload/::Bewaarclicked()
      at Upload/__btnBewaar_click()

      after dismissing this error, everything seems to work ok?

      What is wrong here?

      Thanks a lot
        • 1. Re: DispatchEvent error
          HyderAlamgir Level 1
          var result:Boolean = upload_btn.dispatchEvent(new Event(MouseEvent.CLICK));

          the event that you dispatch here is of type Event NOT MouseEvent

          Remember MouseEvent.CLICK is just a string constant

          The listener function is probably taking the arguments of the wrong type:

          You need to change the type of the argument being passed to the listener function to Event
          • 2. Re: DispatchEvent error
            karel_s Level 1
            I found the anwser, new Event was not specific enough. it had to be new MouseEvent:

            var result:Boolean = upload_btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK));