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
Developer
Posts: 194
Registered: ‎11-12-2010
My Device: Not Specified

Re: Specifying a target folder for File.browse()

Sorry to be going on about this, but I still don't really understand ...

 

Actually, thinking about it, I still find it strange that your code works and am wondering how it would work for the voice directory, seeing that there is nothing in thecode that actually specifies *where* you want to look for the files:

 

var musicFile:File = File.userDirectory;
musicFile.addEventListener(Event.SELECT, onFileSelect);
var musicFilter:FileFilter = new FileFilter("Music", "*.mp3");
musicFile.browseForOpen("Choose a song", [musicFilter]);

 the only possible hint would be the FileFilter description "Music", but that's a free form String (not a String constant), so somebody else might pick the description "Songs", and presumably it shouldn't make any difference to Flash ...   So what would I actually change to go to the Voice directory. The file type is *.m4a, but there are lots of music files in .m4a too, so how does the system know in which directory I want to look?

Developer
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

Re: Specifying a target folder for File.browse()

Oops, my code doesn't work like you wanted.  It tested the code below: 

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	import flash.filesystem.File;
	import flash.net.FileFilter;
	
	import qnx.fuse.ui.buttons.LabelButton;
	import qnx.fuse.ui.text.Label;
	import qnx.fuse.ui.theme.ThemeGlobals;
	
	[SWF(backgroundColor="0x323232")]
	public class BrowseTargetDemo extends Sprite
	{
		private static const MARGIN:int = 10;
		
		public function BrowseTargetDemo()
		{
			super();
			initStage();
			initUI();
		}
		
		private function initStage():void
		{
			ThemeGlobals.currentTheme = ThemeGlobals.BLACK;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
		}
		
		private function initUI():void
		{
			var musicButton:LabelButton = new LabelButton();
			musicButton.label = "Music";
			musicButton.x = MARGIN;
			musicButton.y = MARGIN;
			addChild(musicButton);
			var voiceButton:LabelButton = new LabelButton();
			voiceButton.label = "Voice";
			voiceButton.x = MARGIN*2 + musicButton.width;
			voiceButton.y = MARGIN;
			addChild(voiceButton);	
			musicButton.addEventListener(MouseEvent.CLICK, onMusic);
			voiceButton.addEventListener(MouseEvent.CLICK, onVoice);
		}
		
		private function onVoice(event:MouseEvent):void
		{
			var voiceFile:File = File.userDirectory.resolvePath("shared/voice/");
			trace(voiceFile.nativePath);
			var voiceFilter:FileFilter = new FileFilter("Voice", "*.m4a");
			voiceFile.browseForOpen("Choose a voice note", [voiceFilter]);
		}
		
		private function onMusic(event:MouseEvent):void
		{
			var musicFile:File = File.userDirectory.resolvePath("shared/music/");;
			trace(musicFile.nativePath);
			var musicFilter:FileFilter = new FileFilter("Music", "*.m4a;*.mp3");
			musicFile.browseForOpen("Choose a song", [musicFilter]);
		}
	}
}

 

 Both open dialogs show the same m4a files, regardless of the folder their in (voice or music). Using browse instead of browseForOpen gives the exact same result. It does always show the music tab though, so perhaps that was fixed in the OS2 beta.

 

Seems to me that both browse and browseForOpen just ignore your starting (or target) directory, which is obviously not expected or wanted behavior. You may want to submit an issue about this.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Posts: 194
Registered: ‎11-12-2010
My Device: Not Specified

Re: Specifying a target folder for File.browse()

Thanks so much for helping me to get to the bottom of this! So it looks like it's just guessing on the basis of the extensions you're looking for, which folder to send you to - not quite good enough for real life ... I'll submit a request to have this solved.

 

But one more question: has the layout of the Browse dialog changed at all in OS 2 ?  (Because in OS 1 the user simply cannot navigate at all to the Voice directory - all they get to choose from is Pictures, Video, Music and Documents (see screenshot posted earlier in this thread))

 

Thanks again

Anna

 

 

Developer
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

Re: Specifying a target folder for File.browse()

The layout is still the same.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Highlighted
Developer
Posts: 194
Registered: ‎11-12-2010
My Device: Not Specified

Re: Specifying a target folder for File.browse()

Ok, with everybody's help (thanks zezke!) I've finally figured it out:

 

OS 1 always opens the Browse dialog to look for 'Documents', regardless of the location of the File instance that's calling browse() (or any of it's relatives, like browseForOpen() etc.), and regardless of any extension filters - that's a bug and seems to be fixed in OS 2.

 

Even in OS 2 you cannot request to specifically browse the Voice directory, or the Downloads directory etc., nor can the user navigate to any specific folder. But I just realized for the first time (oops!) that the four tabs at the top of the dialog ('Pictures', 'Video', "Music', 'Documents') have nothing to do with the *directories* of the same name, but they group *all* files in the Shared directory by their file type ('Documents' being a kind of catch-all). So voice notes, for example, can actually be found under 'Music', you just have to scroll down far enough or search vor "VN" ...  Personally I'd much prefer a good old-fashioned directory tree, but that's not a bug, that's more to do with RIM's assumptions about their users, and I guess they must have their reasons. 

 

Not exactly a solution, but at least a conclusion that clears up my confusion ... :-)

 

Thanks again, for helping me investigate!