AS3 - Call Uploaded file into Empty Movieclip


I am in the middle of trying to create an swf that allows the user to upload an image into the flash file and manipulate it in several ways using actionscript 3 and flash cs4. (ideally if possible keeping the flash player needed at 9 or lower)

I have solved most of the photo editing side, but am having trouble uploading any photo into the flash file. I have looked into the ‘getfile reference’ class and also the ‘oncompletedata’ but havent got it working. Can anyone help? I need the user to click on the upload button on frame one which will upload the file to the server and display it on frame 2 in the empty_mc (instance of myObject) Currently i have a random jpeg image in its place.

Originally i intended to use an html form and php upload script to do all the uploading then send the url link into flash but again cannot come up with a way for this.

This successfully uploads my image onto the server in the ‘images’ folder but how do i get this into my swf? The html and php code for this is >


 <form name="newad" method="post" enctype="multipart/form-data"  action="upload.php">
     <tr><td><input type="file" name="image"></td></tr>
     <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>


//define a maxim size for the uploaded images in Kb
 define ("MAX_SIZE","7000"); 
 //define a minim size for the uploaded images in Kb
 define ("MIN_SIZE","100"); 

//This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;

//This variable is used as a flag. The value is initialized with 0 (meaning no error  found)  
//and it will be changed to 1 if an errro occures.  
//If the error occures the file will not be uploaded.
//checks if the form has been submitted
     //reads the name of the file the user submitted for uploading
     //if it is not empty
     if ($image) 
     //get the original name of the file from the clients machine
         $filename = stripslashes($_FILES['image']['name']);
     //get the extension of the file in a lower case format
          $extension = getExtension($filename);
         $extension = strtolower($extension);
     //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
    //otherwise we will do more tests
 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "tif")) 
        //print error message
             echo '<h1>Unknown extension!</h1>';
//get the size of the image in bytes
 //$_FILES['image']['tmp_name'] is the temporary filename of the file
 //in which the uploaded file was stored on the server

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
    echo '<h1>You have exceeded the size limit!</h1>';

if ($size < MIN_SIZE*1024)
    echo '<h1>You have not met the minimum size limit!</h1>';

//we will give an unique name, for example the time in unix time format
//the new name will be containing the full path where will be stored (images folder)
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied) 
    echo '<h1>Copy unsuccessfull!</h1>';

//If no errors registred, print the success message
 if(isset($_POST['Submit']) && !$errors) 
     echo "<h1>File Uploaded Successfully!</h1>";


Zip file containing the fla file etc is attached.

Any help much appreciated, i have spent the last 3-4 days trying out different tutorials, source codes and my own limited knowledge!! with no luck



Got it working in the end thanks to ‘moagrius’ on another forum for helping me! SOlved by: first, you need to give Flash the new file name. You can use a standard querystring or Flash vars, and php to echo it out:

PHP Code:

<param name="movie" value="Test_Editor.swf?filename=<?php echo $newname; ?>" />
<object type="application/x-shockwave-flash" data="Test_Editor.swf?filename=<?php echo $newname; ?>" width="964" height="510">
as you can see, we set a variable named "filename" to the $newname php variable.

now, it’ll be availabe in flash in the loaderInfo.parameters object, which will now have a property named “filename” that will be the path from $newname:
PHP Code:

var imageFilePath:String = root.loaderInfo.parameters.filename;

then load it into flash using a Loader object:

PHP Code:

var loader:Loader = new Loader();
var request:URLRequest = new URLRequest(imageFilePath);