12-11-2012 10:07 PM - edited 12-12-2012 12:14 AM
Alright, I'm trying to save a png file that I've loaded using loader from the internet.
Here is the code:
...
public var TempImage:BitmapData;
...
var loader:Loader = new Loader();
var url:String = new String('http://myurl.com/image.png');
...
LoadImage();
function addLoader():void{
addChild(loader);
}
function LoadImage():void {
var urlReq:URLRequest = new URLRequest(url);
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loader_complete);
loader.contentLoaderInfo.addEventListener(IOErrorE vent.IO_ERROR, loader_err);
loader.load(urlReq);
addLoader();
}
function loader_complete(evt:Event):void {
var target_mc:Loader = evt.currentTarget.loader as Loader;
var TempImage1:Bitmap = Bitmap(target_mc.content);
TempImage = TempImage1.bitmapData;
target_mc.x = (stWidth - stWidth) + 15;
target_mc.y = (stHeight - 15) - 165;
}
...
Button Code for Save button
...
function SAVE(e:Event):void{
file = new FileReference();
var SaveString:String =- new String('myImage.png');
file.save(TempImage, SaveString);
file.addEventListener(IOErrorEvent.IO_ERROR,saveEr ror);
file.addEventListener(Event.COMPLETE, Complete);
file.addEventListener(Event.CANCEL, Complete);
}
...
The Image (loader) Gets added to the stage successfully, the SaveString works fine, I have file system access using "access_shared", save prompt works...
The Issue is that The saved image (TempImage) contains no data, I've tried countless variatioins of getting the loader data into a "temp" image but without luck.
Any ideas?
Solved! Go to Solution.
12-12-2012 12:27 AM
I've found a solution based on my own code from a previous app.
I used PNGEncoder to encode the TempImage in the SAVE function prior to the actual saving.