# dispatchEvent tries to cast my customEvent to something completely different

**URL:** <https://forum.kirupa.com/t/dispatchevent-tries-to-cast-my-customevent-to-something-completely-different/319755>\
**Category:** flash\
**Created:** [March 3, 2011, 12:01pm UTC](https://forum.kirupa.com/t/dispatchevent-tries-to-cast-my-customevent-to-something-completely-different/319755 "2011-03-03T12:01:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wentu](https://avatars.discourse-cdn.com/v4/letter/w/ad7895/32.png) [@Wentu](https://forum.kirupa.com/u/Wentu)\
**Post date:** [March 3, 2011, 12:01pm UTC](https://forum.kirupa.com/t/dispatchevent-tries-to-cast-my-customevent-to-something-completely-different/319755/1 "2011-03-03T12:01:42Z")

</div>

Hi All

I have a problem in dispatching a customEvent. I already managed to dispatch custom events in other projects and all worked well so i can’t understand what’s different now.

I have a WSConnectorEvent that extends Event

```auto
package
{
    import flash.events.Event;
    public class WSConnectorEvent extends flash.events.Event
    {
        public static const WSLOAD:String = "WSConnectorEvent_WSLOAD";
        public static const WSLOADFAULT:String = "WSConnectorEvent_WSLOADFAULT";

        public function WSConnectorEvent(type:String,bubbles:Boolean,cancelable:Boolean)
        {
            super(type,bubbles,cancelable);
        }
        override public function clone():Event
        {
            return new WSConnectorEvent(type,bubbles,cancelable);
        }
    }

}

```

The class WSConnector tries to reach a WebService and in the case of success or failure should send a WSConnectorEvent of type WSLOAD or WSLOADFAULT.

```auto

package
{
    import mx.rpc.soap.*;
    import mx.rpc.events.*;
    import mx.rpc.AbstractOperation;
    import flash.utils.getQualifiedClassName;
    import flash.events.*;
    import flash.events.EventDispatcher;

    public class WSConnector extends EventDispatcher
    {
        private static var instance:WSConnector = new WSConnector();
        private static var WSURL:String;
        private var quizWebService:WebService;
        private var serviceOperation:AbstractOperation;
        public function WSConnector()
        {
               //...
        }

        public function SetupWebService():void
        {
            quizWebService = new WebService();
            //movieWebService.loadWSDL(WSURL);
            quizWebService.addEventListener(LoadEvent.LOAD, quizWebService_onLoad);
            quizWebService.addEventListener(FaultEvent.FAULT, quizWebService_onFault);
            quizWebService.loadWSDL(WSURL);
        }

        function quizWebService_onLoad(evt:LoadEvent)
        {
            var wsce:WSConnectorEvent = new WSConnectorEvent(WSConnectorEvent.WSLOAD, true,true);

            dispatchEvent(wsce);
        }
       
        function quizWebService_onFault(evt:FaultEvent)
        {
            var wsce:WSConnectorEvent = new WSConnectorEvent(WSConnectorEvent.WSLOADFAULT, false ,false);

            dispatchEvent(wsce);
        }
       
    }
}

```

* * *

what actually happens is that (in both cases) the variable wsce of WSConnectorEvent type is correctly created but when the dispatchEvent(wsce) is called, i receive the following error (in case of function quizWebService\_onFault(evt:FaultEvent) ).

Question: why on hell is it trying to convert my custom event in a mx.rpc.events.FaultEvent ??? Isn’t DispatchEvent accepting Event as a class ? Why does it need to cast it to something completely unrelated ???

> 

TypeError: Error #1034: Assegnazione di tipo forzata non riuscita: impossibile convertire WSConnectorEvent@1f7efa1 in mx.rpc.events.FaultEvent. (in english this approximately means Impossible to cast from WSConnectorEvent@1f7efa1 to mx.rpc.events.FaultEvent)  
at flash.events::EventDispatcher/dispatchEventFunction()  
at flash.events::EventDispatcher/dispatchEvent()  
at WSConnector/quizWebService\_onFault()[F:\Documenti\TSF\OnDe\Entertainment\TravelQuiz\WSConnector.as:58]  
at flash.events::EventDispatcher/dispatchEventFunction()  
at flash.events::EventDispatcher/dispatchEvent()  
at mx.rpc::AbstractService/dispatchEvent()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AbstractService.as:333]  
at mx.rpc.soap::WebService/[http://www.adobe.com/2006/flex/mx/internal::wsdlFaultHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\soap\WebService.as:296]](http://www.adobe.com/2006/flex/mx/internal::wsdlFaultHandler()%5BE:%5Cdev%5C4.x%5Cframeworks%5Cprojects%5Crpc%5Csrc%5Cmx%5Crpc%5Csoap%5CWebService.as:296%5D)  
at flash.events::EventDispatcher/dispatchEventFunction()  
at flash.events::EventDispatcher/dispatchEvent()  
at mx.rpc.wsdl::WSDLLoader/faultHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\wsdl\WSDLLoader.as:105]  
at flash.events::EventDispatcher/dispatchEventFunction()  
at flash.events::EventDispatcher/dispatchEvent()  
at HTTPOperation/[http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\http\HTTPService.as:989]](http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()%5BE:%5Cdev%5C4.x%5Cframeworks%5Cprojects%5Crpc%5Csrc%5Cmx%5Crpc%5Chttp%5CHTTPService.as:989%5D)  
at mx.rpc::AbstractInvoker/[http://www.adobe.com/2006/flex/mx/internal::faultHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:350]](http://www.adobe.com/2006/flex/mx/internal::faultHandler()%5BE:%5Cdev%5C4.x%5Cframeworks%5Cprojects%5Crpc%5Csrc%5Cmx%5Crpc%5CAbstractInvoker.as:350%5D)  
at mx.rpc::Responder/fault()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:68]  
at mx.rpc::AsyncRequest/fault()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:113]  
at DirectHTTPMessageResponder/errorHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:405]  
at flash.events::EventDispatcher/dispatchEventFunction()  
at flash.events::EventDispatcher/dispatchEvent()  
at [flash.net](http://flash.net)::URLLoader/onComplete()

Thank You very much !

Wentu
