Home  • Download  • Register Now!  • Benefits  • Help  • Testimonials  • Samples  • Screenshots  • Awards  • Forum  • Convert Documents Online  • Print2Flash APIs  • Print2Flash vs. FlashPaper  • Contact Us
 Help Contents

Designing Custom Document Viewer using ActionScript 2

Designing a document viewer using ActionScript 2 requires Flash and ActionScript 2 programming skills. For developing of your viewer you may use Macromedia Flash Professional or Adobe Flash CS Professional.

Print2Flash SDK contains a sample of a simple ActionScript 2 document viewer developed in Macromedia Flash Professional. It can be imported into Adobe Flash CS Professional format as well. We recommend using this sample as a starting point when developing your own viewer. The description below deals with this sample code so refer to it for full details.

General viewer movie requirements

The viewer should be a Flash movie which is published for Flash Player version 8 or higher and which uses ActionScript 2. The viewer may contain any number of frames. When Print2Flash generates a document, it takes your viewer movie, appends document pages to it and writes the result as the output document Flash file. It is the responsibility of the viewer movie to attach appended pages and use them for displaying of document interface. The SDK sample uses the standard ScrollPane component for displaying document pages in an area where a continuous stack of document pages can be scrolled. Of course, you may use other methods for document display attaching document pages not to ScrollPane component but to other movie clips.

When generating output Flash document, Print2Flash modifies your viewer movie by adding additional frames to it, one frame per each document page. So keep in mind that the number of frames when your viewer movie is executed is greater than the number of frames in your viewer at design time by the number of document pages.

Your viewer should not stop the movie in the last frame and should allow continuous movie execution past the last frame. Print2Flash itself stops the movie after the last appended frame.

Attaching page movies

Each page movie is represented by a library symbol. To create a page movie instance, you may use this function:

function AttachPageMovie(pageno,parent) {
    var id="Page"+pageno;
    var movie=parent.attachMovie(id, id, pageno);
    return movie;
The function accepts two parameters:

The function returns a reference to the created MovieClip instance of the page movie. If a movie cannot be created, undefined is returned.

Print2Flash appends page movies to the viewer movie in such a way so that document can be opened and viewed by users before the Flash file is fully loaded. This makes user interface more responsive and allows users to start viewing the document sooner without having to wait until the document file is loaded in full. As a result of this, when executing the code in your first frame for the first time, no pages are available yet. They become available later as pages code is being loaded by the Flash Player. Because of this we recommend to start a timer and attach pages in timer function until all pages are loaded as demonstrated in this code:

var chLoadedPagesInt=setInterval(CheckLoadedPages,100);

function CheckLoadedPages() {
    if (loadedPages>=totalPages) clearInterval(chLoadedPagesInt);

function ScanPages(startpage) {
    var pageno=startpage;
    do {
        var movie=AttachPageMovie(pageno,parent);
        var validpage=typeof(movie)!="undefined";
        if (validpage) { 
            // Process page here: scale, position, etc.
    } while(validpage); 
This code assumes that parent variable is set to a reference to the parent movie. After successful attachment you may process the page instance: scale, position it, etc. as indicated in the code comment.

Document settings

Along with page movies Print2Flash stores additional settings in the document file which may help the viewer in document rendering. The list of available parameters is contained in Custom Document Viewer Settings help topic. To read these settings you need to declare and execute this code:

var settings=new XML();

function GetSetting(name) {
    return settings.firstChild.attributes[name];

function ReadSettings(name){
    var movie=_root.attachMovie(name,name,_root.getNextHighestDepth());
    return val;
Then you may use the declared GetSetting function to retrieve a setting value passing it the setting name as a parameter. For example, to get the total number of pages in the document, you may use this code:
var totalPages:Number=parseInt(GetSetting("PageNum"));
Note that all values are returned by GetSetting function as strings so you may need to convert them to other types as demonstrated in the previous sample with the standard parseInt function.