02-27-2011 10:30 AM
Hi,
i need user to select image using browse dialog.
My Problem is: browse dialog in simulator is always empty, no files on it...
After resarch i enabled the share folder in simulator and add 2 folders contain images and still noo way always empty... tried file.browse and file.browseForOpen and noo way.
Note: it's working great outside simulator ( Air )
please suggest. Thanks a lot
Simulator and SDK ( 0.9.3 )
Solved! Go to Solution.
02-27-2011 10:44 AM
The browse feature in the simulator is buggy at best. Will need to wait for an updated simulator. Hopefully in a week or 2.
02-27-2011 11:49 AM
No way in current sdk ??
02-27-2011 11:57 AM
I would do some more searches on this forum. There are many threads on this. Some of found some work arounds. There was one thread that one developer wrote their own file browser.
02-27-2011 11:58 AM
The filesystem does not come with any files pre-loaded onto it. The file browse dialogs DO work, but they ARE buggy. I have an app that opens a file and I can see the image thumbnails in the browse dialog just fine. I had to place all of those files there myself though through my app's save process.
If you want to pre-load imagesinto the documents directory for testing, I would suggest making another 'helper' app that embeds some images into the project, and will save those images into the documents directory when you press a button or something. Then you can close the helper app and run your real application to load the files in.
Here is a recent thread where I worked through some of the difficulties I had in working with the browse dialogs that might help.
Bill
02-27-2011 02:45 PM
My Code, i tried many things and still no files in open dialog... ![]()
import mx.graphics.codec.JPEGEncoder; import flash.filesystem.*; import flash.events.Event; import flash.net.FileFilter; import flash.events.MouseEvent; open_btn.addEventListener(MouseEvent.CLICK,openMe); save_btn.addEventListener(MouseEvent.CLICK,saveMe) ; ////////////////////////////////; //Save////////////////////////// //////////////////////////////// var docsDir:File = File.applicationStorageDirectory; function saveMe(e:MouseEvent) { try { docsDir.browseForSave("Save As"); docsDir.addEventListener(Event.SELECT, saveData); } catch (error:Error) { trace("Failed:", error.message); } } function saveData(event:Event):void { var bitmapData:BitmapData = new BitmapData(pic.width,pic.height); bitmapData.draw(pic,new Matrix()); var bitmap:Bitmap = new Bitmap(bitmapData); var jpg:JPEGEncoder = new JPEGEncoder(); var imageByteArray:ByteArray = jpg.encode(bitmapData); var newFile:File = event.target as File; //check extension if exist or no var len:int = (newFile.extension != null) ? newFile.extension.length : 0; if(len) { newFile.nativePath = newFile.nativePath.substr(0,newFile.nativePath.len gth-len) + "jpg"; }else{ newFile.nativePath += ".jpg"; } if (! newFile.exists) { var stream:FileStream = new FileStream(); stream.open(newFile, FileMode.WRITE); stream.writeBytes(imageByteArray, 0, imageByteArray.length); stream.close(); } } //////////////////////////////// //Open////////////////////////// //////////////////////////////// var fileToOpen:File = File.applicationStorageDirectory; function openMe(e:MouseEvent) { try { fileToOpen.browseForOpen("Open", []); fileToOpen.addEventListener(Event.SELECT, chooseFile); } catch (error:Error) { trace("Failed:", error.message); } } function chooseFile(event:Event):void { fileToOpen.removeEventListener(Event.SELECT, chooseFile); fileToOpen.addEventListener(Event.COMPLETE, loadCompleteHandler); fileToOpen.load(); } function loadCompleteHandler(event:Event):void { fileToOpen.removeEventListener(Event.COMPLETE, loadCompleteHandler); var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loadBytesHandler); loader.loadBytes(fileToOpen.data); } function loadBytesHandler(event:Event):void { var loaderInfo:LoaderInfo = (event.target as LoaderInfo); loaderInfo.removeEventListener(Event.COMPLETE, loadBytesHandler); //load image target pic.ui_mc.source = loaderInfo.content; }
02-27-2011 02:55 PM
Look at the .nativePath and .url methods in the browser select callbacks. They are not the same. Basically, you can't trust the FILE objects returned by the browse methods. Here's my code I'm using.
private function save(e:MouseEvent):void
{
trace("saving");
var myFile:File = File.documentsDirectory;
myFile.browseForSave("Save Image");
myFile.addEventListener(Event.SELECT, chooseSave);
menu.close();
}
private function chooseSave(e:Event):void
{
var sel:File = e.target as File;
var name2:File = File.documentsDirectory.resolvePath(sel.name);
trace (sel.nativePath);
trace (name2.nativePath);
// create data to save...
var file:FileStream = new FileStream();
file.open(name2, FileMode.WRITE);
file.writeBytes(data);
file.close();
}
Basically, I only use the browse dialogs as a way to let the user enter a filename, or select a filename. Then, I create a new FILE object using the documentsDirectory path and the selected filename.
This isn't ideal, but it works. The user can't change directories and its not in one of the 'predefined' subdirs. I expect this will need to be changed when we get the next rev of the SDK and the browse dialogs are (hopefully) fixed.
Bill
02-27-2011 03:37 PM
Amazing
Finallyyyyyyyyyyyyy FIXED
Thanks a lot Billfoust (Y)
04-28-2011 12:17 AM
I traced out the File.applicationStorageDirectory.nativePath and it showed:
/accounts/1000/appdata/LoadImage.debug.testYWRJbWF
I came across another thread regarding SFTP transfer. Are these two methods (SFTP/write the image from a helper app) the only ways to put an image into the PlayBook Simulator's (1.0.1) shared media directory so the image can be loaded into an app using the CameraRoll API?