0

I am trying to load folder names into an array for later use. It works fine on my desktop but when I test it on a mobile device (both Android and iPhone) and it is calling another function - displayFlags(); - before I get the folder names into an array.

displayFlags() needs this array of names to work and I am getting errors from this line in of code in displayFlags(); Again its because the array is empty.

flag.load(new URLRequest(LangPath[i] + "/flag.png"));

Below is the code that loads file and the array. Is there a way to check when the array is available and call a function after its loaded?

var folderLanguages:File = File.applicationDirectory.resolvePath("Languages");

var availLang:Array = folderLanguages.getDirectoryListing();
var Lang:Array;
var LangPath:Array;
var flagButton:MovieClip;


function getLang(evt:Event = null)
{
Lang = new Array();
LangPath = new Array();
for (var i:uint = 0; i < availLang.length; i++)
   {

   if(availLang[i].isDirectory)
         {
        //trace(availLang[i].name);// gets the name
        Lang.push(availLang[i].name);
        LangPath.push(availLang[i].nativePath);
        trace(availLang[i].nativePath);// gets the name

         }
   }

displayFlags();
}
Papa De Beau
  • 3,744
  • 18
  • 79
  • 137
  • There's no reason that doesn't work. `getDirectoryListing()` is not asynchronous so it is populated before the other code runs. The only thing I can think of is that you are using `applicationDirectory` which I have always had trouble using on iOS (you don't clarify the system you are using) – Josh May 24 '13 at 21:44
  • It's having issues on both Droid and IOS – Papa De Beau May 24 '13 at 22:52
  • What I need is some sort of loader that can be used with this line: var availLang:Array = folderLanguages.getDirectoryListing(); or the loop below. – Papa De Beau May 24 '13 at 22:55
  • No, you don't need that. `getDirectoryListing()` is synchronous, meaning no other synchronous code (which is 99% of AS3) will run at the same time as it. So the directory listing is properly populating. Is the array null after calling getDirectoryListing() or is it just empty? If it is empty, my guess is that it is an issue with using `applicationDirectory` as opposed to `applicationStorageDirectory` – Josh May 24 '13 at 22:59
  • Well it's not empty on my computer but empty on my Android. On the IOS I can't seem to debug from USB anymore. Not sure why but when I open it on IOS it doesn't work as well but I can't see errors. – Papa De Beau May 24 '13 at 23:03
  • Again, I don't know if you can use applicationDirectory like that on mobile. You are supposed to use applicationStorageDirectory. – Josh May 24 '13 at 23:26
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/30604/discussion-between-papa-de-beau-and-josh-janusch) – Papa De Beau May 24 '13 at 23:42
  • I figured out the issue. I spent a whole day on this. It was a lower case letter that was supposed to be CAPS in the URL. Why did this work on the DESKTOP and not on my phones I don't know. It's too bad. No sign of the reason why the error. What a waste of time. – Papa De Beau May 26 '13 at 16:30

0 Answers0