Using Print2Flash Document API from Flash with ActionScript 2

You can easily load Print2Flash documents into other Flash movies and control
document behavior using the following instructions.
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());
container._x=x;container._y=y
var loadFunc = function()
{
if (!container.init) return;
container.init(width, height);
clearInterval(intervalID);
eventSink.onLoaded(container);
container.addListener(eventSink);
}
intervalID = setInterval(loadFunc, 100);
var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.loadClip(url, container);
return container;
}
Copy CodeIf
you want to load a document created with Print2Flash version 2.5.2 or earlier,
please use this code instead of the previous:
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());
container._x=x;container._y=y
var loadFunc = function()
{
if (!container.setSize) return;
container.setSize(width, height);
container.setCurrentPage(1);
clearInterval(intervalID);
eventSink.onLoaded(container);
container.addListener(eventSink);
}
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
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) {
p2f.setCurrentZoom(100);
p2f.setCurrentPage(2);
}
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:
p2f.setCurrentZoom(100);
p2f.setCurrentPage(2);
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) {
trace(zoom)
}
Copy Code The
sender parameter passed to Print2Flash Document API Events
handlers 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.
Print2Flash SDK contains a sample of
embedding a Print2Flash document into another Flash movie.
|