Skip navigation
Currently Being Moderated

How do I get the Open Dialog on Android ICS 4.0?

Jul 2, 2012 6:46 PM

Hi,

 

I am using Flash CS6, Android setup, 3.0 AS

I have a Galaxy Tab, ICS 4.0 for a device

 

I can read & write a text file perfectly fine on my PC.

 

But, when I upload to my Galaxy Tab 2 (7")....

 

1) I get a generic dialog that displays my path (/mnt/sdcard/) ... And it also displays "Audio, Image, Video" options. It says "Download" as a diaglog title.

 

I can save the file perfectly fine.

 

2) When I try to open, it only displays the "Audio, Image, Video" options BUT DOES NOT allow me to open the file I saved.

 

SO, HOW DO I GET A DIALOG THAT ALLOWS ME TO BROWSE TO THE FILE I SAVED??

 

Screenshot_NoOpenDialog.jpg

 

Here is my code...

 

package com.adobe.examples

{

          import flash.display.Sprite;

          import flash.filesystem.*;

          import flash.events.*;

          import flash.system.Capabilities;

          import flash.text.TextFormat;

 

          import fl.controls.Button;

          import fl.controls.TextArea;

 

          //import flash.net.FileFilter;

 

          public class TextEditorFlash extends Sprite

          {

                    //Fwhilton added

                    //var fileToOpen:File = new File();

                    //var txtFilter:FileFilter = new FileFilter("Text *.txt", "*.txt");

 

 

                    // The currentFile opened (and saved) by the application

                    private var currentFile:File;

 

                    // The FileStream object used for reading and writing the currentFile

                    private var stream:FileStream = new FileStream();

 

                     // The default directory

                    private var defaultDirectory:File;

 

                    // Whether the text data has changed (and should be saved)

                    public var dataChanged:Boolean = false;

 

 

                    public function TextEditorFlash()

                    {

                              trace("TextEditor()");

 

                              defaultDirectory = File.documentsDirectory;

                              //Fwhilton added

                              //defaultDirectory = File.documentsDirectory.resolvePath("testapps/");

 

                              newBtn.addEventListener(MouseEvent.CLICK,newFile);

                              openBtn.addEventListener(MouseEvent.CLICK,openFile);

                              saveBtn.addEventListener(MouseEvent.CLICK,saveFile);

                              saveAsBtn.addEventListener(MouseEvent.CLICK,saveAs);

 

                              var tf:TextFormat = new TextFormat();

                              tf.font = "Courier New";

                              tf.size = "16";

                              mainTextField.setStyle("textFormat",tf);

                    }

 

                    /**

                    * Called when the user clicks the Open button. Opens a file chooser dialog box, in which the

                    * user selects a currentFile.

                    */

                    private function openFile(event:MouseEvent):void

                    {

                              var fileChooser:File;

                              if (currentFile)

                              {

                                        fileChooser = currentFile;

                              }

                              else

                              {

                                        fileChooser = defaultDirectory;

                              }

                              fileChooser.browseForOpen("Open");

                              fileChooser.addEventListener(Event.SELECT, fileOpenSelected);

                    }

                    /**

                    * Called when the user selects the currentFile in the FileOpenPanel control. The method passes

                    * File object pointing to the selected currentFile, and opens a FileStream object in read mode (with a FileMode

                    * setting of READ), and modify's the title of the application window based on the filename.

                    */

                    private function fileOpenSelected(event:Event):void

                    {

                              currentFile = event.target as File;

                              stream = new FileStream();

                              stream.openAsync(currentFile, FileMode.READ);

                              stream.addEventListener(Event.COMPLETE, fileReadHandler);

                              stream.addEventListener(IOErrorEvent.IO_ERROR, readIOErrorHandler);

                              dataChanged = false;

                              currentFile.removeEventListener(Event.SELECT, fileOpenSelected);

                    }

                    /**

                    * Called when the stream object has finished reading the data from the currentFile (in the openFile()

                    * method). This method reads the data as UTF data, converts the system-specific line ending characters

                    * in the data to the "\n" character, and displays the data in the mainTextField Text component.

                    */

                    private function fileReadHandler(event:Event):void

                    {

                              var str:String = stream.readUTFBytes(stream.bytesAvailable);

                              stream.close();

                              var lineEndPattern:RegExp = new RegExp(File.lineEnding, "g");

                              str = str.replace(lineEndPattern, "\n");

                              mainTextField.text = str;

                              stream.close();

                    }

                    /**

                    * Called when the user clicks the "Save" button. The method sets up the stream object to point to

                    * the currentFile specified by the currentFile object, with save access. This method converts the "\r" and "\n" characters

                    * in the mainTextField.text data to the system-specific line ending character, and writes the data to the currentFile.

                    */

                    private function saveFile(event:MouseEvent = null):void

                    {

                              if (currentFile) {

                                        if (stream != null)

                                        {

                                                  stream.close();

                                        }

                                        stream = new FileStream();

                                        stream.openAsync(currentFile, FileMode.WRITE);

                                        stream.addEventListener(IOErrorEvent.IO_ERROR, writeIOErrorHandler);

                                        var str:String = mainTextField.text;

                                        str = str.replace(/\r/g, "\n");

                                        str = str.replace(/\n/g, File.lineEnding);

                                        stream.writeUTFBytes(str);

                                        stream.close();

                                        dataChanged = false;

                              }

                              else

                              {

                                        saveAs();

                              }

                    }

                    /**

                    * Called when the user clicks the "Save As" button. Opens a Save As dialog box, in which the

                    * user selects a currentFile path. See the FileSavePanel.mxml currentFile.

                    */

                    private function saveAs(event:MouseEvent = null):void

                    {

                              var fileChooser:File;

                              if (currentFile)

                              {

                                        fileChooser = currentFile;

                              }

                              else

                              {

                                        fileChooser = defaultDirectory;

                              }

                              fileChooser.browseForSave("Save As");

                              fileChooser.addEventListener(Event.SELECT, saveAsFileSelected);

                    }

                    /**

                    * Called when the user selects the file path in the Save As dialog box. The method passes the selected

                    * currentFile to the File object and calls the saveFile() method, which saves the currentFile.

                    */

                    private function saveAsFileSelected(event:Event):void

                    {

                              currentFile = event.target as File;

                              saveFile();

                              dataChanged = false;

                              currentFile.removeEventListener(Event.SELECT, saveAsFileSelected);

                    }

                    /**

                    * Called when the user clicks the "New" button. Initializes the state, with an undefined File object and a

                    * blank text entry field.

                    */

                    private function newFile(event:MouseEvent):void

                    {

                              currentFile = undefined;

                              dataChanged = false;

                              mainTextField.text = "";

                    }

                    /**

                    * Handles I/O errors that may come about when opening the currentFile.

                    */

                    private function readIOErrorHandler(event:Event):void

                    {

                              trace("The specified currentFile cannot be opened.");

                    }

                    /**

                    * Handles I/O errors that may come about when writing the currentFile.

                    */

                    private function writeIOErrorHandler(event:Event):void

                    {

                              trace("The specified currentFile cannot be saved.");

                    }

          }

}

 
Replies
  • Currently Being Moderated
    Jul 8, 2012 11:18 PM   in reply to fwhilton

    It is impossible with just AIR. If you do not want to user native extensions you can easily implement a simple file browser with File class.

     

    Try this: http://forums.adobe.com/message/4107990#4107990

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 10, 2012 1:49 AM   in reply to fwhilton

    I forgot you are using CS6, and not flex... Then just use the logic in the script tag and create an interface for the files yourself.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points