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 Contributor
Acrossfy
Posts: 8
Registered: ‎03-23-2011
My Device: Not Specified

File cannot be saved or opened in emulator, sdk 0.9.4

[ Edited ]

Hello. I have a trouble. I can't save and open files in my test application. I read a lot of topics and tried a lot of methods, but I can't get any good result. 

There is my code:

 

private function openFile(event:MouseEvent):void 
{
	var myFile:File = File.documentsDirectory;
	myFile.browseForOpen("Open");
	myFile.addEventListener(Event.SELECT, fileOpenSelected);
}

private function saveFile(event:MouseEvent = null):void 
{
	var myFile:File = File.documentsDirectory.resolvePath("file.txt");
	stream = new FileStream();
	stream.open(myFile, FileMode.UPDATE);
	var str:String;
	str = mainTextField.text;
	stream.writeUTFBytes(str);
	stream.close();
}

I'm using Flash Builder 4.0.1 and blackberry sdk 0.9.4.

Thanks in advance.

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: File cannot be saved or opened in emulator, sdk 0.9.4

There are many reports that browseForOpen does not work well on the simulator.  If you get it to work in AIR, you "might" be OK with the final SDK.  Otherwise, you might need to create your own file browser pane.

Please use plain text.
New Contributor
Acrossfy
Posts: 8
Registered: ‎03-23-2011
My Device: Not Specified

Re: File cannot be saved or opened in emulator, sdk 0.9.4

[ Edited ]

Thanks for the reply.

How do I check whether a file is saved on the simulator?

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: File cannot be saved or opened in emulator, sdk 0.9.4

Saved by your application?  The "exists" method in the class File would tell you.  Otherwise, you will need to traverse to it some how.  I think @peter has a thread on how to FTP into the PB, but I am not certain if that is still possible in the latest release (or how it is done has changed).

Please use plain text.
Developer
billfoust
Posts: 382
Registered: ‎05-19-2008
My Device: BlackBerry Torch
My Carrier: AT&T

Re: File cannot be saved or opened in emulator, sdk 0.9.4

i've made a few posts about this as well. Basiclly, you can't trust the File object that is given when the SELECTED event fires. My work-around was to simply get the filename portion of the selected file and then once-again use ResolvePath for the directory that you want to use. it locks the user into just one directory, but lets you use the Browse dialogs still.

Bill
-------------------------------------------
Check out my book on BlackBerry Development for Java.
And my other really really old book
My Apps: FlashKids
Please use plain text.
Contributor
Dinges
Posts: 21
Registered: ‎03-18-2011
My Device: Playbook
My Carrier: KPN

Re: File cannot be saved or opened in emulator, sdk 0.9.4

Also: what is important to keep in mind, is that lots of devices don't allow (full) acces to most folders. The documents directory for example, is often denied access, or in some cases, links to an SD card, that may not be present. It's best to use the applicationStorage directory, as most (all?) OS's will allow you full access to that.

 

So be careful not to depend on folders like documents or desktop!

Please use plain text.