File Open Dialog

By Scenery_J | Jul 10, 2009

actionscript3

I’m working on a little Flash Game prototype, similar to AudioSurf, and I’m trying to add an "Open File" function, so that the user can choose any mp3 on their PC to play. This will obviously only be a local running SWF - no online plans for this - so it won’t have to be uploaded.

So far I’ve managed to get it to open the Open File dialog box, and I can select a file, but it’s only passing the file name at the moment, so I can only open mp3’s that are in the same folder as the SWF.

How can I pass the whole location (folder + filename) of the mp3?

Note: I’m using a modified version of Adam’s File Upload component over at developphp.com:

ActionScript Code:
/*                         Script Written By: Adam Khoury @ [url]www.developphp.com[/url] */ // First thing is to set the flashing upload message clip to invisible uploadMsg.visible = false; // Set the URL for the PHP uploader script var URLrequest:URLRequest = new URLRequest(“http://www.[yoursite.com].com/uploader_script.php”); // Assign the image types Filter var audioTypes:FileFilter = new FileFilter(“Audio (*.mp3)”, “*.mp3″); // Assign the document types filter var textTypes:FileFilter = new FileFilter(“Text Files (*.txt, *.rtf)”, “*.txt; *.rtf”); // Add both filter types to an array var allTypes:Array = new Array(audioTypes, textTypes); // Set the FileReference name var fileRef:FileReference = new FileReference(); // Add event listeners for its various fileRef functions below fileRef.addEventListener(Event.SELECT, syncVariables); fileRef.addEventListener(Event.COMPLETE, completeHandler); fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler); // Add event listeners for your 2 buttons browse_btn.addEventListener(MouseEvent.CLICK, browseBox); upload_btn.addEventListener(MouseEvent.CLICK, uploadVars); // Function that fires off when the user presses "browse for a file" function browseBox(event:MouseEvent):void {     fileRef.browse(allTypes); } // Function that fires off when the user presses the "upload it now" btn function uploadVars(event:MouseEvent):void {     uploadMsg.visible = true;     fileRef.upload(URLrequest);     upload_btn.visible = false; } // Function that fires off when File is selected  from PC and Browse dialogue box closes function syncVariables(event:Event):void {      fileDisplay_txt.text = “” + fileRef.name;      root.fileName = fileRef.name;      blocker.visible = false;      root.gotoAndStop(2); } // Function that fires off when upload is complete function completeHandler(event:Event):void {     uploadMsg.visible = false;     blocker.visible = true;     status_txt.text = fileRef.name + ” has been uploaded.”;     fileDisplay_txt.text = “”; } // Function that fires off when the upload progress begins function progressHandler(event:ProgressEvent):void {    // we want our progress bar to be 200 pixels wide when done growing so we use 200*    // Set any width using that number, and the bar will be limited to that when done growing     progressBar.width = Math.ceil(200*(event.bytesLoaded/event.bytesTotal)); }

actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0