0

FileReference actions work properly in my workspace but wont when installed in mobile/android phone.

Publish Settings:

  • Target - Air 3.2 for Android
  • Script - AS 3.0

Air for Android Settings: Checked the following

  • WRITE_EXTERNAL_STORAGE

Here's what's happening, I have 3 buttons calling the FileReference. One is the for browsing(.browse()) what to load(.load()). Here when I clicked the button for browse, it will prompt "No files selected" even I haven't selected yet. The browse dialog wont even show.

In saving(.save()), it won't show the save dialog box.

Any idea whats happening? all of those are working fine in Flash Pro before publishing

  • Could you show us your code because we don't know when "No files selected" prompt is displayed ? Did you tried to add some event listeners for IOError and SecurityError events ? Did you tried your project with another Android device, may be the problem is with your device ? – akmozo Feb 03 '15 at 19:26

1 Answers1

0

From the AS3 documentation:

Note: In Adobe AIR, the File class, which extends the FileReference class, provides more capabilities and has less security restrictions than the FileReference class.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html

Try something like:

import flash.filesystem.*;

var _file:File = File.applicationStorageDirectory.resolvePath("yourfile.xml");

var _readFileStream:FileStream = new FileStream();

_readFileStream.open(Main._file, FileMode.READ);

var _loadedData:String = String(_readFileStream.readUTFBytes(_readFileStream.bytesAvailable));
_readFileStream.close();

trace(_loadedData);

and to save

var _file:File = File.applicationStorageDirectory.resolvePath("yourfile.xml");

var _writeFileStream:FileStream = new FileStream();

_writeFileStream.open(Main._file, FileMode.WRITE);

_writeFileStream.writeUTFBytes(_loadedData);

_writeFileStream.close();
crooksy88
  • 3,849
  • 1
  • 24
  • 30
  • can you specify where is load, browse, save in the code sir? :D – user3346921 Feb 04 '15 at 09:10
  • What kind of file are you wanting to load and save? – crooksy88 Feb 04 '15 at 13:20
  • xml file sir. I want that when the user clicks load he can browse what file he wanted to load – user3346921 Feb 06 '15 at 11:40
  • You cannot browse the file system on mobile in the same way you can on the desktop. You would have to create your own browsing UI. Scan a folder to get its contents then display those results in a scrollable list. Select an item from the list and load/save it using the AS3 above. – crooksy88 Feb 06 '15 at 15:13