Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2011
    Messaggi
    3

    DispatchEvent tenta di fare il cast di un eventoCustom ad un evento che non c'entra

    Salve a tutti

    Ho il seguente problema nel fare il dispatch di un customevent (cosa che ho fatto altre volte con successo, ma questa volta non capisca cosa non va):

    Ho un customevent WSConnectorEvent extends Event


    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,cance lable:Boolean)
    {
    super(type,bubbles,cancelable);
    }
    override public function clone():Event
    {
    return new WSConnectorEvent(type,bubbles,cancelable);
    }
    }


    }

    La classe WSConnector tenta di contattare un webservice e in caso di successo o fallimento deve inviare un WSConnectorEvent di tipo WSLOAD o WSLOADFAULT

    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);
    }

    }
    }


    -----------------------------------------
    Quello che succede è che in entrambi i casi la variabile wsce di tipo WSConnectorEvent viene creata correttamente ma quando chiamo dispatchEvent(wsce) ricevo un errore del tipo che riporto sotto.

    DOMANDA: perchè diavolo dispatchEvent cerca di convertire un mio evento a un evento che a questo punto non c'entra nulla ? Perchè dovrei dover ri-dispatchare un evento castabile a quello che sto gestendo ??

    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\WSC onnector.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\Abst ractService.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]
    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]
    at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\Abst ractInvoker.as:350]
    at mx.rpc::Responder/fault()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\Resp onder.as:68]
    at mx.rpc::AsyncRequest/fault()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\Asyn cRequest.as:113]
    at DirectHTTPMessageResponder/errorHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messagin g\channels\DirectHTTPChannel.as:405]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()


    Grazie per il vostro aiuto


    Wentu

  2. #2
    Utente di HTML.it
    Registrato dal
    Mar 2011
    Messaggi
    3
    Thankx to maskedMan I now have the answer:

    You're dispatching an instance of your custom event, but the function that you've set up to handle it expects a FaultEvent object. In brief, the scenario looks something like this:
    codice:
    foo.addEventListener(CustomEvent.CUSTOMTYPE, handleEvent); private function handleEvent(evt:FaultEvent):void{ }

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.