Published on : 02.05.2010 Category : PHP/FLASH Viewed : 134 times.
As you can see in the previous example, once "print" button is pressed a loader window appears counting the percent progress.
This is because i used a setInterval function to copy all the pixels. This won't stress your cpu so much..
Here the class i use:
Code:
import flash.display.BitmapData; import flash.geom.Rectangle; import flash.geom.ColorTransform; import flash.geom.Matrix;
/** * Little and simple print flash screen class */ class it.sephiroth.PrintScreen {
public var addListener:Function public var broadcastMessage:Function
private var id: Number; public var record:LoadVars;
function PrintScreen(){ AsBroadcaster.initialize( this ); }
public function print(mc:MovieClip, x:Number, y:Number, w:Number, h:Number){ broadcastMessage("onStart", mc); if(x == undefined) x = 0; if(y == undefined) y = 0; if(w == undefined) w = mc._width; if(h == undefined) h = mc._height; var bmp:BitmapData = new BitmapData(w, h, false); record = new LoadVars(); record.width = w record.height = h record.cols = 0 record.rows = 0 var matrix = new Matrix(); matrix.translate(-x, -y) bmp.draw(mc, matrix, new ColorTransform(), 1, new Rectangle(0, 0, w, h)); id = setInterval(copysource, 5, this, mc, bmp); }
private function copysource(scope, movie, bit){ var pixel:Number var str_pixel:String scope.record["px" + scope.record.rows] = new Array(); for(var a = 0; a < bit.width; a++){ pixel = bit.getPixel(a, scope.record.rows) str_pixel = pixel.toString(16) if(pixel == 0xFFFFFF) str_pixel = ""; // don't send blank pixel scope.record["px" + scope.record.rows].push(str_pixel) } scope.broadcastMessage("onProgress", movie, scope.record.rows, bit.height) // send back the progress status scope.record.rows += 1 if(scope.record.rows >= bit.height){ clearInterval(scope.id) scope.broadcastMessage("onComplete", movie, scope.record) // completed! bit.dispose(); } } }
The ASBroadcaster class will be useful because i will use the addListener() method in order to receive events (onStart, onComplete and onProgress).
the main method is "print", which accepts there params:
1. mc: the movieclip to copy 2. x: x origin of the copy 3. y: y origin of the copy 4. w: width 5. h: height
then the setInterval will copy all the pixel in one single row in the BitmapData object, every 5 ms seconds.
Every array of colors (in each row) will be stored in a new array within a LoadVar object. In this way i will have 210 variables to post with the LoadVars object.
|