1 Reply Latest reply on Jan 6, 2007 7:28 PM by chris.huston.t10

    File Chooser in Flex

      I want to make a file chooser that can allow me to choose (Browse) where's the file that i want to upload. Anyone know how to create a file chooser with flex builder 2 ? I'm very appreciate for any answer.
        • 1. Re: File Chooser in Flex
          chris.huston.t10 Level 3
          Here is an example that will make a file browser to choose either an image or mp3 file:

          private var upload_ref:FileReference;

          private function upload_media():void {
          var media_filter:FileFilter;
          var filter_array:Array = new Array();
          media_filter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
          media_filter = new FileFilter("Audio (*.mp3)", "*.mp3");
          upload_ref = new FileReference();
          upload_ref.addEventListener(Event.SELECT, file_selected);

          private function file_selected(evt:Event):void {
          if (upload_ref.name != null && upload_ref.name.search(" ") == -1 && upload_ref.name.search("'") == -1) {
          var sendVars:URLVariables = new URLVariables();
          sendVars.file_path = "/path_on_server_to_upload_to";
          var request:URLRequest = new URLRequest();
          request.url = " http://yourserver.com/upload_php_script.php";
          request.data = sendVars;
          request.method = URLRequestMethod.POST;
          upload_ref.addEventListener(Event.COMPLETE, completeUpload);
          } else {
          Alert.show("File name can only include letters, numbers or underbars. No spaces.");