Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Open external content on Air As3 App

Community Beginner ,
Feb 03, 2017 Feb 03, 2017

Hello everyone!

Since Wednesday i keep searching for the solution of a problem.

My app loads a document from the smartphone SD Card, with this code:

var file_lista:File=File.documentsDirectory.resolvePath("/sdcard/lista.xml");

var fileStream:FileStream = new FileStream();

try {

  fileStream.open(file_lista, FileMode.READ);

  texto.text="Filestream activado";

} catch(e:Error) {

  texto.text=e.message;

}

It gives me the error 3001 - Folder or file acess denied, but i have already written the permission on manifest:

<manifestAdditions><![CDATA[<manifest>

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

</manifest>]]></manifestAdditions>

  </android>

And it continues to give me that error.

I can't find what's going on.

Can you help me?

TOPICS
ActionScript
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 03, 2017 Feb 03, 2017

try:

  1. var fileStream_write:FileStream=newFileStream();
  2. fileStream_write.open(file_lista,FileMode.WRITE);
  3. texto.text="FilestreamWRITEactivado\n";
  4. fileStream_write.addEventListener(Event.CLOSE,closeF);
  5. fileStream_write.close();

function closeF(e:Event):void{

  1. var fileStream_read:FileStream=newFileStream();
  2. fileStream_read.open(file_lista,FileMode.READ);
  3. texto.text+="Filestreamreadactivado";
  4. var prefsXML:XML=XML(fileStream_read.readUTFBytes(fileStream_read.bytesAvailable));
  5. // do something here to test if pref
...
Translate
Community Expert ,
Feb 03, 2017 Feb 03, 2017

that should be WRITE_EXTERNAL_STORAGE

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 03, 2017 Feb 03, 2017

Nop, because i have tried with both (read and write) and didn't worked.

Do you see any other possible solution?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2017 Feb 03, 2017

oh, i didn't even know there was a READ_EXTERNAL_STORAGE, but after looking on Manifest.permission | Android Developers i see there is.

so you need both to read and write.

and the same app that writes would need to read, not different apps.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 03, 2017 Feb 03, 2017

Ok, thank you, but i have both (Write and Read) and doesn't work.

My app doesn't write, just read the file.

i am trying to troubleshoot accessing the file throught another source.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2017 Feb 03, 2017

i don't think you'll be able to use the same path to read the file unless you the app that writes the file also reads it.

understand?

test by having the xml writing app also read the xml.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 03, 2017 Feb 03, 2017

Ok, now i understood.

I have tried this way and creating two stream variables (one for read stream and another for write stream):

try {

  stream.open(file_lista, FileMode.WRITE);

  texto.text+="Filestream WRITE activado \n";

} catch(e:Error) {

  texto.text+=e.message;

}

try {

  stream.open(file_lista, FileMode.READ);

  texto.text+="Filestream read activado";

} catch(e:Error) {

  texto.text+=e.message+"\n";

}

var prefsXML:XML = XML(stream.readUTFBytes(stream.bytesAvailable));

stream.close();

None of both worked fine.

Now i will try this way:Reading from and writing to an XML preferences file | Adobe Developer Connection

Edit:

var fileStream_write:FileStream = new FileStream();

  fileStream_write.open(file_lista, FileMode.WRITE);

  texto.text="Filestream WRITE activado \n";

  fileStream_write.close();

var fileStream_read:FileStream = new FileStream();

  fileStream_read.open(file_lista, FileMode.READ);

  texto.text+="Filestream read activado";

var prefsXML:XML = XML(fileStream_read.readUTFBytes(fileStream_read.bytesAvailable));

fileStream_read.close();

This way, does not work either.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2017 Feb 03, 2017

try:

  1. var fileStream_write:FileStream=newFileStream();
  2. fileStream_write.open(file_lista,FileMode.WRITE);
  3. texto.text="FilestreamWRITEactivado\n";
  4. fileStream_write.addEventListener(Event.CLOSE,closeF);
  5. fileStream_write.close();

function closeF(e:Event):void{

  1. var fileStream_read:FileStream=newFileStream();
  2. fileStream_read.open(file_lista,FileMode.READ);
  3. texto.text+="Filestreamreadactivado";
  4. var prefsXML:XML=XML(fileStream_read.readUTFBytes(fileStream_read.bytesAvailable));
  5. // do something here to test if prefsXML is defined
  6. fileStream_read.close();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 03, 2017 Feb 03, 2017

Thank You!

We have made good progress!

This way, the filestream WRITE, works:

var fileStream_write:FileStream=new FileStream();

try {

  fileStream_write.open(file_lista,FileMode.WRITE);

}

catch (e:Error){

  texto.text+=e.message;

}

texto.text="Filestream WRITE activado \n";

fileStream_write.addEventListener(Event.CLOSE, closeF);

fileStream_write.close();

But there is something wrong with the listenner.

I am trying to figure it out what.

Thank you, once more!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2017 Feb 03, 2017

you're welcome.

p.s. make sure fileStream_write is defined outside a function body

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 04, 2017 Feb 04, 2017

Unfortunatelly, we are just closer!

It doesn't block but doesn't work either:

It only "fires" an event if i make the stream to be asynchronously.

I have made a listenner for the errors, and guess what: Returns the same error: File/ folder Acess denied

try {

  fileStream_write.openAsync(file_lista,FileMode.WRITE); 

  fileStream_write.addEventListener(Event.COMPLETE, closeF); 

  fileStream_write.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

catch (e:Error){ 

  texto.text+=e.message; 

texto.text="Filestream WRITE activado \n"; 

 

function closeF(e:Event):void{

  texto.text="ADS";

  fileStream_write.close();

  var fileStream_read:FileStream=new FileStream();

  fileStream_read.open(file_lista,FileMode.READ);

  texto.text+="Filestream Read activado";

  var prefsXML:XML=XML(fileStream_read.readUTFBytes(fileStream_read.bytesAvailable));

  // do something here to test if prefsXML is defined

  fileStream_read.close();

  }

Once more, can you help me?

EDIT: I changed manually the smartphone storage options for my aplication have access to storage and dont returned any error!

But doesn't fire closeF either.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2017 Feb 04, 2017

then use the synchronous netstream and don't use a listener for close.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 04, 2017 Feb 04, 2017

Yey! That way it works!

I have a question:

I need to send every item of my xml to a list.

Before having to load my xml as a stream, i had a listenner that fired when the xml loaded sucessfuly and then save the items with that code:

lista_XML = XML(event.target.data);

for (var i: uint = 0; i < lista_XML.movie.length(); i++) {

  texto.text+="Item numero: "+i+", nome: "+lista_XML.movie.nome.text();

  item.label =  lista_XML.movie.link.text();

  item.data = lista_XML.movie.nome.text();

  }

Now, what is the best method to do the same?

Add a eventlistenner to fileStream_read and make it asynchronous?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 04, 2017 Feb 04, 2017
LATEST

read you xml using async

after that code executes execut the code that adds those data to your list component.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines