Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
New Developer
Posts: 8
Registered: ‎10-20-2009
My Device: Not Specified

how to save img

hi, I use the FileReference.save() to save img. but it throw

 Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error.

is there other way to save file, can anyone help, thank you.

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: how to save img

Can you post code that you are using to save the image?

What event listeners did you add to the class before saving?

You may have to add an event listener that listends for the IOError event to a function that does nothing (or show an alert to the user).

 

file_ref.addEventListener( IOErrorEvent.IO_ERROR, SaveError );

..

private function SaveError( event : IOErrorEvent ) : void

{

  // do nothing

}

New Developer
Posts: 8
Registered: ‎10-20-2009
My Device: Not Specified

Re: how to save img

here is my code, is anything wrong? package { import com.adobe.images.JPGEncoder; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.IOErrorEvent; import flash.events.MouseEvent; import flash.net.FileReference; [SWF(width="1024", height="600", backgroundColor="#FFFFFF", frameRate="30")] public class Main extends Sprite { private var testBitMap:BitmapData; private var bitmap:Bitmap; private var file:FileReference; private var jpg:JPGEncoder; private var btnSpriteSmiley Frustratedprite; public function Main() { testBitMap = new BitmapData(320,240,false,0x000000); bitmap = new Bitmap(testBitMap); btnSprite = new Sprite(); btnSprite.addChild(bitmap); addChild(btnSprite); btnSprite.addEventListener(MouseEvent.CLICK,btnDown); } private function btnDown(e:MouseEvent):void{ jpg = new JPGEncoder(100); file = new FileReference(); file.save(jpg.encode(testBitMap),"flash.jpg"); file.addEventListener(IOErrorEvent.IO_ERROR,error); } private function error(e:IOErrorEvent):void{ } } }
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: how to save img

Hi qioxko:

 

Could you repost your code using the [C] icon in the toolbar that does a clean layout of the code.  I cannot read it the way it is.

 

Thanks.

New Developer
Posts: 8
Registered: ‎10-20-2009
My Device: Not Specified

Re: how to save img

 

package
{
	import com.adobe.images.JPGEncoder;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.net.FileReference;
	
	[SWF(width="1024", height="600", backgroundColor="#FFFFFF", frameRate="30")]
	
	public class Main extends Sprite
	{
		private var testBitMap:BitmapData;
		private var bitmap:Bitmap;
		private var file:FileReference;
		private var jpg:JPGEncoder;
		private var btnSprite:Sprite;
		
		public function Main()
		{
			testBitMap = new BitmapData(320,240,false,0x000000);
			bitmap = new Bitmap(testBitMap);
			
			btnSprite = new Sprite();
			btnSprite.addChild(bitmap);
			addChild(btnSprite);
			btnSprite.addEventListener(MouseEvent.CLICK,btnDown);
		}
		
		private function btnDown(e:MouseEvent):void{
			trace("clicked");
			jpg = new JPGEncoder(100);
			file = new FileReference();
			file.save(jpg.encode(testBitMap),"flash.jpg"); 
			file.addEventListener(IOErrorEvent.IO_ERROR,error);
		}
		
		private function error(e:IOErrorEvent):void{
			
		}
	}
}

 

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: how to save img

You're still getting the error?

Is it just on the simulator or AIR as well?

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: how to save img

Move the event listener before the save call.

New Developer
Posts: 8
Registered: ‎10-20-2009
My Device: Not Specified

Re: how to save img

yes, still getting the error , i test it on simulate.

New Developer
Posts: 8
Registered: ‎10-20-2009
My Device: Not Specified

Re: how to save img

it works when i open the swf directly, but not works on the simulate

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: how to save img

People have been reporting issues with browsing on the simulator.  It is probably related to that.  I am certain some one will confirm the simulator issue within a day.

 

If it is an issue and it works in AIR, then assume that it will be fixed before the final release.  If you want to make certain BB is aware of the issue, submit a bug/issue report to the BB.