18 Replies Latest reply on Aug 19, 2009 1:47 AM by NSurveyor

    Open a local file

    oxydiom

      Hey

      I want to use a script on a button in my flash movie to open local files. This movie is going to be on a CD and I want to open some files through the movie. Actually it's an autorun.

       

      What shall I do?

        • 1. Re: Open a local file
          kglad Adobe Community Professional & MVP

          you can use the filerefence class to open a file-browse window.  but if you mean you want to execute some local file you should check the fscommand() function.

          1 person found this helpful
          • 2. Re: Open a local file
            oxydiom Level 1

            would you please help me more about it? What fscommand shall I use?

            • 3. Re: Open a local file
              kglad Adobe Community Professional & MVP

              use "exec" to execute a local file that's in an fscommand sub directory of your app.

              • 4. Re: Open a local file
                oxydiom Level 1

                sorry that I'm so amateur

                 

                 

                you mean this?

                 

                on(release) {
                    fscommand("exec", "Required Programs/active sync 4.5 .msi");
                }

                 

                 

                it's not working

                • 5. Re: Open a local file
                  kglad Adobe Community Professional & MVP

                  that executable must be in a subdirectory named fscommand.  then use:

                   


                   

                  on(release) {
                      fscommand("exec", "fscommand/active sync 4.5 .msi");
                  }

                   

                   

                   

                  • 6. Re: Open a local file
                    oxydiom Level 1

                    ain't working

                    besides, I need to organize them in different folders

                    • 7. Re: Open a local file
                      kglad Adobe Community Professional & MVP

                      well, that's how it's done.

                       

                      (p.s.  your file name doens't look correct.)

                      • 8. Re: Open a local file
                        oxydiom Level 1

                        I've heard there are plugins that can do this, can you help me with that?

                        besides, is this fscommand you told me in AS 2.0? It's not working!

                         

                         

                        And another question, what if I want to open a folder not a file?

                        • 9. Re: Open a local file
                          kglad Adobe Community Professional & MVP

                          if you want to interact with system files and folders you'll need to use as3 and create an air application.

                          1 person found this helpful
                          • 10. Re: Open a local file
                            oxydiom Level 1

                            Would you please explain more and give me some examples? Can you create an example file and upload it for me?

                             

                            Besides I have an extra question, I have a main flash file that loads another swf within it by "loadMovieNum". Can I use AS2.0 for the main flash file and AS3.0 for the swf which is played within the first one?

                            • 11. Re: Open a local file
                              kglad Adobe Community Professional & MVP

                              i don't have time to create an air file for you.  here's code from a project i did that (among other things) reads a local xml file:

                               

                              var shoremasterXMLFile:File;
                              var file2:File;
                              var partXML:XML;
                              var partCopyXML:XML;
                              var currentPartS:String;
                              var fileStream1:FileStream;

                               

                              function openShoremasterXML(xmlDirectorySS:String){
                                  xmlDirectoryS = xmlDirectorySS
                                  //xmlDirectoryS = xmlDirectoryS.replace(/\//g, File.separator);
                                  //traceF("openshoremasterxml: "+xmlDirectoryS+"shoremaster.xml");
                                  shoremasterXMLFile = File.applicationDirectory.resolvePath(xmlDirectoryS+"shoremaster.xml");
                                  // done in initializations
                                  // ReadMXLDirectoryFS = new FileStream();

                               

                                  ReadMXLDirectoryFS.addEventListener(Event.COMPLETE, xmlDirectoryReadCompleteF);
                                  ReadMXLDirectoryFS.addEventListener(IOErrorEvent.IO_ERROR,xmlDirectoryReadErrorF);
                                  ReadMXLDirectoryFS.openAsync(shoremasterXMLFile, FileMode.READ);
                              }

                               

                              function xmlDirectoryReadCompleteF(event:Event):void {
                                 
                                  var shoremasterXML:XML = XML(ReadMXLDirectoryFS.readUTFBytes(ReadMXLDirectoryFS.bytesAvailable));
                                  parseShoremasterXML(shoremasterXML);
                                 
                                  ReadMXLDirectoryFS.close();
                                  ReadMXLDirectoryFS.removeEventListener(Event.COMPLETE, xmlDirectoryReadCompleteF);
                                  //shoremasterXMLFile = null;
                                  //ReadMXLDirectoryFS = null;
                              }
                              function xmlDirectoryReadErrorF(e:IOErrorEvent){
                                  //traceF("ERROR: "+e.toString());
                                  attachPopupF(null,"ERROR:","shoremaster.xml read-error.\n\nUse the LOAD DATA button to (re)specify the xml files' location.");
                              }

                               

                              function parseShoremasterXML(xml:XML) {
                                  //tf.appendText("\n\nparseShoremasterXML entered");
                                  var xml:XML = XML(xml);
                                 
                                  var xmlList:XMLList = xml.children();
                                  for each (var item in xmlList) {
                                      var childList:XMLList = item.children();
                                     
                                      for(var i:int=0;i<childList.length();i++){
                                          cb.addItem({label:childList[i].attribute("name"),data:childList[i].attribute("name")});
                                      }
                                  }
                                  cbListenerF();
                                  // initial
                                 
                                  loadXML(cb.getItemAt(0).label.split(" ").join("").split("-").join(""));
                              }

                               

                               

                              // and not you cannot use an as2 swf to load an as3 swf.

                              • 12. Re: Open a local file
                                oxydiom Level 1

                                please make an example file when you are free

                                I can't get it

                                • 13. Re: Open a local file
                                  mantissa0

                                  A simpler option might be to use a flash application builder like mProjector, it adds an openDocument command (along with many others) into Flash

                                   

                                  Here a link to the API Docs page

                                   

                                  http://www.screentime.com/software/flash-projector/docs/AS3-mSys-openDocument.htm

                                   

                                  So your would code something like this in AS

                                   

                                   

                                  mSystem.openDocument("C:/Help.pdf");
                                  

                                   

                                  There is a full built example fla / swf / app on this page

                                   

                                  http://www.screentime.com/software/flash-projector/flas.html

                                   

                                  called "Open Documents"

                                   

                                  You would need to download the demo version of mProjector  to install these new commands into Flash.

                                   

                                   

                                   

                                  • 14. Re: Open a local file
                                    oxydiom Level 1

                                    that's cool

                                    but my main problem is opening folders. It's MUCH more important

                                    I want to open some folders by clicking on buttons

                                    • 15. Re: Open a local file
                                      mantissa0 Level 1

                                      Yes you can do that too

                                       

                                      OpenDocument is actually a pretty generic call, it can open a document, send and email, open a web browser and also open a folder, just pass it the path to the folder you want to open and it will open in the Windows Explorer (Win) or Finder (Mac)

                                       

                                      This Code for example will open the folder that the application is running in

                                       

                                       

                                      var fileToOpen = mApplication.getFolder() + mSystem.getPathDelimiter();

                                      mSystem.openDocument(fileToOpen);

                                       

                                      • 16. Re: Open a local file
                                        oxydiom Level 1

                                        it's AS3.0, yeah?

                                        If I want to open another folder, what shall I do then?

                                         

                                        for example:

                                         

                                        Flash file is located in CDROM// Autorun\flash.swf

                                        Target folder:  CDROM// Programs\Root1\1

                                        • 17. Re: Open a local file
                                          mantissa0 Level 1

                                          No, our software supports AS2 or AS3,

                                           

                                          if the path is constant then you can hardcode it into the call

                                           

                                           

                                          mSystem.openDocument("CDROM// Programs\Root1\1");
                                          
                                          
                                          If it is relative to the App you made then you would make a call to figure out the path to your app
                                          var applicationFolder:String = mApplication.getFolder();
                                          
                                          
                                          applicationFolder now equals the path to the folder you app is in, you use Flash string handling to add or substract to this string to make the path you need.
                                          mProjector also has a routine
                                          mSystem.getSpecialFolder(folderName:String) : String


                                          that takes a selector to return a path places like the programs folder

                                           

                                          http://www.screentime.com/software/flash-projector/docs/AS3-mSys-getSpecialFolder.htm

                                          • 18. Re: Open a local file
                                            NSurveyor

                                            You may be able to use a batch file which in turn can open a folder/file of your choosing. I was able to muster up this short, but robust batch script:

                                            @echo off
                                            set file=%~n0
                                            %SystemRoot%\explorer.exe /e, "%~dp0..\%file:@=\%"
                                            

                                             

                                            The filename of the batch file dictates the folder which the script will open. The path is relative to the swf, with @ used in place of "\". Thus, in your case, you would name the batch file:  "..@Programs@Root1@1.bat" which would be saved in the directory "Autorun/fscommand/"

                                             

                                            And then to execute it, you'd simply use:

                                            fscommand("exec", "..@Programs@Root1@1.bat" );
                                            

                                             

                                            Of course, you could very well hardcode the path in the batch file to ease the naming process:

                                            @echo off
                                            %SystemRoot%\explorer.exe /e, "%~dp0..\..\Programs\Root1\1"