2 Replies Latest reply on Apr 24, 2008 9:49 AM by RanchingOnMyMind

    Event communication between Dynamically loaded modules

    sk_acura Level 1
      Hi All,

      I am loading the Modules dynamically in a separate popup windows and
      once ther are loaded they need to communicate with each other (for
      when i click some link in one window i need to refresh the contents of
      the Other window and switch focus to it..)

      And when i try to send a custom event i am getting the following Error:

      I am not sure why it is having trouble in converting FocusViewEvent
      Object to FocusViewEvent Type !!!

      [ERROR]

      TypeError: Error #1034: Type Coercion failed: cannot convert
      com.dpa.ui.desktop.event::FocusViewEvent@-4ff225ff to
      com.dpa.ui.desktop.event.FocusViewEvent.
      at
      flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio\
      n()
      at flash.events::EventDispatcher/dispatchEvent()
      at MyGraph/::notifyParent()
      at MyGraph/___Button4_click()
      [/ERROR]

      The code i have is :

      window1.as

      [CODE]
      private function notifyParent():void{
      var focusEvent:FocusViewEvent = null;
      var viewVO:ViewVO = new ViewVO();
      viewVO.viewId="1234";
      focusEvent = new FocusViewEvent(viewVO);
      trace("Here in notifyParent() and focusEvent ="+focusEvent);
      MyEventDispatcher.getInstance().dispatchEvent(focusEvent);
      trace("After sending the Notification Event");
      }
      [/CODE]

      window2.as
      [CODE]

      public function init():void{
      trace("Here in init()");
      this.addEventListener(
      FocusViewEvent.EVENT_FOCUS_WINDOW,this.onFocusWindow);
      trace("After adding the Event Listener 1");
      }
      public function onFocusWindow(event:FocusViewEvent):void{
      trace("Here in onFocusEvent focusEvent ="+event);
      }
      [/CODE]

      The FocusViewEvent is declared as
      [CODE]
      public class FocusViewEvent extends CairngormEvent
      {
      public static var EVENT_FOCUS_WINDOW : String = "focusViewEvent";
      public var viewVO:ViewVO;
      public function FocusViewEvent(viewVO : ViewVO)
      {
      super(EVENT_FOCUS_WINDOW);
      this.viewVO = viewVO;
      }
      }
      [/CODE]

      Thanks
      Kumar
        • 1. Re: Event communication between Dynamically loaded modules
          Gaurav J Adobe Employee
          You may be having class loading conflicts in your app. The definition of FocusViewEvent may be different between the two modules.

          As a workaround you should try to declare the FocusViewEvent in the main app, so that the class gets loaded as part of the main app and the same definition is shared by both modules.

          You should add the following to your main app.

          import com.dpa.ui.desktop.event::FocusViewEvent;
          var dummyFocusEvent:FocusViewEvent = null;

          Thanks,
          Gaurav Jain
          Flex SDK Team
          • 2. Re: Event communication between Dynamically loaded modules
            RanchingOnMyMind Level 1
            Kumar/Gaurav,

            I encountered a similar problem--TypeError: Error #1034: Type Coercion failed: cannot convert mx.controls::ToggleButtonBar@431b0a1 to mx.controls:ButtonBar.

            I followed Gaurav's advice and placed a variable in the main app, as follows:

            [Bindable]
            private var dummyToggleButtonBar:ToggleButtonBar = null;

            This resolved the TypeError: Error #1034.

            My only question is why, I assume this resets the ToggleButtonBar, but how does the above variable get associated with the ToggleButtonBar I'm using in several modules?

            Dan