Select to view content in your preferred language

event inter widgets

1009
1
08-31-2011 05:52 AM
lavoillottenicolas
Emerging Contributor
hello

I have two widgets : W1 and W2
I would like to send data from w1 to w2 with a custom event

when i receive the object from w1 I can't transform it into my own class (MyClassEvent). however object type is right because in debug mode Eclipse display its type (MyClassEvent)

e.g :
//
// MyClassEvent
//
public class MyClassEvent extends Event
    {
       
        public static const GOTO_POINT:String="gotopoint";
        public var drawEvent:DrawEvent;
       
        public function MyClassEvent(type:String, event:DrawEvent)
        {
            super(type, false, false);
            this.drawEvent=event;
        }
    }

//
// W1 sender
//
private function sender_clickhandler() : void {
                var id:Number=ViewerContainer.getInstance().widgetManager.getWidgetId("w1");
                var widget:IBaseWidget =ViewerContainer.getInstance().widgetManager.getWidget(id,true) ;

                if (widget !=null) {
                    var mp:MapPoint=map.toMapFromStage(550, 480);
                   
                    widget.dispatchEvent(new  MyClassEvent(MyClassEvent.GOTO_POINT,new DrawEvent(Geometry.MAPPOINT,new  Graphic(mp))));                   
                }
                   
  }

//
// W2 listener
//
private function init():void {
addEventListener(MyClassEvent.GOTO_POINT,function event(event:Event):void {
   var mce:MyClassEvent = MyClassEvent (event);

   // At this point, mce is null but event parameter is well displayed by
   // Eclispse's debugger (not null and with the good type !)
   trace(mce.drawEvent);
});   
}

Nicolas
Tags (2)
0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus
Nicolas,

   First you should be posting Flex Viewer Questions to the Flex Viewer forum:

http://forums.arcgis.com/forums/111-ArcGIS-Viewer-for-Flex

You don't need to extend your own custom event just add your event name to the AppEvent.as and let the Viewers event handling do all the work for you, that way all you have to do is add listeners for that AppEvent and Dispatch that AppEvent in the widgets.
0 Kudos