4 Replies Latest reply on Aug 15, 2011 9:33 AM by Meate

    Problems with using a variable of type flash.filesystem.File

    Meate Level 2

      I need to parse a file with my flex app.  I can import flash.filesystem.File with no problem but if I try to create a variable of that type, it does strange things at run time.  If the variable is defined inside a function, it's as if that function no longer exists.  The function doesn't get called and I can't step into it.  If I define a File variable at global scope, the swf simply won't do anything at all.

       

      I've added all the AIR libs to my project and don't know what else to try at this point.  Any ideas?

       

      This sample code shows the problem.  If I comment out the File in initData, initData doesn't get called and I can't step into it.  If I comment out the global File, then I get a blank swf.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application           
         xmlns:mx="http://www.adobe.com/2006/mxml" minWidth="955" minHeight="600"
         initialize="initData()">
             
          <mx:Script>
              <![CDATA[
                  import flash.filesystem.File;
                                         
                  //private var file:File;
                             
                  private function initData():void
                  {                      

                      //var file:File;  
                      testLabel.text = "test";   
                  }
                 
              ]]>
          </mx:Script>
         
          <mx:TextArea y="200" id="testLabel" text="hello" />
         
      </mx:Application>

        • 1. Re: Problems with using a variable of type flash.filesystem.File
          _spoboyle Level 4

          sorry for my ignorance, I've only been using flex since 4.0

           

          shouldn't you be using WindowedApplication rather than Application for an AIR app?

           

          also there is no need to import File

           

          below is my code that work's fine

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
                                        layout="absolute"
                                        initialize="initData()">
               
               <mx:Script>
                    <![CDATA[
                         private var file:File;
                         
                         private function initData():void
                         {
                              var file:File;
                              testLabel.text = "test";
                         }
                    ]]>
               </mx:Script>
               
               <mx:TextArea y="200" id="testLabel" text="hello" />
               
          </mx:WindowedApplication>
          
          • 2. Re: Problems with using a variable of type flash.filesystem.File
            Meate Level 2

            I'm very new at Flex, and so you are probably right.  The code I started with was from a sample project from the Adobe PDF Driver sdk.  However, if I copy/paste your code, I still have to use the import and when I run it it crashes with the following stack trace:

             

            VerifyError: Error #1014: Class flash.events::NativeWindowBoundsEvent could not be found.

             

                at flash.display::MovieClip/nextFrame()
                at mx.managers::SystemManager/deferredNextFrame()[E:\dev\4.5.1\frameworks\projects\framework \src\mx\managers\SystemManager.as:284]
                at mx.managers::SystemManager/preloader_preloaderDocFrameReadyHandler()[E:\dev\4.5.1\framewo rks\projects\framework\src\mx\managers\SystemManager.as:2633]
                at flash.events::EventDispatcher/dispatchEventFunction()
                at flash.events::EventDispatcher/dispatchEvent()
                at mx.preloaders::Preloader/timerHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx \preloaders\Preloader.as:515]
                at flash.utils::Timer/_timerDispatch()
                at flash.utils::Timer/tick()

             

             

            Is there some other project setting I may be missing?

            • 3. Re: Problems with using a variable of type flash.filesystem.File
              _spoboyle Level 4

              is this a FlashBuilder project? are you getting that error with in your IDE it sounds like you are trying to run the AIR application in Flash Player which dosn't have the required AIR libraries

              • 4. Re: Problems with using a variable of type flash.filesystem.File
                Meate Level 2

                You are absolutely correct.  I created a new project and made sure it was an AIR project instead of a Flash Player project and it is working now.

                 

                Is there any file support (open, read, etc) in Flash (non-AIR)?  I have a command-line Flash compiler (again, part of the Adobe PDF Driver sdk) that will compile mxml files on the fly, and I don't know if it can create AIR apps.  It is something that I'll need to look into still.