Skip to main content
Inspiring
July 24, 2012
Question

How to transfer a local javascript AMF object from webpage to embedded swf file?

  • July 24, 2012
  • 1 reply
  • 2901 views

Is it possible to transfer AMF data from the containing webpage into the embedded swf file (in that same webpage)?

For example, if I have a javascript ArrayBuffer in the webpage, and I encode into an AMF object (yes, this is another issue entirely), is there anyway to pass the AMF object to the swf file loaded in the webpage?

Everything I've seen so far is based on getting the AMF from a remote location, using say URLLoader, but in my case I already have the data locally, just not in the swf.

thanks

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
July 25, 2012

use the ExternalInterface class.

if you can use the call() method, you should have no problem.  if you have to use the addCallback() method, you'll need to use compatible (with the ExternalInterface class) embedding code (like swfobject or the sample embed code shown in the flash help files).

ryan_seAuthor
Inspiring
July 30, 2012

Thanks for the response kglad. However I'm unable to get any sort of test to work. I have the following code in AS3, as a button click handler (I'm trying to pass AMF data out to JS as an initial test, in the end I'm going to have it the other way around though).

protected function AMFBtn_clickHandler(event:MouseEvent):void

{

    registerClassAlias("com.example.eg", ExampleClass);

    var eg1:ExampleClass = new ExampleClass();

    var ba:ByteArray = new ByteArray();

    ba.writeObject(eg1);

    ba.position = 0;

    ExternalInterface.call("onAMF", ba)

}

but in the javascript in the html page the returned object only has the following properties, bytesAvailable, endian, length, objectEncoding and position, and no binary data.

Note: ExampleClass has no properties or methods (though I've tried with properties also and get the same result)

I'm using swfobject.embedSWF to embed the swf file, and all externalinterface communication works fine.

thanks

kglad
Community Expert
Community Expert
July 30, 2012

pass a string instead of a bytearray to test externalinterface.  otherwise, you're testing a lot more than externalinterface.

then you start thinking about your serialization/deserialization code which is where you have a problem.