Flash的SharedObject中可以存储图片吗?
是否可以将图像存储在 Flash 的 SharedObject 中?如果能行的话那就太好了。我需要在本地“存储”图像,但 Flash 似乎不支持它...所以我想将这些图像放入可以保存的 SharedObject 中...但是它可以处理图像吗?
我用位图尝试过,但如果我想读取并将其添加到舞台上,它会说该对象无法转换为位图...
var image:Bitmap = //some awesome image;
sharedObject = SharedObject.getLocal("img");
sharedObject.data.img = image;
sharedObject.flush();
此处错误 ->
sharedObject = SharedObject.getLocal("img");
addChild(Bitmap(sharedObject.data.img));
Is it possible to store a Image in a SharedObject in Flash? It would be nice if it would work. I need to "store" Images locally but it seems not to be supported by Flash... So I 'ld like to put those images in a SharedObject that can be saved... but does it work with images?
I tried it with a Bitmap but if I want to read and add it to the stage it says that the Object can't be converted to a Bitmap...
var image:Bitmap = //some awesome image;
sharedObject = SharedObject.getLocal("img");
sharedObject.data.img = image;
sharedObject.flush();
Error here ->
sharedObject = SharedObject.getLocal("img");
addChild(Bitmap(sharedObject.data.img));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下,您需要在设置共享对象之前将位图写入 ByteArray(换句话说,二进制数据)。然后,当您检索它时,您需要将其从 ByteArray 读取到位图中。这是一个快速示例,希望能让您朝着正确的方向前进:
http: //www.kirupa.com/forum/showthread.php?t=306972
In this case, you need to write your Bitmap to a ByteArray (in other words - binary data) before you set your shared object. Then you need to read it from a ByteArray into a bitmap when you retrieve it. Here is a quick sample the hopefully will get you moving in the right direction:
http://www.kirupa.com/forum/showthread.php?t=306972
不要忘记,共享对象的大小是有限的(默认为 100Kb)
Don`t forget, shared object has limited size (100Kb default)
往返于 SharedObject.data 的图像 - 简单、免费且随时可用的类,其中包括完整的 SharedObject 事件和状态逻辑:
向/从 SharedObject.data 的图像
Images to/from SharedObject.data - easy, free and ready to use class which includes full SharedObject events and status logic:
Images to/from SharedObject.data