0

Intro - I am working on a iOS game using Flash CS5.5. In my game i am loading a image via the camera roll, and gonna use the image in the gameplay. I want the image to load back in when the user restarts the game.

Question - Is there a way to access such image again without having to open up the camera roll interface.

Can i use the flash.display.Loader class? Is there any special things i need to do or set? Or is there another way?

I've tried just saving the file, given from the MediaEvent dispatched when you select an image.

But i have no luck using the URL given in the loader object. I am using the example from this page as my base: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/CameraRoll.html.

4

1 回答 1

0

是的,这是可能的。您需要使用 File 类将图像保存到应用程序文档目录中,如下所示:(这使用 Adob​​e JPGEncoder 类)

f = File.documentsDirectory.resolvePath("logo.jpg"); 

stream = new FileStream();
stream.open(f, FileMode.WRITE);                                         

j = new JPGEncoder(80);
var bytes:ByteArray = j.encode(visualLogo.bitmapData);
stream.writeBytes(bytes,  0, bytes.length);
stream.writeBytes(bytes, 0, bytes.bytesAvailable);
stream.close();

//I read the file back in to test that it has been successfully written 
stream.openAsync(f, FileMode.READ); 
stream.addEventListener(Event.COMPLETE, bringBoardOn, false, 0, true);

然后使用以下内容将其加载回:

f = File.documentsDirectory.resolvePath ("logo.jpg");

if (f.exists == true) {

var _urlRequest:URLRequest = new URLRequest(f.url);
loader=new Loader;
loader.load(_urlRequest);
loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void{ trace(e) });
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ImageLoaded, false, 0, true);     
_urlRequest = null;

}
于 2012-06-01T07:22:50.480 回答