5

我目前正在尝试创建一个允许我传入 aMovieClip并打印它的函数。

这是该函数的简化版本:

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 );

不幸的是,这没有按预期工作,即打印整个宽度MovieClip并在长度上进行分页。

4

3 回答 3

5

我忘记缩放打印区域以匹配正在调整大小的影片剪辑。请参阅下面的工作解决方案:

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 );
于 2009-09-14T16:47:52.747 回答
2

感谢您的开源精神!基于您的出色工作,我实现了它并进行了一些改进以解决我实际的 MovieClip 打印问题。我取得的主要进展是制定了一种仅通过发送一个打印作业来打印具有多帧的 MovieClip 的方法。当然,我解决了“打印电影剪辑的全宽”的问题。因为 SWF 以矢量图的形式存储内容,所以您需要做的是确保clip.height = printArea.height; clip.width = printArea.width;. 这是一个简单的方法:

 1//MC printing Function 
 2private function printMovieClip(clip:MovieClip):void
 3{
 4    var printJob:PrintJob=new PrintJob();
 5    var printArea:Rectangle;
 6    if (!printJob.start())
 7      return;
 8    //The page you choose to print ,"selectPages" is a mx:combox object i used to support printing one frame of MC
 9    var printPage:int=selectPages.selectedItem.data;
10    if (printPage == 0) //print all frames of the MovieClip
11      {
12        for (var i:int=1; i <= clip.totalFrames; i++)
13        {
14          clip.gotoAndStop(i);
15          /* Resize movie clip to fit within page width */
16          clip.width=printJob.pageWidth;
17          clip.scaleY=clip.scaleX;
18          /* Store reference to print area in a new variable! Will save on scaling */
19          printArea=new Rectangle(0, 0, printJob.pageWidth, printJob.pageHeight);
20          //numPages=Math.ceil(clip.height / printJob.pageHeight);
21                  /* Add pages to print job */
22          printJob.addPage(clip, printArea);
23        }
24      }
25    else //print the selected frame
26    {
         //goto the selected frame firstly
27        clip.gotoAndStop(printPage);
28        /* Resize movie clip to fit within page width */
29        clip.width=printJob.pageWidth;
30        clip.scaleY=clip.scaleX;
31        printArea=new Rectangle(0, 0, printJob.pageWidth, printJob.pageHeight);
32         /* Add pages to print job */
33        printJob.addPage(clip, printArea);
34        }
35
36        /* Send print job to printer */
37        printJob.send(); 
38         /* Delete job from memory */
39        printJob=null;
40
41    }

如果您想了解更多信息,可以看一下我的剪辑图片(并让您了解一点中文):都在我的博客中。还有MovieClip缩略图(还是中文的)。

于 2009-11-17T15:12:09.520 回答
0

我添加了一个小修复程序,在打印作业完成后重置 MovieClip 的尺寸。问题在于,当您打印的内容比您的页面大时,代码还会在舞台上缩放影片剪辑。所以我修正了...没什么特别的,但可能对其他人有用:)

此代码还修复了您的透明 PNG 在您的打印件上也将是透明的事实

protected function printMovieClip(clip:MovieClip):void {

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

            if ( printJob.start() ) {

                originalWidth = clip.width;
                originalHeight = clip.height;

                if (clip.width > printJob.pageWidth) {
                    clip.width = printJob.pageWidth;
                    clip.scaleY = clip.scaleX;
                }

                printArea = new Rectangle(0, 0, printJob.pageWidth/clip.scaleX, printJob.pageHeight/clip.scaleY);

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

                for (var i:int = 0; i < numPages; i++) 
                {
                    printJobOptions.printAsBitmap = true;
                    printJob.addPage(clip, printArea, printJobOptions);
                    printArea.y += printArea.height;
                }

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

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

                /* reset the clips width and height on stage so it is back at its original size*/
                clip.width = originalWidth;
                clip.height = originalHeight;
            }

        }
于 2012-06-16T10:30:29.020 回答