Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Error 2037 File Reference

Participant ,
Mar 03, 2011 Mar 03, 2011

Hi to everybody!

I'm trying to build an application where you can save a jpeg from the stage and after u saved on the desktop it's uploading to my server.

In the Main class the important method are:

// the button for save the image

private function btnClickHandler(e:Event):void {  
     downloadClass = new DownloadClass();
     downloadClass.download(sp);
     downloadClass.addEventListener(DownloadClass.FILE_DOWNLOADED, fileDownloadedListener)

}

// after downloading the file i start the upload
private function fileDownloadedListener(e:Event):void {
     uploadClass = new UploadClass();
     uploadClass.uploadFile(downloadClass.getFile())   
}

The download operation i'ts succesfull, i dispatch the FILE_DOWNLOADED event and start the upload operation passing to uploadClass.uploadFile the file reference:

// DownloadClass //

// complete the download operation

private function completeHandler(event:Event):void {
     file = FileReference(event.target);
     dispatchEvent(new Event(DownloadClass.FILE_DOWNLOADED))
}

// public getFile() method in DownloadClass

public function getFile():FileReference{
     return file

}

The problem is that when i start the upload operation i get the error 2037.

This the UploadClass():

package com.cb.utils.image {
   
    /* PHP CODE
    <?php
    if ($_FILES['Filedata']['name']) {
    move_uploaded_file($_FILES['Filedata']['tmp_name'], 'upload_directory/' . basename($_FILES['Filedata']['name']));
    echo "result=ok"
    }else {
    echo "result=ko";
    }
    ?>   
    */
   
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.FileFilter;
    import flash.net.FileReference;
    import flash.net.URLRequest;
    import flash.net.URLVariables;

   
    public class UploadClass extends Sprite {
        private var uploadURL:URLRequest;
        private var file:FileReference;
       
        public function UploadClass() {
            uploadURL = new URLRequest();
            uploadURL.url = "http://localhost/php_code/FileReferenceExample.php";
            file = new FileReference();
            configureListeners();
        }

        private function configureListeners():void {
            file.addEventListener(Event.CANCEL, cancelHandler);
            file.addEventListener(Event.COMPLETE, completeHandler);
            file.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
            file.addEventListener(Event.OPEN, openHandler);
            file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadCompleteDataHandler);
        }

        private function cancelHandler(event:Event):void {
            trace("cancelHandler: " + event);
        }
       
        private function completeHandler(event:Event):void {
            trace("completeHandler: " + event);
        }
       
        private function uploadCompleteDataHandler(event:DataEvent):void {
            //The uploadCompleteData event is not dispatched if data is not returned from the server.
            //trace("uploadCompleteData: " + event.data);
           
            //will receive the data as a string, can easily convert the string into a URLVariables object
            //by passing the string to the URLVariables constructor,
            //or by using the URLVariables class’s decode() method
           
            var strData:String =(event.data);
            var vars:URLVariables = new URLVariables(strData);
            // result e la variabile
            trace('result: '+vars.result)
        }
       
        private function httpStatusHandler(event:HTTPStatusEvent):void {
            trace("httpStatusHandler: " + event);
        }
       
        private function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }
       
        private function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }
       
        private function progressHandler(event:ProgressEvent):void {
            var file:FileReference = FileReference(event.target);
            trace("progressHandler name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }
       
        private function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }
       
        /*private function selectHandler(event:Event):void {
            var file:FileReference = FileReference(event.target);
            trace("selectHandler: name=" + file.name + " URL=" + uploadURL.url);
            file.upload(uploadURL);
        }*/
       
        public function uploadFile(imageFile:FileReference):void{
           
             file = FileReference(imageFile);
            try {
                file.upload(uploadURL);
            }
            catch (e:Error) {
                trace("Unable to upload file.    error:"+e.errorID);
            }
        }
    }
}

The difference beatween a normal file reference is that i start the upload calling a method and not after the select event like this:

private function selectHandler(event:Event):void {
     var file:FileReference = FileReference(event.target);
     trace("selectHandler: name=" + file.name + " URL=" + uploadURL.url);
     file.upload(uploadURL);
}

Hope somebody can reply to me!

thanks

TOPICS
ActionScript
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 03, 2011 Mar 03, 2011
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 03, 2011 Mar 03, 2011

... so what should i change im my classes???


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 03, 2011 Mar 03, 2011

the File and FileReference classes must be initialized to reference a file path, before their properties can be accessed

don`t write

file = new FileReference();

in your coonstructor

but

file = FileReference.desktopDirectory;

or one of the other static properties:

  • File.applicationStorageDirectory—a storage directory unique to each installed AIR application
  • File.applicationDirectory—the read-only directory where the application is installed (along with any installed assets)
  • File.desktopDirectory—the user's desktop directory
  • File.documentsDirectory—the user's documents directory
  • File.userDirectory—the user directory

it doesn`t matter which


					
				
			
			
				
			
			
			
			
			
			
			
		
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 03, 2011 Mar 03, 2011

like this:

    public function UploadClass() {
            uploadURL = new URLRequest();
            uploadURL.url = "http://localhost/php_code/FileReferenceExample.php";
            file = FileReference.desktopDirectory;
            configureListeners();
        }

i have this error in flash builder problems panel:


1119: Access of possibly undefined property desktopDirectory through a reference with static type Class.

thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 03, 2011 Mar 03, 2011
LATEST

im using flash player runtime and not air!

look here:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines