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

Using Print2Flash Document API from Flash with ActionScript2

 You can easily load Print2Flash documents using ActionScript2 into other Flash movies which use ActionScript2 and control document behavior with the help of the following instructions. Note that you cannot load ActionScript3 documents into ActionScript2 movies.

First, include the following function somewhere in your code. This function performs loading of Print2Flash document and returns a reference to the created document. Note that the returned reference may not be valid until the document is fully loaded. You may specify an event listener object as the last parameter to get a notification (onLoaded event) when Print2Flash document is loaded and ready to use.

function LoadPrint2FlashDoc(
    url, // Path of Print2Flash document to load
    x, // x coordinate of the Print2Flash document movie
    y, // y coordinate of the Print2Flash document movie
    width, // Width of Print2Flash document movie
    height, // Height of Print2Flash document movie
    name, // Instance name to assign the Print2Flash document movie
    parent, // Optional: parent object of Print2Flash document movie (default is _root)
    eventSink) // Optional: event handler object
    var intervalID = 0;
    if (!parent) parent=_root
    var container:MovieClip = parent.createEmptyMovieClip(name, getNextHighestDepth());

    var loadFunc = function()
       if (!container.init) return;
       container.init(width, height);
    intervalID = setInterval(loadFunc, 100);
    var mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.loadClip(url, container);
    return container;
Copy Code

Then you may load a Print2Flash document into your Flash movie such as in the following example:

var p2f=LoadPrint2FlashDoc("MyDoc.swf", 0,0,350, 350, "MyDoc");

Copy Code

Note that to load a document in Flash and access it via Print2Flash Document API you should clear "Disable Print2Flash Document API support" option when converting the document.

To get a notification when the document is fully loaded, you may declare the following event listener:

var P2FListener=new Object()
P2FListener.onLoaded=function (p2f) {

Copy Code

and specify it in the last parameter to the declared loader function:

var p2f=LoadPrint2FlashDoc("MyDoc.swf", 0,0,350, 350, "MyDoc",_root,P2FListener);

Copy Code

Then you can manipulate the loaded Print2Flash document programmatically using either reference to the document instance returned from LoadPrint2FlashDoc call or passed to the onLoaded event handler as a parameter:


Copy Code

In the example above the document zoom level is set to 100 percent and document view is navigated to the second page.

To process Print2Flash Document API events you may use the same approach as above for processing onLoaded event. For example, to get event notifications each time when document zoom level is changed, you may declare the following event handler to output new zoom level values to the Flash Professional output window:

P2FListener.onZoomChanged=function (sender, zoom) {

Copy Code

The first parameter of the event handler function should be the sender parameter. It refers to the Print2Flash document to which this event is related. This parameter may be helpful to differentiate between notifications generated by different documents if you have multiple documents in your movie and use a single event handler object. The event handler may have additional parameters specific to each event. For example, onZoomChanged event handler has a zoom parameter which specifies a new zoom level. These parameters are described in Print2Flash Document API events help topic.

To remove (unload) a loaded document properly, you should call uninit function on the document instance. This is to ensure that all resources used by the document are freed.

Print2Flash SDK contains a sample of embedding a Print2Flash document into another Flash movie.