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 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:
Print2Flash documents are represented by standard MovieClip class so p2f
variable referenced above needs to be declared of that type:
public var p2fdoc:MovieClip;
|
To call functions of
Print2Flash Document API, you need to invoke
them as
methods of the retrieved document reference. For example, to invoke
setCurrentPage
function you may use the code such as the following:
p2fdoc.setCurrentPage(3);
|
To handle events fired by Print2Flash documents, you need to add an event
handler invoking standard addEventListener method on the retrieved document
reference. For example, to process
onZoomChanged event, you may use the code such as this:
p2fdoc.addEventListener("onZoomChanged", onZoomChanged);
public function onZoomChanged(e:Object):void {
trace(e.zoom.toString());
}
|
The event processing code may reference an object passed to the event handler which
holds the event detailed information. Each event has special event fields
detailed in the Print2Flash Document API Events
help topic. For example, in
onZoomChanged event processing code above zoom parameter is used to output the
new zoom level to the console window.
Print2Flash SDK contains a sample of
embedding a Print2Flash document into the Flex application.
|