Note that there are some explanatory texts on larger screens.

plurals
  1. POFlex Custom Event - Type Coercion Error - Application domain related?
    text
    copied!<p>I've been looking at answers for my problem, I think I may be on the right track but I just can't understand how to implement the solution. I need help.</p> <p>I have a class, RootPackage.Utils.SelectableGraphic.as, a widget, RootPackage.Widgets.WidgetWithSelection.mxml and a custom event, RootPackage.Events.SelectableGraphicEvent. </p> <p>The SelectableGraphic dispatches SelectableGraphicEvents and the WidgetWithSelection listens to those events. My event looks like this : </p> <pre><code>{ import RootPackage.utils.SelectableGraphic; import flash.events.Event; public class SelectableGraphicEvent extends Event { public static const GRAPHIC_ADDED:String = 'Graphic_Added'; public static const GRAPHIC_CLICKED:String = 'Graphic_Clicked'; private var graphic:SelectableGraphic; public function SelectableGraphicEvent(type:String, gra:SelectableGraphic, bubbles:Boolean=false, cancelable:Boolean=false) { super(type, bubbles, cancelable); graphic = gra; } override public function clone():Event { return new SelectableGraphicEvent(type, graphic, bubbles, cancelable); } public function get Graphic():SelectableGraphic { return graphic; } } </code></pre> <p>My dispatch looks like this :</p> <pre><code>lastDrawnGraphic = new SelectableGraphic(...); lastDrawnGraphic.dispatchEvent(new SelectableGraphicEvent(SelectableGraphicEvent.GRAPHIC_ADDED, lastDrawnGraphic, true)); </code></pre> <p>And my listening function looks liek this :</p> <pre><code>private function SelectableGraphic_ClickHandler(event:SelectableGraphicEvent):void { gra:SelectableGraphic = event.Graphic; ... } </code></pre> <p>It crashes between the dispatch and the reception in the WidgetWithSelection, before entering the listening function. If I change the listening function header to listen to a basic Event, then it doesn't crash but, when I try to obtain the event.Graphic, it gives the same type coercion error. I've tried many work arounds, for example receiving a normal event, casting it to a SelectableGraphicEvent and using it. The cast operation returns a null value in this case.</p> <p>The type coercion error is something like : Error #1034: Type Coercion failed: cannot convert RootPackage.Events::SelectableGraphicEvent@b56b071to RootPackage.Events.SelectableGraphicEvent.</p> <p>Anyhow, I've read a bit about this and I believe it might be due to those classes being in a different application domain than my main application or something to that effect. Apparently there's a way of changing the application domain but I just don'T know how to do this. This has me confused at the moment, as you probably can tell from the last paragraph. Is there a simpler answer or can anyone explain to me what I should be doing?</p> <p>Thanks,</p> <p>Ggilmann</p> <p><strong>EDIT TO ADD:</strong></p> <p>Here is the part where the EventListener is added. The open() is on the Added_To_Stage event and the close() is on the Remove_From_Stage :</p> <pre><code>private function open():void { this.map.addEventListener(SelectableGraphicEvent.GRAPHIC_CLICKED, SelectableGraphic_ClickHandler); this.map.addEventListener(SelectableGraphicEvent.GRAPHIC_ADDED, SelectableGraphic_AddedHandler); _selectableGraphics = GetSelectableGraphics(); } private function close():void { this.map.removeEventListener(SelectableGraphicEvent.GRAPHIC_CLICKED, SelectableGraphic_ClickHandler); this.map.removeEventListener(SelectableGraphicEvent.GRAPHIC_ADDED, SelectableGraphic_AddedHandler); ClearSelection(); } </code></pre> <p>Basically, there's a map that contains a graphic layer that contains the selectable graphics. So when I dispatch from my SelectableGraphic, the event bubbles up to map (and beyond). The map catches the event and fires the appropriate SelectableGraphic_EventHandler.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload