Skip to main content
October 13, 2011
Question

Mobile AIR - FileReference browse() & .zip

  • October 13, 2011
  • 2 replies
  • 5329 views

I am trying to load a zip file which is in /mnt/sdcard/download/ on my Android phone. Using the following code:

m_fileReference = new flash.net.FileReference();

m_fileReference.browse();

But when I open the app and browse I am only able to see video, audio and image files. Does anybody know how I can load a zip file?

Thanks

--Matt

This topic has been closed for replies.

2 replies

Inspiring
December 24, 2011

You have to write your own simple file browser with File class (not FileReference)

December 27, 2011

I tried to use the File.browseForOpen with and without extension filters but I am getting either a No file found message or the choice with audio/video/picture files only. Am I missing something?

Inspiring
December 29, 2011

It is not so easy... You have to actualy make your own view for viewing and selecting files on the sd card. You can do this easily by passing objects between views. Try this for a start (works on my android phone):

<?xml version="1.0" encoding="utf-8"?>

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                    xmlns:s="library://ns.adobe.com/flex/spark"

                    title="Browse"

                    creationComplete="init();">

          <fx:Script>

                    <![CDATA[

                              import mx.collections.ArrayCollection;

 

                              [Bindable] private var currentDirectory:File;

                              [Bindable] private var files:ArrayCollection;

 

                              private var returnObject:Vector.<File>;

 

                              override public function createReturnObject():Object{

                                        return returnObject;

                              }

 

                              private function init():void{

                                        changeDir( File.desktopDirectory );

                              }

 

                              private function changeDir(file:File):void{

                                        if(file.isDirectory){

                                                  var parent:File = file.parent;

 

                                                  currentDirectory = file;

 

                                                  files = new ArrayCollection( currentDirectory.getDirectoryListing().sort(fileSort) );

                                        }

                              }

 

                              private function fileSort(file1:File, file2:File):int{

                                        if(file1.isDirectory && !file2.isDirectory)

                                                  return -1;

                                        else if(!file1.isDirectory && file2.isDirectory)

                                                  return 1;

                                        else

                                                  return file1.name.localeCompare( file2.name );

                              }

 

                              private function doubleClick():void{

                                        if(fileList.selectedItem == null)

                                                  return;

 

                                        var selectedFile:File = fileList.selectedItem;

 

                                        if(selectedFile.isDirectory)

                                                  changeDir(selectedFile);

                                        else{

                                                  returnObject = new <File>[ selectedFile ];

 

                                                  navigator.popView();

                                        }

                              }

 

                              private function up():void{

                                        changeDir( currentDirectory.parent );

                              }

                    ]]>

          </fx:Script>

 

          <s:VGroup width="100%"

                                height="100%">

                    <s:Button label="Up"

                                          click="up();"

                                          width="100%"

                                          enabled="{currentDirectory.parent != null}"/>

 

                    <s:List id="fileList"

                                        width="100%"

                                        height="100%"

                                        dataProvider="{files}"

                                        doubleClick="doubleClick();"

                                        doubleClickEnabled="true"

                                        labelField="name">

                    </s:List>

          </s:VGroup>

</s:View>

December 24, 2011

Hi,

If by any chance you got your answer, I'm very interested with it.

Yvan