| ActionScript 3: Flash to PNG Export Class (Ver 0.2) |
|
Author: Muhammad bin Yusrat Description: Makes an easy to export PNG/JPG Images from with in Flash. You can take a snapshot of any MovieClip (or the entire stage) and tell the class to export it to PHP which then saves it on the server. The usage of the script will require only two lines for the basic export of image. Functions:
This function has 1 primary and 3 optional arguments. Here is the easiest way to export PNG image with ActionScript 3 using this class: import com.muhammadbinyusrat.PNGExport;
var exporter:PNGExport = new PNGExport();
exporter.Snap(testClip);
exporter.SendTo("getImage.php");
Crop and onComplete Example: import com.muhammadbinyusrat.PNGExport;
var exporter:PNGExport = new PNGExport();
var cropArea:Rectangle = new Rectangle(50,50,100,150);
exporter.Snap(MovieClip(root),cropArea);
//This will Snap the entire page and crop it according to the rectangle.
exporter.SendTo("getImage.php",ShowWhenImageSaved);
function ShowWhenImageSaved(e:Event):void{
trace("The image has been saved..");
trace("PHP Said:" + e.target.data);
}
ProgressEvent Example: import com.muhammadbinyusrat.PNGExport;
var exporter:PNGExport = new PNGExport();
exporter.Snap(SomeMovieClip);
exporter.SendTo("getImage.php",null,ShowProgress);
//second argument is null because I don't want to specify
//an onComplete function in this example.
function ShowProgress(e:ProgressEvent):void{
trace(int((e.bytesLoaded/e.bytesTotal)*100));
//this should trace from 0 to 100 while the image is loading..
}
Custom Variable Example: import com.muhammadbinyusrat.PNGExport;
var exporter:PNGExport = new PNGExport();
exporter.Snap(SomeMovieClip);
var ExtraVariables:Array = new Array();
ExtraVariables[0] = {define:"Username",data:"ibnYusrat"};
ExtraVariables[1] = {define:"SessionID",data:"FFWEIE23920800012343JIFWK9V932CC"});
exporter.SendTo("getImage.php",null,null,ExtraVariables);
//This will send two extra variables called "Username" and
//"SessionID" with the values specified above.
Download: If you guys have any questions, please free free to post in the forum. I'll try and respond myself. |

.png)
Comments
Quoting George Rood:
Actually, this part doesn't work as shown. It needs to be the following:
ExtraVariables[ 0] = {define:"Username",data:"ibnYusrat"};
Only took about a half hour to debug...
Please fix the code above for the next guy.
Thanks for the tool, man! It's the best.
I want to send the movieclip data to twitpic, by default, I need to send 'media' variable to php that would be the movieclip that i want to upload, do you know how can i do this?
Thanks!
want to send croped area (photo png) to album in facebook ????? thank's for your help
exporter.Snap(MovieClip( root));
to
FileReference.save(BYTEARRAY OR BITMAPDATA FROM YOUR LIB, "Image.png");
You don't have to save the file to the server if you want the user to download it on their computer.
Look for a tutorial explaining client side file saving and reading in Flash Player 10. That would get you a way to save files directly on the user's computer without first having to save them on the server and then asking the user to download it.
How do I prompt the user to download the file? Everything is working fine and it is stored in the images directory on the server...
Thanks, Muhammad!
instead of this.stage, try MovieClip(root) .
Basically the URL "domain removed" is not really a URL. So obviously you'll get an IOError that URL is not accessible, because its not a URL at the first place.
Output error :
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: "domain removed"
at com.muhammadbinyusr at::PNGExport/SendTo()
at demo_fla::MainT imeline/demo_fla::frame 1()
Thanks in advance to anyone who can help me.
plizz someone help me..!!..feel suck with this!
plizz help me anyone??...feel suck!
This class is a life saver for me!
Thanks!
Any tips?
I think I found the issue. Changed line 44 of PNGExport.as to :
ImageData[vars.define] = vars.value;
(Changed last word from "data" to "value")
Here's what I'm doing:
$filename = $_POST['Username'].'_img.png';
It's coming back as 'undefined_img.png'.
Any help is appreciated!
-d
i cannot create a screenshot on a loaded content mb ? :(
why does it work on local though :(
I bumped into another problem. I was testing everything on localhost with WAMP and everything was working. After i uploaded it on live server GetImage.php doesnt look to get started from flash.
If i run the flash locally loading the GetImage.php from the live server its working and saving the image on the live server. LOL ? :) I've tried Security.allowDomain but still nothing
One solution that I could think of was to split the bitmap into multiple bitmaps and then combine them with PHP.