2 Replies Latest reply on Feb 27, 2011 2:45 PM by mroiler

    File upload.

    mroiler

      This is what i have so far:

      [Bindable]
      public var file:FileReference;
      
      public function button1_clickHandler(event:MouseEvent):void
      {
      file = new FileReference();
      file.browse();
      }
      
      public function upload(event:MouseEvent):void
      {
      var fileup:FileReference;
      var dest:URLRequest = new URLRequest("http://www.mywebsite.com/upload.php");
      dest.method = URLRequestMethod.POST;    
      fileup = new FileReference();
      fileup.upload(dest, fileName.text);
      }
      
      <s:TextInput id="fileName" text="{file.name}"/>
      <s:Button label="Browse" click="button1_clickHandler(event)"/>
      <s:Button label="Upload" click="upload(event)"/>
      
      
      

      When i click the browse button i get:

       

      Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.

      at flash.net::FileReference/get name()

      at mx.binding::PropertyWatcher/updateProperty()[E:\dev\4.x\frameworks\projects\framework\src \mx\binding\PropertyWatcher.as:338]

      at Function/http://adobe.com/AS3/2006/builtin::apply()

      at mx.binding::Watcher/wrapUpdate()[E:\dev\4.x\frameworks\projects\framework\src\mx\binding\ Watcher.as:192]

      at mx.binding::PropertyWatcher/updateParent()[E:\dev\4.x\frameworks\projects\framework\src\m x\binding\PropertyWatcher.as:239]

      at mx.binding::Watcher/updateChildren()[E:\dev\4.x\frameworks\projects\framework\src\mx\bind ing\Watcher.as:138]

      at mx.binding::PropertyWatcher/updateProperty()[E:\dev\4.x\frameworks\projects\framework\src \mx\binding\PropertyWatcher.as:347]

      at Function/http://adobe.com/AS3/2006/builtin::apply()

      at mx.binding::Watcher/wrapUpdate()[E:\dev\4.x\frameworks\projects\framework\src\mx\binding\ Watcher.as:192]

      at mx.binding::PropertyWatcher/eventHandler()[E:\dev\4.x\frameworks\projects\framework\src\m x\binding\PropertyWatcher.as:375]

      at flash.events::EventDispatcher/dispatchEventFunction()

      at flash.events::EventDispatcher/dispatchEvent()

      at mx.core::UIComponent/dispatchEvent()[E:\dev\4.x\frameworks\projects\framework\src\mx\core \UIComponent.as:12528]

      at main/set file()

      at main/button1_clickHandler()[to my project/main.mxml:19]

      at main/main_Button1_click()[to my project/main.mxml:56]