Using Print2Flash Document API for ActionScript2 documents from Flash with ActionScript3
Note: Embedding of ActionScript2 documents in other Flash movies compiled with ActionScript3 support and using Print2Flash Document API from it is possible but not recommended. The method described below is deprecated due to poor interoperability support by the Flash Player between ActionScript2 and ActionScript3 movies. It is preferable to use ActionScript2 documents with movies compiled with ActionScript2 support. See Using Print2Flash Document API from Flash with ActionScript 2 help topic for more information. If you still need to be able to load Print2Flash documents in other Flash movies compiled with ActionScript3 support or in Flex applications, consider using ActionScript3 documents instead. You can control the ActionScript version using Document Template field in the Flash Output Tab of Document Options window. See Using Print2Flash Document API for ActionScript3 documents from Flash and Using Print2Flash Document API from Flex for ActionScript3 documents help topics for more information.
To facilitate the task of loading of ActionScript2 documents into other Flash movies created in Adobe Flash CS Professional with ActionScript3 support, you may make use of Print2FlashDoc 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 P2FDoc:Print2FlashDoc=new Print2FlashDoc("sample.swf",10,50,500,350,this); |
- 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.
Then you may call any Document API functions using the created Print2FlashDoc class instance reference. For example:
P2FDoc.setCurrentPage(5); |
public function ongetCurrentPage(page:Number):void { trace(page); } P2FDoc.getCurrentPage(ongetCurrentPage); |
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 the event handler like this:
function onPageChanged(e:PageChangedEvent) { trace(e.page.toString()) } P2FDoc.addEventListener("onPageChanged", onPageChanged); |
Event |
Event object type |
Event object properties |
onPageChanged | Print2Flash.PageChangedEvent | page:Number - page number |
onZoomChanged | Print2Flash.ZoomChangedEvent | zoom:Number - zoom level |
onSelection | Print2Flash.Selection | selection:Object - text selection described by object of SelectionRange type |
onToolChanged | Print2Flash.ToolChangedEvent | tool:String - tool represented by text as in getCurrentTool function |
onVisibleAreaChanged | Print2Flash.VisibleAreaEvent | area:Object - visible area described by object of VisibleArea type |
onLinkClicked | Print2Flash.LinkClickedEvent | page:Number - the number of the page on
which the clicked link is located url:String - the link address |
onPageLoaded | Print2Flash.PageLoadedEvent | page:Number - page number |
onPrinted | Print2Flash.PrintedEvent | No properties |
onLoaded | flash.events.Event | No properties |
onUnloadCompletedEvent | Print2Flash.UnloadCompletedEvent | No properties |
If you want an event handler to stop receiving event notifications, you need to remove the handler using removeEventListener method:
P2FDoc.removeEventListener("onPageChanged", onPageChanged); |
To remove (unload) a loaded document properly, you should call unload method of the Print2FlashDoc class. This is to ensure that all resources used by the document are freed. If you want to load another document reusing the same Print2FlashDoc class instance, you may not do this until onUnloadCompletedEvent event is fired. If you try to load a document before this event is fired, you'll get an exception.
Print2Flash SDK contains a sample of embedding a Print2Flash document into a Flash movie which uses ActionScript 3.