2 Replies Latest reply on Jan 14, 2010 7:48 AM by Sebastien V.

    File Uploader using FileReference will not work

    vital_101

      Hey Everyone,

       

      I'm relatively new to Flex and Actionscript development, so I'm having a few issues here.  I've been following the tutorials at http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDo cs_Parts&file=00001936.html  and at   http://www.peachpit.com/articles/article.aspx?p=464427   but I can't seem to get my file uploader to work properly.

       

      I have a form in Flex, that I have submitting properly to my server, I'm catching the XML response, etc etc.  That part was straight foward, but when I wanted to add a file uploader that filters out certain file types, Flex Builder keeps throwing me errors.  I've included the relavent code below.  If you need more, let me know.  The errors Flex Builder gives me are all about undefined properties for imageTypes or btnListener.

       

      [CODE]

      <mx:Script>
                  <![CDATA[
                      import flash.net.FileReference;
                     
                      var fileTypes:Array = new Array();
                      var imageTypes:Object = new Object();
                      imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
                      imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png";
                      fileTypes.push(imageTypes);
                     
                      var fileListener:Object = new Object();
                      var btnListener:Object = new Object();
                      btnListener.click = function(eventObj:Object) {
                          var fileRef:FileReference = new FileReference();
                          fileRef.addListener(fileListener);
                          fileRef.browse(fileTypes);
                      }
                     
                      uploadButton.addEventListener("click", btnListener);
                     
                     
                  ]]>
              </mx:Script>
              <!-- Start Image Upload Stuff -->
              <!-- On click, execute actionscript for file upload dialoug -->
              <mx:FormItem label="Upload Image" fontWeight="bold" fontSize="11" width="402">
                  <mx:Button id="uploadButton" label="Browse" fillAlphas="[1.0, 1.0]" fillColors="[#FBFBFB, #C8C7C7]" width="100" themeColor="#638DA8" color="#4E585A" fontWeight="normal"/>
                  <mx:Text text="Upload a logo or other image file to be displayed in information box." fontWeight="normal" selectable="false" width="250" fontSize="10"/>
                  <mx:Text text="Image Size: 200 width by 120 height" fontWeight="bold" selectable="false" width="250" fontStyle="normal" fontSize="10"/>
              </mx:FormItem>

       

      [/CODE]