A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] FileReference not getting complete event

  1. #1
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    resolved [RESOLVED] FileReference not getting complete event

    Let me start by mentioning that I am using a program called "Koolmoves" that outputs AS3 compliant flash for player 9-10.

    For some reason my filereference is not recieving COMPLETE event.
    Every works fine and file is uploaded etc, and I see the byte total match up in my progress event. but never get the complete event, I also tried the uploadCompleteData event as well and have tried with the PHP code sending a response and also without.

    AS3 Code (pb1 and pb2 are buttons)
    PHP Code:
        import flash.display.Sprite;
        
    import flash.events.*;
        
    import flash.net.FileReference;
        
    import flash.net.URLRequest;
        
    import flash.net.FileFilter;



    myfile= new FileReference()
    mp3Filter = new FileFilter("mp3""*.mp3");
    myfile.addEventListener(ProgressEvent.PROGRESS,fstatus);
    myfile.addEventListener(Event.COMPLETE,fileDone);
    myfile.addEventListener(IOErrorEvent.IO_ERRORioErrorHandler);
    myfile.addEventListener(Event.SELECT,selectHandler);

    function 
    selectHandler(e:Event){
        
    txt2.text=e.target.name;
        }
        
    function 
    fstatus(e:Event){
        
    stat.text="status:"+e.bytesLoaded+" of "+e.bytesTotal;
        }
    function 
    fileDone(e:Event){
        
    stat.text="file uploaded "+e.data;
        }
    function 
    ioErrorHandler(e:Event){
        
    stat.text="IO ERROR "+e;
        }

    pb1.addEventListener(MouseEvent.CLICK,bFile);
    pb2.addEventListener(MouseEvent.CLICK,sendFile);

    function 
    bFile(e:MouseEvent){
        
    myfile.browse([mp3Filter]);
        }
    function 
    sendFile(e:MouseEvent){
        
    stat.text="Trying to send";
        
    uploadURL = new URLRequest();
        
    uploadURL.url="upload.php";
        
    myfile.upload(uploadURL);
        
        } 
    THE PHP I'm currently using is pretty simple at this point.
    PHP Code:
    <?php

    $fileName 
    basename($_FILES["Filedata"]["name"]);
    $ok=move_uploaded_file($_FILES["Filedata"]["tmp_name"], $fileName);
    echo 
    $ok;
    ?>
    I'm stumped at the moment, and the examples I've found all do pretty much the same coding as I have here.

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Ok finally resolved this myself.

    The adobe docs imply that complete event is fired but it seems this is not the case at least it was for me on my server.

    The trick was to use DataEvent.UPLOAD_COMPLETE_DATA and this also gets response from server.

    New PHP code
    PHP Code:
    <?php

    $fileName 
    basename($_FILES["Filedata"]["name"]);
    $ok=move_uploaded_file($_FILES["Filedata"]["tmp_name"], $fileName);
    if (
    $ok)
    {
        
    $message =  "$fileName uploaded successfully.";
    }
    else 
    {
        
    $message "Somthing is wrong with uploading a file.";
    }
     
    echo 
    $message;

    ?>
    Fixed AS3 Code
    PHP Code:
    import flash.display.Sprite;
        
    import flash.events.*;
        
    import flash.net.FileReference;
        
    import flash.net.URLRequest;
        
    import flash.net.FileFilter;



    myfile= new FileReference();
    mp3Filter = new FileFilter("mp3""*.mp3");
    myfile.addEventListener(ProgressEvent.PROGRESS,fstatus);
    myfile.addEventListener(IOErrorEvent.IO_ERRORioErrorHandler);
    myfile.addEventListener(Event.SELECT,selectHandler);
    myfile.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,completeHandler);

    function 
    completeHandler(e:Event){
        
    stat.text=e.data;
        }
    function 
    selectHandler(e:Event){
        
    txt2.text=e.target.name;
        }
        
    function 
    fstatus(e:Event){
        
    stat.text="status:"+e.bytesLoaded+" of "+e.bytesTotal;
        }

    function 
    ioErrorHandler(e:Event){
        
    stat.text="IO ERROR "+e;
        }

    pb1.addEventListener(MouseEvent.CLICK,bFile);
    pb2.addEventListener(MouseEvent.CLICK,sendFile);

    function 
    bFile(e:MouseEvent){
        
    myfile.browse([mp3Filter]);
        }
    function 
    sendFile(e:MouseEvent){
        
    stat.text="Trying to send";
        
    uploadURL = new URLRequest();
        
    uploadURL.url="upload.php";
        
    myfile.upload(uploadURL);
        
        } 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center