1

ステージを印刷できません:

btn.addEventListener(MouseEvent.CLICK, printFunction);

function printFunction(event:MouseEvent):void
{
    var myPrintJob:PrintJob = new PrintJob();
    myPrintJob.addPage(0);
    myPrintJob.send();

}

それは私にコンパイルエラーを与えます:

1118: 静的なタイプの flash.display:DisplayObject を持つ値が、おそらく無関係なタイプの flash.display:Sprite に暗黙的に強制されています。

私も試しました:

myPrintJob.addPage(Sprite(0));

コンパイル エラーはありません。しかし、印刷ボタンをクリックすると、印刷ダイアログが表示されず、Flash の出力セクションで次のエラーが表示されます。

TypeError: エラー #1034: 型強制に失敗しました: 0 を flash.display.Sprite に変換できません。Untitled_fla::MainTimeline/printFunction() で

4

1 に答える 1

3

Printjob の addPage メソッドは、最初のパラメーターとして Sprite を想定しています。

0を渡すことで何を達成しようとしていますか?

空白のページが必要な場合は、次を試してください。

var myPrintJob:PrintJob = new PrintJob();
myPrintJob.start(); /*Initiates the printing process for the operating system, calling the print dialog box for the user, and populates the read-only properties of the print job.*/
myPrintJob.addPage( new Sprite() );
myPrintJob.send();

赤い四角の別の例:

var s:Sprite = new Sprite();
s.graphics.beginFill(0xFF0000);
s.graphics.drawRect(0, 0, 80, 80);
s.graphics.endFill();

var myPrintJob:PrintJob = new PrintJob();
myPrintJob.start(); /*Initiates the printing process for the operating system, calling the print dialog box for the user, and populates the read-only properties of the print job.*/
myPrintJob.addPage( s );
myPrintJob.send();

詳細はこちら

ステージの一部を印刷するには、次のことができます。

1) 印刷するすべてのものをスプライトでラップし、そのスプライトを addPage() に渡します。

また

2) BitmapData を使用する

 var bd :BitmapData = new BitmapData(stage.width, stage.height, false);
 bd.draw(stage);
 var b:Bitmap = new Bitmap (bd);
 var s:Sprite = new Sprite();
 s.addChild(b);

 var printArea = new Rectangle( 0, 0, 200, 200 ); // The area you want to crop

 myPrintJob.addPage( s, printArea );
于 2013-06-23T17:12:10.403 に答える