I’m having a problem- not being able to get the loaded_swf that is not added to display list to get printed . The printer prints a blank page instead.
I use Loader to load the external swf . If I add the loader to display list, the loaded_swf gets printed with no problem. However, I do not want to display the loaded_swf on screen .
Is this as3 limitation or did I do anything wrong? I attach the code below. ( the problem is at loadAsset function)
I also tried using addChild(loader) and then make the loader invisible (loaded.visible = false) . It also prints the blank page. I know I can move the loaded swf off stage, but hm…m that doesn’t seem like it fixes the problem at the root cause.
/*
This is a class document.
it loads assets/a.swf and the loaded file will get printed when you click print button.
*/
package{
import flash.display.*;
import flash.events.*;
import flash.printing.*;
import flash.geom.*;
import flash.text.*;
import flash.net.URLRequest ;
public class PrintTest extends Sprite{
private var _assetList :Array=["assets/a1.swf"];
private var _myContainer :Sprite;
private var _myContainer2 :Sprite;
private var _loadCounter :Number=0;
private var _myLoader :Loader;
public function PrintTest(){
loadAsset(0);
}
private function loadAsset(assetIndex:Number){
var assetSrc:String=_assetList[assetIndex];
_myLoader= new Loader();
_myLoader.contentLoaderInfo.addEventListener( Event.INIT,handleInit);
_myLoader.load(new URLRequest(assetSrc));
/*
// problem here : When i comment out the following line and click print, It prints a blank page.
*/
//addChild(_myLoader);
_myLoader.visible=false;
displayPrintBtn();
}
private function displayPrintBtn():void{
//create print button
var myPrintBtn:Sprite=createPrintBtn(300,5,70,30,0xFFCC33,"click to print");
addChild(myPrintBtn);
}
private function handleInit(event:Event):void{
trace("handleInit"+_loadCounter);
}
private function createPrintBtn(x:Number,y:Number,w:Number,h:Number,c:Number,t:String):Sprite{
var myPrintBtn:Sprite=createRec(x,y,w,h,c);
var myText:TextField=new TextField();
myText.text=t;
myText.x=x;
myText.y=y;
myPrintBtn.addChild(myText);
myPrintBtn.addEventListener(MouseEvent.MOUSE_DOWN,printPages);
return(myPrintBtn);
}
private function createRec(x:Number,y:Number,w:Number,h:Number,c:Number):Sprite{
var myRec:Sprite=new Sprite();
myRec.graphics.lineStyle();
myRec.graphics.beginFill(c);
myRec.graphics.drawRect(x,y,w,h);
myRec.graphics.endFill();
return(myRec);
}
private function printPages(evt:Event):void{
trace("printBtn clicked");
var myPrintJob:PrintJob = new PrintJob();
myPrintJob.start();
var printingSprite:Sprite=_myLoader.content as Sprite;
myPrintJob.addPage(printingSprite);
myPrintJob.send();
}
}
}
Many thanks!!