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
Contributor
mokayyali
Posts: 10
Registered: ‎01-20-2011
My Device: Not Specified
Accepted Solution

FileReference Browse issue

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 )

 

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: FileReference Browse issue

The browse feature in the simulator is buggy at best.  Will need to wait for an updated simulator.  Hopefully in a week or 2.

Please use plain text.
Contributor
mokayyali
Posts: 10
Registered: ‎01-20-2011
My Device: Not Specified

Re: FileReference Browse issue

:smileysad: No way in current sdk ??

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: FileReference Browse issue

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.

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

Re: FileReference Browse issue

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

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
mokayyali
Posts: 10
Registered: ‎01-20-2011
My Device: Not Specified

Re: FileReference Browse issue

My Code, i tried many things and still no files in open dialog... :smileysad:

 

 

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.length-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.COMPLETE, 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;
}

 

 

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

Re: FileReference Browse issue

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

 

 

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
mokayyali
Posts: 10
Registered: ‎01-20-2011
My Device: Not Specified

Re: FileReference Browse issue

Amazing :smileyvery-happy: Finallyyyyyyyyyyyyy FIXED :smileyvery-happy: Thanks a lot Billfoust (Y) 

 

 

 

Please use plain text.
Contributor
ElliotMebane
Posts: 21
Registered: ‎03-15-2011
My Device: Playbook
My Carrier: None

Re: FileReference Browse issue

I traced out the File.applicationStorageDirectory.nativePath and it showed:

/accounts/1000/appdata/LoadImage.debug.testYWRJbWFnZS5kZWJ1ZyAgICA/data

 

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? 

 


PlayBook App: Flash Performance Tester
http://appworld.blackberry.com/webstore/content/38476
Please use plain text.