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
wuya
Posts: 6
Registered: ‎11-28-2010
My Device: Not Specified

how to choose file?

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);
}
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: how to choose file?

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.

 

Please use plain text.
New Contributor
wuya
Posts: 6
Registered: ‎11-28-2010
My Device: Not Specified

Re: how to choose file?

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

 

1.jpg

 

2.jpg

 

SO what`s wrong?

Please use plain text.
New Contributor
wuya
Posts: 6
Registered: ‎11-28-2010
My Device: Not Specified

Re: how to choose file?

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.

Please use plain text.
New Member
to267224
Posts: 1
Registered: ‎12-12-2010
My Device: Not Specified

Re: how to choose file?

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

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: how to choose file?

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.

Please use plain text.