Domanda

Stavo cercando di recuperare i dati binari su HTTP per la mia applicazione Flex, e correvo in alcuni ostacoli. HTTPService non sembrava a che fare con dati binari bene, la gente ha detto di usare URLLoader. Ma URLLoader non ha la bella interfaccia AsyncToken / IResponder che HTTPService fornisce.

Così, ho fatto qualche ricerca e non riuscivo a trovare qualcuno che si estende URLLoader per fornire questo tipo di funzionalità. Sono andato avanti e ha preso una pugnalata a me stesso: http://pastebin.com/d7369d0e0

In sostanza si avvolge un'URLLoader e un AsyncToken, e le mappe The Complete, eventi IO_ERROR, e SECURITY_ERROR da URLLoader ai risultati / Anomalie che vengono in rilievo sul AsyncToken.

Utilizzo di base:

var tidbitLoader:AsyncURLLoader = new AsyncURLLoader();
tidbitLoader.dataFormat = URLLoaderDataFormat.BINARY;

var asyncToken:AsyncToken = tidbitLoader.load(new URLRequest("http://localhost/SampleTidbit.swf"));

asyncToken.addResponder(this);

public function result(resultEvent:Object):void
{
    trace("result");
}

public function fault(faultEvent:Object):void 
{
    var fault:FaultEvent = faultEvent as FaultEvent;
    trace("fault: " + fault.toString());
}

E 'questo il modo giusto di affrontare il problema? Ci sono già esistente soluzioni? Mi piacerebbe sentire il feedback.

Grazie,

Karthik

È stato utile?

Soluzione

Utilizza il resultFormat = text sulla HTTPService e quindi creare un nuovo ByteArray e chiamare writeUTFBytes scrivere il testo dal risultato HTTPService al ByteArray. Poi si dovrebbe essere in grado di impostare che ByteArray ad un SWFLoader.source o una chiamata Loader.loadBytes.

Altri suggerimenti

Ho provato la soluzione James con AIR 1.5 app, ma ottengo il seguente errore quando ho impostato il ByteArray sul mio SWFLoader.source. Qualche idea? Ho pensato che ho letto da qualche parte che AIR cambia le intestazioni HTTP e questo potrebbe essere la causa? Grazie Ben.

[DEBUG] mx.messaging.Channel 'direct_http_channel' canale di invio del messaggio: (Mx.messaging.messages :: HTTPRequestMessage) # 0   corpo = (Object) # 1   clientId = (null)   contentType = "application / x-www-form-urlencoded"   destinazione = "DefaultHTTP"   headers = (Object) # 2   httpHeaders = (Object) # 3   messageId = "3044E76C-CF0E-2D5F-96BE-74CFF62098B0"   method = "GET"   recordHeaders = false   timestamp = 0   timeToLive = 0   url = " http://www.myurl.com/test.jpg " produttore [INFO] mx.messaging.Producer '4FA2CCF4-2B3E-4EAB-2873-74CFF612AA72' connessa. [INFO] mx.messaging.Producer '4FA2CCF4-2B3E-4EAB-2873-74CFF612AA72' produttore acknowledge di '3044E76C-CF0E-2D5F-96BE-74CFF62098B0'. [INFO] mx.rpc.http.HTTPService decodifica HTTPService risposta messaggio di risposta [DEBUG] mx.rpc.http.HTTPService Processing HTTPService: (mx.messaging.messages :: AcknowledgeMessage) # 0   body = "Yoya Errore # 2044: non gestita IOErrorEvent :. text = Errore # 2124:. File caricati è un tipo sconosciuto

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top