5 Replies Latest reply on Sep 30, 2010 7:22 PM by miguel8312

    Help with FileReferenceList... please...

    mikall1979

      Hi all,

      I need to select multiple files (but no upload... only select and return path).

      I would  select some images and and work locally one at time.

       

      These few lines of code don't work... (when I click the button browse() method doesn't work!!)

      Could someone explain why???????

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">   
          <fx:Script>
              <![CDATA[
                  import flash.net.FileReference;
                  import flash.net.FileReferenceList;
                  private var fileReferenceList:FileReferenceList;
        
                  private function browse():void {
                      var fileReferenceList:FileReferenceList;
                      fileReferenceList.browse();
                  }

       

              ]]>
          </fx:Script>
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
              <s:Button x="183" y="38" label="Button" click="browse()"/>
      </s:Application>

       

      Ref. Flex 4.

      Thanks for any help.

      Michele

        • 1. Re: Help with FileReferenceList... please...
          RUSH-ME Level 3

          Hi

           

          I think you have not initialized the FileReferenceList variable.

           

          var fileReferenceList:FileReferenceList = new FileReferenceList();

           

          in the cunstroctor of the FileReferenceList() you can pass the file types you want to browse.

           

          Hope this helps.

          Rush-me

          1 person found this helpful
          • 2. Re: Help with FileReferenceList... please...
            mikall1979 Level 1

            Thank you Rush-me!!

            I have another stupid question... sorry .. I'm learning Flex!

            How can I manage the event select (after browse)?

            For example this code... (obviously) doesn't work...

            .

             

            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                           creationComplete="init_app()">   
                <fx:Script>
                    <![CDATA[
                        import flash.net.FileReference;
                        import flash.net.FileReferenceList;
                        import flash.net.FileFilter;
                   
                        internal function init_app():void {               
                            addEventListener(Event.SELECT, onFilesSelect);
                        }
                                   
                        private function browse_files():void {
                            var fileReferenceList:FileReferenceList = new FileReferenceList();               
                            var myFilter:FileFilter = new FileFilter("Images", "*.jpg;*.JPG;*.png;*.PNG");
                            fileReferenceList.browse([myFilter]);
                            //init_app();
                        }
                       
                        private function onFilesSelect():void {
                            textArea.text="HELLO!";           
                        }
                       
                    ]]>
                </fx:Script>
                <s:Button x="183" y="38" label="Button" click="browse_files()"/>
                <s:TextArea x="65" y="92" width="338" height="301" id="textArea"/>
            </s:Application>

             

             

            thanks to anyone who has the patience to answer..

            • 3. Re: Help with FileReferenceList... please...
              miguel8312 Level 3

              try this  on your file select .

               

               

              private
              
              
              
               function onFileSelect(e:Event):void
              
              
              


              your listener is going to pass an event to your function.

               

               

               

               

               

              if this answers your question please mark it as such.

              • 4. Re: Help with FileReferenceList... please...
                mikall1979 Level 1

                Hi miguel8312

                 

                With your suggestion (you can see it in the code below) it doesn't work exactly like before...

                 


                <?xml version="1.0" encoding="utf-8"?>
                <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                               xmlns:s="library://ns.adobe.com/flex/spark"
                               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                               creationComplete="init_app()">
                   
                    <fx:Script>
                        <![CDATA[
                            import flash.net.FileReference;
                            import flash.net.FileReferenceList;
                            import flash.net.FileFilter;
                           
                            internal function init_app():void {               
                                addEventListener(Event.SELECT, onFilesSelect);
                            }
                                       
                            private function browse_files():void {
                                var fileReferenceList:FileReferenceList = new FileReferenceList();               
                                var myFilter:FileFilter = new FileFilter("Images", "*.jpg;*.JPG;*.png;*.PNG");
                                fileReferenceList.browse([myFilter]);
                                //init_app();
                            }
                           
                            private function onFilesSelect(e:Event):void {
                                textArea.text="HELLO!";           
                            }
                           
                        ]]>
                    </fx:Script>
                    <s:Button x="183" y="38" label="Button" click="browse_files()"/>
                    <s:TextArea x="65" y="92" width="338" height="301" id="textArea"/>
                </s:Application>

                 

                Any ideas?

                • 5. Re: Help with FileReferenceList... please...
                  miguel8312 Level 3

                  Try this.

                   

                   

                   

                   

                   

                   

                  <?xml version="1.0" encoding="utf-8"?>

                  <s:Application

                   

                   

                  xmlns:fx="http://ns.adobe.com/mxml/2009"

                  xmlns:s="

                  library://ns.adobe.com/flex/spark"

                  xmlns:mx="

                  library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"

                   

                  >

                   

                   

                   

                  <fx:Script>

                  <![CDATA[

                   

                   

                  import flash.net.FileFilter;

                   

                  import flash.net.FileReference;

                   

                  import flash.net.FileReferenceList;

                   

                  private var fr:FileReference;

                   

                  internal function init_app():void {

                   

                  }

                   

                  //File types which we want the user to open

                   

                   

                  private static const FILE_TYPES:Array = [new FileFilter("Images", "*.jpg;*.JPG;*.png;*.PNG")];

                   

                  private function browse_files():void {

                  fr =

                  new FileReference();

                  fr.addEventListener(Event.SELECT, onFilesSelect);

                  fr.browse(FILE_TYPES);

                   

                  }

                   

                   

                  private function onFilesSelect(e:Event):void {

                  textArea.text=

                  "HELLO!";

                  }

                   

                  ]]>

                   

                  </fx:Script>

                   

                   

                  <s:Button x="183" y="38" label="Button" click="browse_files()"/>

                   

                   

                  <s:TextArea x="65" y="92" width="338" height="301" id="textArea"/>

                  </s:Application>

                   

                   

                   

                   

                   

                   

                  if this answers your question please mark it as such!!

                  Miguel