I've got some UIloader in my AS3 code that displays images via web link.
uiloader1.source = "http://www.mywebsite/image1.jpg";
uiloader2.source = "http://www.mywebsite/image2.jpg";
Once the user have open the app with an internet connection, I'd like him to be able to open it again without any internet connection but still have the possibility to display the images.
I thought about something like :
var savedImage:SharedObject;
savedImage= SharedObject.getLocal("ImagesFolder");
if (monitor.available || savedImage.data.images == "null") {
uiloader1.source = "http://www.mywebsite/image1.jpg";
uiloader2.source = "http://www.mywebsite/image2.jpg";
savedImage.data.loader1 = uiloader1.source;
savedImage.data.loader2 = uiloader2.source;
}
else {
uiloader1.source = savedImage.data.loader1;
uiloader2.source = savedImage.data.loader2;
}
But it doesn't work as it saves the link of the image and not the actual image.
Any idea how can I save the images into a file and told uiloader1.source
and uiloader2.source
to load them ?
EDIT
So I've tried that :
uiloader10.source = "http://www.myWebsite/image1.jpg";
uiloader10.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void {
var bitmapData:BitmapData = new BitmapData(uiloader10.width,uiloader10.height);
bitmapData.draw(uiloader10);
var jpgencoder:JPGEncoder = new JPGEncoder(100);
var mybyte:ByteArray = jpgencoder.encode(bitmapData);
var myfile:FileReference = new FileReference();
myfile.save(mybyte,"test.jpg");
}
It seems to work (test it on desktop, not on my phone device yet).
1/But you think I shouldn't do that for an AIR app ? Could you show me the code I should change in order to make it more "app compatible" please ?
2/ How do I do to load the file in a Uiloader (how can retrieve automatically the path ?"
Example : I've tried uiloader11.source = "test.jpg";
but error : Unhandled ioError:. text=Error #2035: URL Not Found. URL: app:/test.jpg