How to pass binary data from javascript to actionscript (webpage to flash) without encoding or saving data?

StackOverflow https://stackoverflow.com/questions/11458717

Pergunta

Situation: I'm trying to replace Flash Socket communication (byte-range) with javascript, to avoid the flash socket security policy file restrictions.

Details: I have binary data from javascript, and I can pass it to flash by base64 encoding/decoding, but this is too slow. Saving to disk and passing the local url is not an option (and not just for speed, but also clients prefer everything in memory, and the swf file may be restricted from loading local files). Furthermore, not using base64 doesn't work, as flash's ExternalInterface uses XML (which isn't designed to carry binary data) to pass the data to AS3.

Question: Is there any way to get binary data from JS to AS3 without writing to disk and not bae64 encoding?

I am aware of Action Message Format (AMF) but it seems to add way to many external dependencies, and may still be slow?

Note: My program needs to be as browser compatible as possible, and it's downloaded by clients (so needs to be small) and it also needs to run as fast as possible...

thanks!

Foi útil?

Solução

I've modified my thinking slightly about this problem:

There is no straight forward way to send binary data between Flash and Javascript without marshaling it into a text based format first (ie: base64 encoding it).

As noted by the OP, to facilitate communication between Actionscript and Javascript the ExternalInterface class actually marshals objects/data into an XML format. As such the binary data would need to go through this conversion to XML.

New thought: when you use ExternalInterface the Flash application actually modifies the DOM, adding methods that serialize/deserialize the data to/from XML (reference needed, I've read about this but cannot find it now). Technically, it might be possible to re-define these methods in Javascript and fix the XML parsing errors you saw when trying to pass binary data. You'd have to determine the names of the names of these methods (I recall them starting with __Flash__ or something similar).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top