Actionscript 3 使用Actionscript 3在flash中打印当前帧

Actionscript 3 使用Actionscript 3在flash中打印当前帧,actionscript-3,flash,printing,frame,Actionscript 3,Flash,Printing,Frame,嘿,我正在通过flash制作一个定时测验游戏,我正在尝试设置一个代码,允许用户打印他们当前所在帧的内容。(即,如果他们想在5分钟内或在问题20上打印进度,等等)。我可以打开“打印选项”框,但每次单击“确定”打印时,它都会显示为空白。以下是我正在使用的代码: print_btn.addEventListener(MouseEvent.CLICK, onPrintClick); function onPrintClick(event:Event):void{ import flash.d

嘿,我正在通过flash制作一个定时测验游戏,我正在尝试设置一个代码,允许用户打印他们当前所在帧的内容。(即,如果他们想在5分钟内或在问题20上打印进度,等等)。我可以打开“打印选项”框,但每次单击“确定”打印时,它都会显示为空白。以下是我正在使用的代码:

print_btn.addEventListener(MouseEvent.CLICK, onPrintClick);

function onPrintClick(event:Event):void{

    import flash.display.Sprite;
    import flash.printing.PrintJob;

    var printJob:PrintJob = new PrintJob();
    var mySprite:Sprite = new Sprite();

    if (!printJob.start()) {
        return;
        printJob.addPage(mySprite); 
        printJob.send();
    }
}

有什么建议吗?

我认为您的代码存在一些直接的问题。希望把它们整理出来能解决你的问题

首先,您应该将
import
语句放在代码的最顶端

其次,对于
if(!printJob.start())
您是说如果打印作业尚未启动,请执行此操作

return;
printJob.addPage(mySprite);
printJob.send();
这意味着永远不会调用
printJob.addPage(mySprite)
&
printJob.send()

第三,如果您直接从
new Sprite()
使用
Sprite
对象,那么它仍然是空的。试着画一个红方块,然后打印

var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xFF0000);
mySprite.graphics.drawRect(0,0,100,100);
mySprite.graphics.endFill();
// now print

有什么帮助吗?

谢谢您的回复

好的,所以我对你建议的代码做了调整。。肯定修复了打印空白的问题(现在左上角有一个红色框),但我仍在试图找出如何在打印时将当前帧转换为精灵,以便该帧的所有文本和图像都可以打印,而不是打印红色框

以下是我的更新代码:

导入flash.display.Sprite;
导入flash.printing.PrintJob

print_btn.addEventListener(MouseEvent.CLICK,onPrintClick);
函数onPrintClick(事件:事件):void{

}

这让我发疯了!!哈哈。。如有任何进一步建议,将不胜感激


谢谢

谢谢你的回复!如果要打印屏幕,请尝试printJob.addPage(阶段);
var printJob:PrintJob = new PrintJob();
var mySprite:Sprite = new Sprite();
    mySprite.graphics.beginFill(0xFF0000);
    mySprite.graphics.drawRect(0,0,100,100);
    mySprite.graphics.endFill();

    printJob.start(); 
    printJob.addPage(mySprite); 
    printJob.send();