actionscript-3filepathfile-browserurlrequest

Trying to select a files location + file name in AS3


I am creating a file testing program in actionscript 3. I have the URL loader to load the file path + name typed in the textbox. However I am looking to upgrade the experience. I am trying to find a way to choose a file location and name from a function like browseforDirectory(). If anyone could help with providing me either a link to documentation on how to do this or if anyone could help me out that would be awesome. For an example of how its set up currently.

public var TestPath:string = this.TestTxt.txt;
..

this.ldr.load(new URLRequest(TestPath));

This is pretty much a simple example of what would be going on. I am just looking for a way to find a file via browsing for it in a file select window and save the complete path of the file. Sorry if I sound repetitive and all help is appreciate. Couldn't find any documentation towards this specific topic.


Solution

  • I have figured out how to do it. Thank you for pointing me to browse Organis. I think explaining the use of browse a little more, or even providing a quick sample, would have proved to create an excellent answer that others who might view this topic would find helpful. Here is what I have used. It is quite crude and I will refine it later.

    package  {
    
    import flash.events.MouseEvent;
    import flash.net.FileReference;
    import flash.net.FileFilter;
    import flash.utils.ByteArray;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.display.MovieClip;
    import flash.filesystem.File;
    
    
    public class Browse extends MovieClip 
    {
        var File1:File = new File();
    
    
        public function Browse() 
        {
                //Adds an event listener for the selected file.
                File1.addEventListener(Event.SELECT, FileSelected);
                //Narrows down the file selection
                var swfTypeFilter:FileFilter = new FileFilter("Text Files","*.txt; *.png;*.as");
                var allTypeFilter:FileFilter = new FileFilter("All Files (*.*)","*.*");
                //Calls the browse function to pop up a file selection window
                File1.browse([swfTypeFilter, allTypeFilter]);
        }
    
        function FileSelected(event:Event):void
        {
            trace(File1.nativePath);
        }
    
    }
    

    }

    Hopefully anyone looking for a way just to get a file path of a file selected can find it here.