8 Replies Latest reply on Jul 28, 2011 7:40 AM by ThibaultB

    Differences between emulators


      Is it possible that an application that works on all the emulators for FB 4.5 does not run on the Android SDK emulator?


      I'm having problems with the stagewebviewbridge.

        • 1. Re: Differences between emulators
          saracinesca Level 1

          The problem seems to be about reading and writing files.
          Here's the code:


          <?xml version="1.0" encoding="utf-8"?>

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"





          import mx.events.FlexEvent;


          private var _tmpFile:File = new File();

          private var _fileStream:FileStream;



          protected function fileinit(event:FlexEvent):void


          _fileStream = new FileStream();

          _tmpFile.nativePath = File.applicationDirectory.resolvePath('tmp.cfg').nativePath;

          _fileStream.open(_tmpFile, FileMode.WRITE);

          _fileStream.writeUTFBytes( 'firstRun=true' );




          protected function readFile(event:MouseEvent):void


          // get original file contents

          _fileStream.open(_tmpFile, FileMode.READ);

          var originalFileContents:String = _fileStream.readUTFBytes(_fileStream.bytesAvailable);



          tArea.text = originalFileContents;






          <!-- Place non-visual elements (e.g., services, value objects) here -->


          <s:Label left="20" top="20" text="Label"/>

          <s:Button x="20" y="51" label="Button" click="readFile(event)"/>

          <s:TextArea id="tArea" y="137" right="20" height="70"/>


          • 2. Re: Differences between emulators
            Anirudh Sasikumar Adobe Employee

            I don't think applications can write into their installation folder. There's a separate storage folder. Try accessing that path via File.applicationStorageDirectory. You should be able to have write into that.


            P.S: I'm guessing running it on an actual device will have the same problem.



            • 3. Re: Differences between emulators
              xperiments.es.fr Level 1

              I have find some time and machine ( Android ) to test with...
              As you comment the problem with Android is that we can't write to the application directory as is really a "pseudo-zip" and the nativePath of the "app:/" returns blank.
              As you say the workarround is to move the cache filesystem to the File.applicationStorageDirectory. But this implies that you double the space used by your content. For little projects with only a few files there is no major problem, but imagine an app that contains a huge amount of videos....!!!!!!
              The problem with the communication is solved deleting the window.alert rewrite code from the StageWebViewBridge.as and StageWebViewBridge.js.
              Seems that the Android webkit don't like this!!! grrr
              DELETE THIS LINES FROM StageWebViewBridge.as and StageWebViewBridge.js.
              // workaround to fix application crash when window.alert is called directly from AS3         
                  window.alert = function(native)
                          window.nativeAlert = native;
                          return function(str)
              Anyway, I am testing some other methods for do a good workarround.... 

              • 4. Re: Differences between emulators
                Rangora Level 3

                It doesn't double the space used... this solution is the normal way to store data. In fact, this is the only way to store data that will work on all OS...


                What is your problem? You have assets included in the package that you want to modify and save again?

                • 5. Re: Differences between emulators
                  xperiments.es.fr Level 1



                  Yes, this is the exact case... imagine you have an app that will show some big mp4 videos with the stagewebview class.


                  The stagewebview.loadURL method docs says:


                  "The URL can use the following URI schemes: http:, https:, file:, data:, and javascript:.            Content loaded with the file: scheme can load other local resources."




                  "On Android, the nativePath property of a File object pointing to the application directory is an empty       string. Use the url property to access application files."


                  From this, its imposible to access using the file:/ protocol to the assets you have added to the app  as you can only point to the files with the app:/ protocol.


                  The only workarround I know ( is working with some modification in my StageWebViewBridge class ) is to copy the entire resources to the applicationStorageDirectory, and then, you can safe read these documents use the file:/ protocol.


                  But as I comment this workarround implies douplicate the space used in the html assets.


                  Other workarround will be to download the assets from the net in the app first run, but this implies you have a hoting server to host the files...


                  If you know another way, ideas to overcome this problem please say me as I will test if it can fit with the StageWebViewBridge class.


                  Anyway, as some developers use net resources with the StageWebViewBridge class, I am preparing a StageWebViewBridgeLitte without the cache filesystem.

                  • 6. Re: Differences between emulators
                    Rangora Level 3

                    Someone found a trick to get the nativePath from the app install directory... Try it on a device to see if you have enough permission to access the file by that url.


                    http://www.mikechambers.com/blog/2008/11/06/getting-the-file-uri-of-a-file-in-an-air-apps- install-directory/

                    • 7. Re: Differences between emulators
                      xperiments.es.fr Level 1

                      Yes, I know this... This is the way StageWebViewBridge class works... but this "hack" is unuseful as:


                      "On Android, the nativePath property of a File object pointing to the application directory is an empty       string. Use the url property to access application files."


                      The problem with the apps in android is that the app with its contents is packaged as a .apk ( really a zip file ) and the app works inside the "zip".

                      Then is imposible to access the files with the file:/ protocol as the files really don't exist in the filesystem.

                      • 8. Re: Differences between emulators


                        Someone found a solution to load properly local HTML files on Android ?

                        I try to load a html file with a video inside, but I don't success.

                        If I copy the file in other place, I can load the HTML but my video is unvailable (local file)


                        How can I do that ? Do I need to use HTML 5 <video> tag ? which path I need to use ?

                        If someone has an example (its ok on IOS)