9 Replies Latest reply on Aug 14, 2011 12:54 AM by EvyatarBH

    How can I open a local folder using flash builder or AS3?

    kanjiri

      I need to open a local folder get the zip file and unzip it.

      I know that i cannot open a folder using flash builder, i did it using air app. now i do not know how do i integrate it with my flex program.

      Please help me with this issue.

       

      Thanks

        • 1. Re: How can I open a local folder using flash builder or AS3?
          Flex harUI Adobe Employee

          If you are running in a browser, you cannot access the local file system.

          • 2. Re: How can I open a local folder using flash builder or AS3?
            kanjiri Level 1

            Hi Flex harUI,

            Thanks for your reply.

            Flash player dosenot allow to display the local files,but there must be setting that we can change.Do you have any idea how to do that.

            I did some changes in the process.I have created a .as file and i am using FileReferenceList.browse() method to browse the folder. I can use FileReferenceList.FileList() method list the files under that folder.But the problem is i do not know how to direct that extracted list to the combobox.

             

            please help me.

            • 3. Re: How can I open a local folder using flash builder or AS3?
              Flex harUI Adobe Employee

              The user can grant permission to access the file system, but your

              application cannot grant itself permission.  If it could, folks would write

              malware with Flash all of the time.

              • 4. Re: How can I open a local folder using flash builder or AS3?
                kanjiri Level 1

                How to grant permission to access the file system? i tried searching FlashAuthor.cfg file but i cun't find it on my machine.

                Actually now  i am using IE 8. its allowing me to display names of the files and it retrives the filereferenceObject too which means it retrives all the files.I just need to direct all the files to a <mx:ComboBox> .,here also i am having problem.

                the array values(files) i am getting thro' .as script needs to be passed to <mx:ComboBox> in mxml code. i do not know how to do that either.

                any suggestions on this?

                • 5. Re: How can I open a local folder using flash builder or AS3?
                  Flex harUI Adobe Employee

                  See doc on "Global Security Settings" and "Flash Player Trust Files"

                   

                  Combobox can be passed an array of objects.  The labelField property

                  determines what to display.

                  • 6. Re: How can I open a local folder using flash builder or AS3?
                    kanjiri Level 1

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

                    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

                    <mx:Script source="Asset/folder.as" />

                    <mx:Button x="10" y="10" label="My Button" width="122" height="31" id="myButton" click="folder()"/>

                    <mx:ComboBox x="10" y="49" id="cbobx" dataProvider="{}"  ></mx:ComboBox>

                     

                    </mx:Application>

                    and .as code is:
                    // ActionScript file
                    import flash.display.*;
                    import flash.events.*;
                    import flash.net.FileFilter;
                    import flash.net.FileReference;
                    import flash.net.FileReferenceList;
                    import mx.controls.Alert;
                    import mx.controls.ComboBox;
                    private var fr:FileReferenceList;
                    private var cmbobx:ComboBox = new ComboBox();
                        private function folder():void
                    {
                    fr = new FileReferenceList();
                    fr.browse([new FileFilter("Zip Files", "*.zip")]);
                    fr.addEventListener(Event.SELECT, listZipFiles);
                    }
                    private function listZipFiles(e:Event):void
                    {
                    Alert.show("selectHandler: " + fr.fileList.length + " files");
                            var fls:Array = new Array();
                            var file:FileReference;
                           
                            for (var i:uint = 0; i < fr.fileList.length; i++)
                            {
                                file = FileReference(fr.fileList[i]);
                                //Alert.show("File Name: " + fr.fileList[i]);
                                Alert.show("File Name: " + file.name);
                                fls.push(file);
                                cmbobx.selectedItem = fls;
                               
                            }
                       
                    }
                    private function getShpFiles(event:MouseEvent):void
                    {
                    }

                    • 7. Re: How can I open a local folder using flash builder or AS3?
                      Flex harUI Adobe Employee

                      Set the dataProvider property not the selectedItem

                      • 8. Re: How can I open a local folder using flash builder or AS3?
                        kanjiri Level 1

                        I appreciate your prompt response.

                        i tried that way too(dataProviider="{fls}".it just gives me {fls} on the comboBox on the result browser.

                        • 9. Re: How can I open a local folder using flash builder or AS3?
                          EvyatarBH Level 3

                          That syntax works on MXML, but not on pure AS3.

                          In addition, make sure you define it AFTER the loop ends as follows -

                           

                          [Bindable]
                          private var filesCollection:ArrayCollection;
                           
                          private function listZipFiles(e:Event):void
                          {
                          Alert.show("selectHandler: " + fr.fileList.length + " files");
                                  var fls:Array = new Array();
                                  var file:FileReference;
                                 
                                  for (var i:uint = 0; i < fr.fileList.length; i++)
                                  {
                                      file = FileReference(fr.fileList[i]);
                                      //Alert.show("File Name: " + fr.fileList[i]);
                                      Alert.show("File Name: " + file.name);
                                      fls.push(file);
                                  }
                                  filesCollection = new ArrayCollection(fls);       
                                  cmbobx.dataProvider = filesCollection;
                          
                                  cmbobx.labelField="name"; //Adjust object's property name accordingly
                          }
                           
                           
                          
                          

                           

                          I added a designated ArrayCollection for the list of files and prepared it for data changes, but you don't have to use it as is.