使用的PrintJob打印影片剪辑AS3 [英] AS3 using PrintJob to print a MovieClip

查看:194
本文介绍了使用的PrintJob打印影片剪辑AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在试图创建一个函数,它可以让我通过了影片剪辑并打印。

I am currently trying to create a function which will allow me to pass in a MovieClip and print it.

下面是该函数的简化版本:

Here is the simplified version of the function:

function printMovieClip(clip:MovieClip) {

var printJob:PrintJob = new PrintJob();
var numPages:int = 0;
var printY:int = 0;
var printHeight:Number;

if ( printJob.start() ) {

/* Resize movie clip to fit within page width */
if (clip.width > printJob.pageWidth) {
   clip.width = printJob.pageWidth;
   clip.scaleY = clip.scaleX;
}

numPages = Math.ceil(clip.height / printJob.pageHeight);

/* Add pages to print job */
for (var i:int = 0; i < numPages; i++) {
 printJob.addPage(clip, new Rectangle(0, printY, printJob.pageWidth, printJob.pageHeight));
 printY += printJob.pageHeight;
}

/* Send print job to printer */
printJob.send();

/* Delete job from memory */
printJob = null;

}

}

printMovieClip( testMC );

不幸的是,这是工作不正常,即打印影片剪辑和做分页的整个宽度的长度。

Unfortunately this is not working as expected i.e. printing the full width of the MovieClip and doing page breaks on the length.

推荐答案

我忘了缩放打印区域相匹配的影片剪辑被调整。对工作的解决方案如下图:

I forgot to scale the print area to match the movie clip being resized. See below for working solution:

function printMovieClip(clip:MovieClip) {

    var printJob:PrintJob = new PrintJob();
    var numPages:int = 0;
    var printArea:Rectangle;
    var printHeight:Number;
    var printY:int = 0;

    if ( printJob.start() ) {

	    /* Resize movie clip to fit within page width */
	    if (clip.width > printJob.pageWidth) {
		    clip.width = printJob.pageWidth;
		    clip.scaleY = clip.scaleX;
	    }

	    /* Store reference to print area in a new variable! Will save on scaling calculations later... */
	    printArea = new Rectangle(0, 0, printJob.pageWidth/clip.scaleX, printJob.pageHeight/clip.scaleY);

	    numPages = Math.ceil(clip.height / printJob.pageHeight);

	    /* Add pages to print job */
	    for (var i:int = 0; i < numPages; i++) {
		    printJob.addPage(clip, printArea);
		    printArea.y += printArea.height;
	    }

	    /* Send print job to printer */
	    printJob.send();

	    /* Delete job from memory */
	    printJob = null;

    }

}

printMovieClip( testMC );

这篇关于使用的PrintJob打印影片剪辑AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆