7 Replies Latest reply on May 24, 2009 4:49 AM by Francisc

    FileReference not throwing a ProgressEvent...

    Reevesp

      Is there any reason why a FileReference will not throw a ProgressEvent? I've created several uploading apps and they've all thrown ProgressEvents and now I've created one that will not throw one at all. The file is being uploaded, I'm just not getting the progress for it.

       

      Thanks,

      PJ

        • 1. Re: FileReference not throwing a ProgressEvent...
          Michael Borbor Level 4

          Could you post a sample app of the progress bar/file reference that isn't working

          • 2. Re: FileReference not throwing a ProgressEvent...
            Reevesp Level 1

            Yeah, here is the app:

             

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

            <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="center" fontSize="14" addedToStage="initApp();">

                 <mx:Script>

                      <![CDATA[

                           import flash.net.FileFilter;

                           import flash.net.FileReference;

                           import flash.events.ProgressEvent;

                          

                           [Bindable]

                           private var reevesURL:URLRequest = new URLRequest('http://www.reevespro.com');

                           private var fileSearch:FileReference;

                           [Bindable]

                           private var myFile:FileReference;

             

                          

                           private function initApp():void {

                                fileSearch = new FileReference();

                                fileSearch.addEventListener(Event.SELECT, doSomething);

                           }

                           private function doSomething(e:Event):void {

                                myFile = FileReference(e.target);

                                fileTxt.text = myFile.name;

                           }

                           private function getFilter():FileFilter {

                                return new FileFilter("Files(*.mov,*.jpg,*.pdf)", "*.mov;*.jpg;*.pdf");

                           }

                           private function getTypes():Array {

                                var allTypes:Array = new Array(getFilter());

                                return allTypes;

                           }

                           private function lookNow(e:MouseEvent):void {

                                fileSearch.browse(getTypes());

                           }

             

                           private function addIt():void {

                                if(myFile.size > 0){

                                     var upURL:URLRequest = new URLRequest("files/brains.cfm");

                                     myFile.upload(upURL);

                                     myFile.addEventListener(ProgressEvent.PROGRESS, upP);

                                     myFile.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, weDone);

                                }

                           }

                           private function upP(e:ProgressEvent):void {

                                this.currentState = 'Uploading';

                                myPB.source = e.target;

                           }

                           private function weDone(e:DataEvent):void {

                                myHB.visible = true;

                           }

                      ]]>

                 </mx:Script>

             

                 <mx:states>

                      <mx:State name="Uploading">

                           <mx:RemoveChild target="{form1}"/>

                           <mx:AddChild position="lastChild">

                                <mx:ProgressBar width="392" trackHeight="23" label="Uploading File %3 %%" id="myPB"/>

                           </mx:AddChild>

                           <mx:AddChild position="lastChild">

                                <mx:HBox id="myHB" visible="false">

                                     <mx:Button label="Upload More" id="moreBttn" click="currentState=''"/>

                                     <mx:Button label="Done" id="doneBttn" click="navigateToURL(reevesURL, '_parent')"/>

                                </mx:HBox>

                           </mx:AddChild>

                           <mx:AddChild relativeTo="{myHB}" position="before">

                                <mx:Spacer height="27"/>

                           </mx:AddChild>

                          </mx:State>

                 </mx:states>

                 <mx:Form id="form1">

                      <mx:FormItem label="File:">

                           <mx:TextInput width="232" id="fileTxt" editable="false"/>

                      </mx:FormItem>

                      <mx:FormItem direction="horizontal">

                           <mx:Button label="Browse" id="browseBttn" click="lookNow(event)"/>

                           <mx:Button label="Upload" id="upDone" click="addIt()"/>

                      </mx:FormItem>

                 </mx:Form>

             

            </mx:VBox>

                          
            (Brains.cfm just does the sever side commands to save the file to the server)
            Again I can't get the ProgressEvent to throw, and event the DataEvent.UPLOAD_COMPLETE_DATA will not throw. I'm at a loss.
            Thanks,
            PJ

            • 3. Re: FileReference not throwing a ProgressEvent...
              Francisc Level 3

              Does the file get uploaded without getting the Progress events?

              Or it doesn't work at all? ~ Which would mean the upload fails somewhere along the way.

              If this is the case, try to see if the brains.cfm really works, you can quickly write an HTML form with the action set to the CF file to see if it does the upload.

              • 4. Re: FileReference not throwing a ProgressEvent...
                Reevesp Level 1

                M*A*S*H 4077 wrote:

                 

                Does the file get uploaded without getting the Progress events?

                Or it doesn't work at all? ~ Which would mean the upload fails somewhere along the way.

                If this is the case, try to see if the brains.cfm really works, you can quickly write an HTML form with the action set to the CF file to see if it does the upload.

                The file does get uploaded, so the ColdFusion page is fine I just don't get the ProgressEvent and/or DataEvent(upload complete). It is completely odd to me because I've created almost identical uploading apps and they all work (they throw the ProgressEvents and DataEvents).

                • 5. Re: FileReference not throwing a ProgressEvent...
                  Francisc Level 3

                  Hm... if the upload file works, the only thing I can think of is the if(myFile.size > 0) getting invalidated.

                   

                  Try if(myFile!=null).

                  • 6. Re: FileReference not throwing a ProgressEvent...
                    Francisc Level 3

                    Or take the IF clause out...

                    • 7. Re: FileReference not throwing a ProgressEvent...
                      Francisc Level 3

                      Also, I think the listeners should be added before the upload is called;

                       

                      myFile.addEventListener(ProgressEvent.PROGRESS, upP);

                      myFile.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, weDone);

                      myFile.upload(upURL);