| 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",value:"ibnYusrat"};
ExtraVariables[1] = {define:"SessionID",value:"FFWEIE23920800012343JIFWK9V932CC"});
exporter.SendTo("getImage.php",null,null,ExtraVariables);
//This will send two extra variables called "Username" and
//"Password" with the values as 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
Thanks for the quick reply. I just figured it out my self as well.
Grate stuff. Thanks for sharing.
You have to give write permission (777) to the directory that holds the images.
I don´t get a output file... any suggestions?
I've put the GetImage.php on my server and changed the Action Script so that it links to the new address. But it don´t work. Could it be the file rights on my server that does´t allow php to write?
Thanks in advance for you help.
yer Thanks it works now, I just thought the php was ment to output inside the page the flash was in and not acctuly inside the flash itself.
Are you able to get the images in the output folder?
The Upload works, but I don't get any reply from php when I for example use the ShowWhenImageSa ved. Why is this?
Open com/muhammadbinyusr at/PNGExport.as
At line 26,
Replace
new BitmapData(targ et.width,target.height)
By
new BitmapData(targ et.width,target.height, true, 0)
Yes, but it can only be reduced from what is being produced right now. Its producing 100/100 quality atm. If you want to change it, you will be able to only reduce it.
Thanks again!
Hi Simo,
If you look at the second example in the above article, you will see how the whole stage is snapped and part of it cropped.
I hope that helps, thanks!
I'm going to test this if it can solve my issue and let you know.
Cheers
I have updated the class. Now those errors are gone. Basically I uploaded it last time without testing it so missed a few things.
I hope its error free now. I have tested it and does work.
Feel free to post back if you have questions about it. Thanks!
Hi All,
I try this today and got same err.
It seem this minor error come from PNGExport.as line 57,
Action.addEventListene r(ProgressEvent .PROGRESS,fnProg ress);
"fnProgress" should be the function name on para list, i reference line 54, i guess, it should be "ProgressFunctio n" itself...
Action.addEventListene r(ProgressEvent .PROGRESS,Progre ssFunctio n);
Also, please notes that a folder call "images" should be create on same level as "com" for captured image
Please reply if i misundertaken
Hi Francesca,
Yes, its saved in CS4.
The reason why you are getting that error is probably because you've downloaded an older version of the class from some other page. If you download the latest version, the fnProgress function does not exist in it and is not used anywhere.
Are you getting any errors? One reason of images not getting saved could be that you have to give write permission (777) to the directory that holds the images.
Let me know if that works, thanks!