I've been trying really hard on this with no results, hope someone could help me out.
What I have is an HTML page with a ActionScript2 SWF object embedded. The SWF is a static sprite that gets dynamic text from the javascript. So basically looks like an image.
I want to print out the whole page HTML + SWF included, but as expected on the possition of the SWF object appears a blank square.
I print the page using javascript window.print()
;
Is there anyway to take a snapshot of the SWF or render it like an image? to show it on the print preview and on the printed document? The size of the flash object is 600x381px;
Thank you!
Sorry guys、but I finally came up with a solution.
Thanks for having a look anyways.
What I first did is to convert the flash file from ActionScript2 to ActionScript3 to be able to use the as3corelib of Mike Chambers https://github.com/mikechambers/as3corelib . From this library I used the JGPEncoder as seen below
import flash.external.ExternalInterface;
import flash.display.JPEGEncoderOptions;
import com.adobe.images.JPGEncoder;
import flash.display.BitmapData;
import flash.utils.ByteArray;
import flash.display.Bitmap;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
function snapShot(){
var imgBM:Bitmap;
var myBitmapData:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
myBitmapData.draw(stage);
imgBM=new Bitmap(myBitmapData);
addChild(imgBM);
var imgBA:ByteArray;
var jpgEncoder:JPGEncoder = new JPGEncoder(90);
//-------Send image to php
imgBA = jpgEncoder.encode(myBitmapData);
var sendHeader:URLRequestHeader = new URLRequestHeader('Content-type', 'application/octet-stream');
var sendReq:URLRequest = new URLRequest("parseimg.php");
sendReq.requestHeaders.push(sendHeader);
sendReq.method = URLRequestMethod.POST;
sendReq.data = imgBA;
var sendLoader:URLLoader = new URLLoader;
sendLoader.addEventListener(Event.COMPLETE, imageSentHandler);
sendLoader.load(sendReq);
}
var imagePath:String;
function imageSentHandler(event:Event):void {
var dataStr:String = event.currentTarget.data.toString();
var resultVars:URLVariables = new URLVariables();
resultVars.decode(dataStr);
imagePath = "http://" + resultVars.base + resultVars.filename;
}
The next step was to create the php that receives the ByteArray and creates the image file on the server.
<?php
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
$filename = "your_image_name.jpg";
$fp = fopen( $filename,"wb");
fwrite( $fp, $GLOBALS[ 'HTTP_RAW_POST_DATA' ] );
fclose( $fp );
echo "filename=".$filename."&base=".$_SERVER["HTTP_HOST"].dirname($_SERVER["PHP_SELF"]); } ?>
Finally and with the image already in a folder on the server, I just had to hide the Embedded flash object using CSS, and show up the image instead.
I got this using jquery on document.ready
var d = new Date();
setTimeout(function(){
$("#imgflash").attr("src", "your_image_name.jpg?"+d.getTime());
setTimeout("window.print();", 200);
},1000);
As I'm pretty new on ActionScript and Flash, any improvements on this code are kindly accepted.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.