Transfer bitmap from Flash movie to Javascript

我们两清 提交于 2019-12-25 05:15:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!