AS3 使用 PrintJob 打印 MovieClip

编程入门 行业动态 更新时间:2024-10-20 11:55:40
本文介绍了AS3 使用 PrintJob 打印 MovieClip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在尝试创建一个函数,它允许我传入 MovieClip 并打印它.

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

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

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

更多推荐

AS3 使用 PrintJob 打印 MovieClip

本文发布于:2023-11-23 15:59:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622045.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PrintJob   MovieClip

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!