0
votes

I am trying to read from words from a text file in ActionScript Mobile Project. Each Word is then stored in an Array. This works fine during AIR IOS Simulator, but now I am Debugging on an Ipad and its not working...

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: app:/var/mobile/Applications/13FB44C5-E2EB-421F-9EF8-CB1290B75DD8/Library/Application%20Support/com.mcmami3.word/Local%20Store/media/words5.txt

private function slangLoadedThree(event:Object):void {

        slangContentThree = event.target.data;
        slangArrayThree= slangContentThree.split("\n");

    }



//five letter load
            var xmlFileFive:File=new File(File.applicationStorageDirectory.nativePath).resolvePath("media/words5.txt");
            myLoaderThree.load(new URLRequest(xmlFileFive.nativePath));
            myLoader.addEventListener(AsyncErrorEvent.ASYNC_ERROR, errorHandlerAsyncErrorEvent);
            myLoader.addEventListener(IOErrorEvent.IO_ERROR, errorHandlerIOErrorEvent);
            myLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandlerSecurityErrorEvent);
            myLoaderThree.addEventListener(Event.COMPLETE, slangLoadedThree);
4

4 Answers

1
votes

If there is only one file, you can just embed the txt file the same way you would embed an image. Directions on how found here:

Flex3: Load contents of an embedded text file into a variable

or here:

How do I embed static text in actionscript 3?

1
votes

Try one of these:

myLoaderThree = new URLLoader();
myLoaderThree.addEventListener(Event.COMPLETE, processText, false, 0, true);
myLoaderThree.load(new URLRequest("media/words5.txt"));

or

var xmlFileFive:File = File.applicationStorageDirectory.resolvePath("media/words5.txt");
var _urlRequest:URLRequest = new URLRequest(f.url);
myLoader = new Loader();
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, processText, false, 0, true);
myLoader.load(_urlRequest);

Both can use:

private function processText(e:Event):void {
        trace(e.target.data);
}
0
votes

Are you including the media folder and the words5.txt file when publishing your app?

i.e. in Flash Pro > Publish Settings > Click the spanner button next to the AIR version dropdown box > In the General tab you have a Included Files area. You should add your media folder here.

0
votes

So since I am just creating an array by reading a file, I might as well just skip reading the file and create the array one element at a time. Of course I don't mean typing in array[0] array[1] in Flash Builder. But instead I wrote a seperate C++ program that will read my WORD file and then write to another file "slangArrayOne[0] = "WORD" " and index the array for every word. I then take the output of that file which is... slangArrayOne[0] = "WORD"; slangArrayOne[1] = "WORD2"; and put them in a Action Script Class.

I now can use my Word Array for my Word Game on an iPad....This can probably be done a better way but I am new to this. Also whats the difference from reading a file during App load up to populate and Array of size X compared to just having the Array of size X populated in a program?

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{

 cout<<"Hello";
 cin.ignore();   


  string line;
  int x = 0;
  ifstream myfile ("FiveLetterWords.txt");
  // open a file in write mode.
   ofstream outfile;
   outfile.open("FiveLetterWordsNew.txt");


  if (myfile.is_open())
  {
    while ( myfile.good() )
    {
      getline (myfile,line);
      cout << "slangArrayFour["<<x<<"] = "<< "\""<< line <<"\"" <<"\n";
      outfile<< "slangArrayFour["<<x<<"] = "<< "\""<< line <<"\"" <<";"<<"\n";
      x++;
    }
    myfile.close();
  }

  else cout << "Unable to open file"; 



 cin.ignore();