Actionscript 3 (AS3) Printing issue with large SWFs

Publishing Print2Flash Documents embedding them in Flash movies
Post Reply
borg
Posts:3
Joined:Wed Feb 25, 2009 10:31 am
Actionscript 3 (AS3) Printing issue with large SWFs

Post by borg » Thu Feb 26, 2009 11:50 am

Attempting to call printTheDocument() in the onLoaded event listener works fine for small files but if it's greater than 800kbp or so, something is still loading that prevents you from printing.

p2f.addEventListener("onLoaded", function (evt) {
p2f.printTheDocument();
});

I am forced to use a timer that attempts to call printTheDocument() every few seconds. I added an onPrinted event listener to stop the timer. The problem is when the print dialog box is dismissed via "Print" or "Cancel" the timer goes off one last time before the onPrinted listener can go off, because the dialog apparently halts the timer while it's up and it sets off as soon as the dialog is dismissed. This causes the print dialog to open a second time.

var myTimer;
p2f.addEventListener("onPrinted", function (evt) {
myTimer.stop();
});

p2f.addEventListener("onLoaded", function (evt) {
p2f.printTheDocument();

myTimer = new Timer(3000); // 3 seconds should be good
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER, function (evt) {
p2f.printTheDocument();
});
});

What is needed is for the printTheDocument() function to return a success/failure or for a new onLoaded type event function that goes off when printing is actually accessible.

Anyone got any solutions?

Print2Flash, will you address my suggestions or how I can get around this?

borg
Posts:3
Joined:Wed Feb 25, 2009 10:31 am

Response from print2flash

Post by borg » Fri Feb 27, 2009 10:26 am

onLoaded event is fired when the document viewer is loaded but document pages may not be available yet. As pages become available, onPageLoaded events are fired. So it is better to invoke this function after the last page is loaded and possibly wait yet a bit before starting printing. So you need to write an onPageLoaded event handler which checks if the last page has been loaded (the last page number can be determined with getNumberOfPages function) and then start a timer that tries printing after a certain interval, say, 1 second. This approach should be quite reliable.

In the current version of Print2Flash printTheDocument function indeed does not return a value. Thank you for your suggestion! We’ll make it return a success value in future versions of Print2Flash.

Best regards,
Print2Flash Support Team

Note that the documentation says that getNumberOfPages() returns a value but it doesn't. You have to do this crazy stuff to get the value:

var totalPages;
function ongetNumberOfPages(num) {
totalPages = num;
}
p2f.getNumberOfPages(ongetNumberOfPages);

Post Reply