Skip navigation
oxydiom
Currently Being Moderated

Open a local file

Aug 14, 2009 10:21 AM

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?

 
Replies
  • kglad
    62,161 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2009 11:27 AM   in reply to oxydiom

    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.

     
    |
    Mark as:
  • kglad
    62,161 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2009 1:43 PM   in reply to oxydiom

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

     
    |
    Mark as:
  • kglad
    62,161 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2009 2:31 PM   in reply to oxydiom

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

     


     

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

     

     

     

     
    |
    Mark as:
  • kglad
    62,161 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 14, 2009 3:18 PM   in reply to oxydiom

    well, that's how it's done.

     

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

     
    |
    Mark as:
  • kglad
    62,161 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 16, 2009 8:16 AM   in reply to oxydiom

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

     
    |
    Mark as:
  • kglad
    62,161 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 16, 2009 2:46 PM   in reply to oxydiom

    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,xmlDirector yReadErrorF);
        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].at tribute("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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 17, 2009 11:12 AM   in reply to oxydiom

    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-openD ocument.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.

     

     

     

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 17, 2009 2:22 PM   in reply to oxydiom

    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);

     

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 18, 2009 6:26 AM   in reply to oxydiom

    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-getSp ecialFolder.htm

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2009 1:47 AM   in reply to oxydiom

    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"
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points