Problem transferring data from Javascript to Flex

I am using ExternalInterface in Flex to extract an AMF encoded string from Javascript. The problem is that the AMF encoding sometimes contains \ u0000, which causes ExternalInterface to return null instead of the encoded string from Javascript.

Any idea how to solve this?

Thanks in advance.

+3
source share
2 answers

Encoding AMF pyamf output to base64 will do the trick.

Here is the coding part in python:

encoder = pyamf.get_encoder(pyamf.AMF3)
encoder.writeObject(myObject)
encoded = base64.b64encode(encoder.stream.getvalue())

Here is the decoding part in AS3:

var myDecoder:Base64Decoder = new Base64Decoder();
myDecoder.decode(base64EncodedString);
var byteArr:ByteArray = myDecoder.toByteArray()
byteArr.position = 0;
var input:Amf3Input = new Amf3Input();
input.load(byteArr);                
var test:MyObject = input.readObject();
+2
source

\ 0000 is falsely interpreted as EOF when reading external data. The same thing happens in XML files.

Flash ActionScript. JavaScript -

return returnString.replace (/\0000/g, "{nil}");

\0000 , Flash.

Flash

receiveString = receiveString.replace (/\{nil\}/g, "\u0000"); 

.

+4

Source: https://habr.com/ru/post/1795609/


All Articles