Skip to main content
Oct 13, 2011 8:05 PM UTC
Question

Mobile AIR - FileReference browse() & .zip

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 is closed to new replies. Start a new post to keep the conversation going.

6 replies

Inspiring
Dec 24, 2011 12:48 PM UTC

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

Translate
Dec 27, 2011 8:51 PM UTC

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?

Translate
Inspiring
Dec 29, 2011 10:27 AM UTC

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>

Translate
Dec 24, 2011 10:57 AM UTC

Hi,

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

Yvan

Translate