oddball25 Posted December 31, 2009 Share Posted December 31, 2009 Hey 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) A link to the ongoing example can be found here - http://www.photoincanvas.co.uk/test/test-editor.html 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. If this is the better way i have a working php upload on the below link > http://www.photoincanvas.co.uk/test/ 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 > HTML CODE - <form name="newad" method="post" enctype="multipart/form-data" action="upload.php"> <table> <tr><td><input type="file" name="image"></td></tr> <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr> </table> </form> PHP UPLOAD CODE - <?php //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. $errors=0; //checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['image']['name']; //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>'; $errors=1; } else { //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 $size=filesize($_FILES['image']['tmp_name']); //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>'; $errors=1; } if ($size < MIN_SIZE*1024) { echo '<h1>You have not met the minimum size limit!</h1>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=time().'.'.$extension; //the new name will be containing the full path where will be stored (images folder) $newname="images/".$image_name; //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>'; $errors=1; }}}} //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 Thanks Jon [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/186801-as3-call-uploaded-file-into-empty-movieclip/ Share on other sites More sharing options...
oddball25 Posted January 2, 2010 Author Share Posted January 2, 2010 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); loader.load(request); addChild(loader); Quote Link to comment https://forums.phpfreaks.com/topic/186801-as3-call-uploaded-file-into-empty-movieclip/#findComment-987071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.