12-06-2010 09:58 AM
I want choose a *.txt ,file.
when I click the button,
I use the code ,but it don not work.
So how can I choose the file?
private function click_open():void{
var file:File=new File();
var filter:FileFilter=new FileFilter("TXT","*.txt");
file.browseForOpen("Open",[filter]);
file.addEventListener(Event.SELECT,fileselect);
}
private function fileselect(evt:Event):void{
trace(evt.target.nativePath);
trace(evt.target.name);
}
12-06-2010 10:12 AM
Try placing the variable 'file' as an attribute of the class instead of a variable of the function. The local variable file loses scope once the function is done. Having the scope of the variable global to that class should resolve the issue.
public class MyClass extends Something
{
private var _file : File = null;
public function MyClass()
{
super();
}
private function DoOpen() : void
{
this._file = new File();
var filter : FileFilter = new FileFilter( 'TXT, '*.txt' );
this._file.browseForOpen( 'Open', [filter] );
this._file.addEventListener( Event.SELECT, DoSelection );
}
private function DoSelection( event : Event ) : void
{
trace( event.target.nativePath );
}
}
Not tested: Pseudo code.
12-06-2010 09:52 PM
yes,I use it.But when I debug ,it`s black.
...
private function button_click(evt:MouseEvent):void{
switch (evt.target.name){
case "open":
click_open();
break;
default:
break;
}
}
private function click_open():void{ trace("open"); this._file = new File(); var filter : FileFilter = new FileFilter( 'TXT', '*.txt' ); this._file.browseForOpen( 'Open', [filter] ); this._file.addEventListener( Event.SELECT, fileselect ); } private function fileselect(evt:Event):void{ trace(evt.target.nativePath); trace(evt.target.name); }
...
when I click button,it say "open".but.....
like this
SO what`s wrong?
12-06-2010 10:05 PM
I`m sorry to click the Solution.
————————————————
when I use AIR SDK in PC desktop ,it`s OK.
but use blackberry SDK in blackberry Playbook,it can`t work,can`t browse any file.
I wrong or something wrong.
12-12-2010 11:32 AM
I'm looking forward to see some solutions - it seems that playbook device only accepts multimedia files. If you specify in FileFilter object the image file extensions - "jpg , png, ... " - then the browse dialog show the image gallery. But if you specify some other extension, for ex. "abc" then the dialog is empty and there's nothing to click , as on the screenshot above.
So maybe:
- There exists some other, not-standard solution on how to open a "browse..." dialog
- due to security reasons, users can only open image files (?!?)
- there's a bug in the sdk
12-12-2010 12:22 PM
There might be some security/sanbox related to this. I have an app the reads a directory of images that were installed with the application. It can read the directory fine, but when I try to load one of the images using its nativePath, it will not load (works fine as an AIR application). If I truncate the nativePath to be just the local part, it loads fine. I think it saw the full path and thinks I am trying to open a file outside of my application space. Bug or feature? Who knows.