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); |
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(); } |
Then you may call Document API functions using the retrieved document reference. For example:
P2FDoc.setCurrentPage(5); |
function onPageChanged(e:Object) { trace(e.page.toString()) } P2FDoc.addEventListener("onPageChanged", onPageChanged); |
If you want an event handler to stop receiving event notifications, you need to remove the handler using removeEventListener method:
P2FDoc.removeEventListener("onPageChanged", onPageChanged); |