问题
I would like to know what is the most efficient way to transfer BitmapData object from Actionscript to Javascript, so an image can be displayed on webpage.
So far, I've managed to craft a string containing image data using data URI scheme in Flash and then I transfered it to the Javascript using ExternalInterface.call("<function_name>", data).
While it is working fine, it seems wasteful to convert image to its textual representation just to transfer it. Is there a cleaner/more efficient way to achieve the same?
回答1:
AS3:
base64 encode your BitmapData object. example
then:
ExternalInterface.call("setImage",encodedImg);
Javascript:
function setImage(baseSixtyFourEncodedImage)
{
document.getElementById("myImage").src = "data:" + baseSixtyFourEncodedImage;
}
HTML:
<img id="myImage" src="no_image_from_flash_yet.png">
Don't forget to import ExternalInterface on the flash end! let me know how it goes.
来源:https://stackoverflow.com/questions/10936408/transfer-bitmap-from-flash-movie-to-javascript