This is NOT duplicate of my earlier post (its is slightly different)
But this is similar issue with similar error but its not the same error
The error I am getting now is below while dispatching the custom event from my custom component
TypeError: Error #1034: Type Coercion failed: cannot convert events::MapEvent@a74ab51 to flash.events.MouseEvent.
dispatchEvent(new MapEvent(MapEvent.CLICKED_ON_MAP));
Note: The error in my earlier post is giving below error message
Type Coercion failed: cannot convert flash.events::Event@81ecb79 to com.events.ShopEvent
The difference here are two things, the earlier error is while converting flash event to custom event and now this one is while converting custom event to flash event and secondly, I have no clue why it is trying to convert to the mouseevent where I am just dispatching my custom event with proper listeners.
Can some one correct me what I am doing wrong here.
This is my custome event
package events
{
import flash.events.Event;
import ui.map.MapElement;
public class MapEvent extends Event
{
public static const NEW_ELEMENT_ATTACHED:String = "newElementAttached";
public static const CLICKED_ON_MAP:String = "clickedOnMap";
public static const CLICKED_ON_ELEMENT:String = "clickedOnElement";
public var element:MapElement;
public function MapEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false){
super(type, bubbles, cancelable);
}
override public function clone():Event{
var c:MapEvent = new MapEvent(type, bubbles, cancelable);
c.element = this.element;
return c;
}
}
}
This is how I am dispatching the event from my custom component (WorldMap.as class file)
private function clickHandler(e:MouseEvent):void{
e.stopImmediatePropagation();
trace("worldmap click handler");
if (dragInProgress){
/*trace ("stopping event propagation");*/
dragInProgress = false;
return;
}else{
trace("dispatching proxy click event");
dispatchEvent(new MapEvent(MapEvent.CLICKED_ON_MAP));
}
}
I have declared [Event] metatag as well
[Event(name="newElementAttached", type="events.MapEvent")]
[Event(name="clickedOnMap", type="events.MapEvent")]
[Event(name="clickedOnElement", type="events.MapEvent")]
Finally the listener is attached in other component (controller.as)
_userWorld.addEventListener(MapEvent.CLICKED_ON_MAP,clickedOnWorldMap);
_userWorld.addEventListener(MapEvent.CLICKED_ON_ELEMENT,clickedOnElement);
private function clickedOnWorldMap(e:MouseEvent):void{
_draggingMapElement.hideBaseGrid();
_draggingMapElement = null;
}
private function clickedOnElement(e:MapEvent):void{
}
Its my bad. I fixed the silly bug.
I changed the lister function definition. (Replace mouseevent to MapEvent)