Home  • Download  • Register Now!  • Benefits  • Help  • Testimonials  • Samples  • Screenshots  • Awards  • Forum  • Convert Documents Online  • Print2Flash APIs  • Print2Flash vs. FlashPaper  • Contact Us
 Help Contents

Using Print2Flash Document API from Flex for ActionScript2 documents

Note: Embedding of ActionScript2 documents in Flex 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 ActionScript3 documents with Flex. You can control the ActionScript version using Document Template field in the Flash Output Tab of Document Options window. See Using Print2Flash Document API from Flex for ActionScript3 documents help topic for more information.

Print2Flash documents using ActionScript2 can be embedded into Adobe Flex applications and controlled from them using Print2Flash Document API. To facilitate this task, you may make use of Print2FlashDoc 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 directory of your project.

Then, Print2FlashDoc 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 Print2FlashDoc 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 Print2FlashDoc component instance. This can be done by selecting Print2FlashDoc component instance in the layout and setting its id property in the Flex Properties window.

To invoke functions of Print2Flash Document API, use the name you have given to the Print2FlashDoc instance as an object variable and invoke Print2Flash Document API functions as methods of this object. For example, to invoke setCurrentPage function on the instance named doc use the code such as the following:

Invoking functions that return values is a bit tricky in Flex as interaction between Flex and Print2Flash documents is asynchronous. It means that you should break your function calling code into two parts: the first part for calling the function and another part for obtaining the result. When calling such functions you should pass an additional argument at first position which must denote the function that will receive the return value. For example, to call getCurrentPage function you should use the code such as this:

public function ongetCurrentPage(page:Number):void {

Here ongetCurrentPage is the function that receives the result of the getCurrentPage function which is passed to it as a parameter. When calling getCurrentPage function, the first argument denotes ongetCurrentPage function as the function to call for receiving the return value.

To handle events fired by Print2Flash documents, you should enter the event handling code in the respective event properties of the Print2FlashDoc component instance. To accomplish this, select a Print2FlashDoc component instance in the layout and enter event handling code in its event properties in the Flex Properties window. For example, to process onZoomChanged event enter the processing code in the onZoomChanged property of the Print2FlashDoc component instance.

The event processing code may reference an object named event which holds the detailed event information. Each event has a special type of event object. These types are detailed in the table below.


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

For example, in onZoomChanged event processing code you may have the code which outputs the new zoom level to the console window like this:

Print2FlashDoc component exposes a additional event named onLoaded. It is called when the document is ready to be accessed by API methods. You should not call any methods of Print2FlashDoc component before onLoaded event is fired.

To remove (unload) a loaded document properly, you should call unload method of the Print2FlashDoc component. This is to ensure that all resources used by the document are freed. If you want to load another document reusing the same Print2FlashDoc component 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 the Flex application.