Using Print2Flash Document API from Flex for ActionScript3 documents
Print2Flash documents can be embedded into Adobe Flex applications and controlled from them using Print2Flash Document API. The documents you intend to embed in Flex must be generated using ActionScript3 standard document template (this is controlled using Document Template field in the Flash Output Tab of Document Options window).Note: There is a method of loading of ActionScript2 documents in Flex detailed in Using Print2Flash Document API from Flex for ActionScript2 documents help page. However, this method is deprecated due to poor interoperability support by the Flash Player between ActionScript2 and ActionScript3 movies.
To facilitate the task of embedding of Print2Flash documents into Flex applications, you may make use of Print2FlashDoc3 Flex component which is included in Print2Flash SDK.
First, copy the component folder named Print2Flash to a directory located at class path of your Flex project It can be the root or src directory of your project.
Then, Print2FlashDoc3 component should appear in the Custom group in the Components window of Adobe Flex Builder. In MXML editor's Design mode drag this component into the layout and specify its position and size. In the Flex Properties window click Alphabetical View button at its top and enter the URL of the Print2Flash document you want to display in the source property.
After that you may launch your application and the Print2Flash document should load into it and appear at the space you placed Print2FlashDoc3 component at. Note that to load a document in Flex and access it via Print2Flash Document API you should clear "Disable Print2Flash Document API support" option when converting the document.
To control the document you should give a name to the Print2FlashDoc3 component instance. This can be done by selecting Print2FlashDoc3 component instance in the layout and setting its id property in the Flex Properties window. Then you need to retrieve a reference to the actual Print2Flash document loaded in your Print2FlashDoc3 component instance using getDoc component method. It should be done no sooner than onLoaded event of this component is fired. So to retrieve a reference to the actual Print2Flash document, you need to specify the code executed when onLoaded event is fired. This can be done if you select a Print2FlashDoc3 component instance in the layout, open Alphabetical View in the Flex Properties window and enter the code in the onLoaded property. For example, if you gave doc name to the Print2FlashDoc3 component instance, your code for retrieval of Print2Flash document reference may look like this:
p2fdoc=doc.getDoc(); |
public var p2fdoc:MovieClip; |
p2fdoc.setCurrentPage(3); |
p2fdoc.addEventListener("onZoomChanged", onZoomChanged); public function onZoomChanged(e:Object):void { trace(e.zoom.toString()); } |
Print2Flash SDK contains a sample of embedding a Print2Flash document into the Flex application.