Using Print2Flash Document API for ActionScript3 documents from Flash

Print2Flash documents using ActionScript3 can be loaded into other Flash movies created in Adobe
Flash CS Professional and controlled using Print2Flash Document API.
Such Flash movies must be compiled with ActionScript3 support. You cannot load
ActionScript3 documents into Flash movies which use ActionScript2.
Note: There is a method of loading of ActionScript2 documents in Flash
movies using ActionScript3
detailed in Using Print2Flash
Document API for ActionScript2 documents from Flash with ActionScript3 help page. However, this method is
deprecated due to poor interoperability support by the Flash Player between
ActionScript2 and ActionScript3 movies.
To facilitate loading of ActionScript3 documents, you may make use of Print2FlashDoc3 class which is included in Print2Flash SDK.
First, copy the folder named Print2Flash to a directory located at class path
of your project It can be the root directory of your project.
Then, you may use the code such as the following to load a Print2Flash document:
import Print2Flash.*;
var P2FDocLoader:Print2FlashDoc3=new Print2FlashDoc3("sample.swf",10,50,500,350,this);
|
The meanings of Print2FlashDoc constructor parameters (from left to right)
are:
- 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;
- parent- parent object of Print2Flash document movie.
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 learn when the document has started loading and when
Print2Flash Document API becomes
available, you need to declare a listener for onLoaded event like this:
P2FDocLoader.addEventListener(Print2FlashDoc3.ONLOADEVENT, OnLoaded);
var P2FDoc:MovieClip;
function OnLoaded(e:Event) {
P2FDoc=P2FDocLoader.getDoc();
}
|
In onLoaded event handler you may retrieve a reference to the
Print2Flash document instance itself using getDoc method of Print2FlashDoc3
class as demonstrated in the code above. Print2Flash documents are represented by
the standard MovieClip class.
Then you may call Document API functions using the
retrieved document reference. For example:
P2FDoc.setCurrentPage(5);
|
To handle events fired by Print2Flash documents, you should register an event
handler using standard addEventListener method. For example, to handle
onPageChanged
event you need to declare an event handler like this:
function onPageChanged(e:Object) {
trace(e.page.toString())
}
P2FDoc.addEventListener("onPageChanged", onPageChanged);
|
The event processing code may reference an object passed to the event handler
method as a parameter which holds event detailed information. Such object has
special event fields detailed in the Print2Flash Document API Events
help topic. For example, in
onPageChanged event processing code above page parameter is used to
output the current page number to the console window.If you want an event handler to stop receiving event notifications, you need
to remove the handler using removeEventListener method:
P2FDoc.removeEventListener("onPageChanged", onPageChanged);
|
Print2Flash SDK contains a sample of
embedding an ActionScript3 Print2Flash document into a Flash movie which uses ActionScript3.
|