load and unload

Publishing Flash documents by embedding them in Flex applications
Post Reply
Posts: 5
Joined: Tue Jan 20, 2009 12:26 am

load and unload

Post by drvortex » Tue Jan 20, 2009 12:35 am


i am using flex plug in 3.2, flashplayer10.

i want to be able to load and unload a doc. here is your adapted code.
i realize i have to use the onUnloadCompletedEvent but i don't know how
i am trying to figure out how to add the listener
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:ns1="Print2Flash.*" width="910"
creationComplete="applicationComplete()" height="610" horizontalScrollPolicy="off" verticalScrollPolicy="off">


import Print2Flash.*
import weborb.data.DynamicLoadEvent;
import mx.controls.Alert;
private var totalPages:Number;
private var sourceSwf:String;

private var unloadCompletedEvent:UnloadCompletedEvent;

private function applicationComplete():void

function Init(){


public function updateArtist(event:LoadedArtist){

sourceSwf = "galleries/swf_files_flash2print/" + event.artistSource + ".swf"

sourceSwf = "galleries/swf_files_flash2print/" + event.artistSource + ".swf"
doc.source = sourceSwf


public function SetPageNo(page:Number):void {
PageNo.text = page+" of "+totalPages;


public function ongetNumberOfPages(num:Number):void {
//Alert.show( "Test ID","test" );

public function ongetUnloadCompleted(event):void {
//Alert.show( "Event","test " + sourceSwf );

var unloading = UnloadCompletedEvent(event);


private function artistResult():void {

Alert.show( "Event","test doc " + sourceSwf );
doc.source = sourceSwf

<ns1:Print2FlashDoc x="10" y="41" width="733" height="549" id="doc" unload = "ongetUnloadCompleted(event)" onLoaded="doc.getNumberOfPages(ongetNumberOfPages)" onPageChanged="SetPageNo(event.page)"/>
<mx:Image x="10" y="10" source="images/dragbyhand.gif" click="doc.setCurrentTool("move")"/>
<mx:Image x="35" y="10" source="images/selecttext.gif" click="doc.setCurrentTool("select")"/>
<mx:Image x="63" y="10" source="images/fitwidth.gif" click="doc.setCurrentZoom("width")"/>
<mx:Image x="89" y="10" source="images/fitpage.gif" click="doc.setCurrentZoom("page")"/>
<mx:Image x="115" y="10" source="images/prevpage.gif" click="doc.PreviousPage()"/>
<mx:Image x="194" y="10" source="images/nextpage.gif" click="doc.NextPage()"/>
<mx:Image x="224" y="10" source="images/rotate.gif" click="doc.Rotate()"/>
<mx:Image x="253" y="10" source="images/print.gif" click="doc.printTheDocument()"/>
<mx:Image x="284" y="10" source="images/newwindow.gif" click="doc.OpenInNewWindow()"/>
<mx:Image x="312" y="10" source="images/help.gif" click="doc.OpenHelpPage()"/>
<mx:Label x="145" y="16" width="47" id="PageNo" textAlign="center"/>

Posts: 281
Joined: Sat Dec 15, 2007 4:48 pm

Re: load and unload

Post by staff » Thu Jan 22, 2009 12:52 am

To load another Print2Flash document using the same Print2FlashDoc component instance, you need to call unload method of the component, wait for onUnloadCompleted event and then load another document using source property of the component.
To declare onUnloadCompleted event handler you need to use this component embedding code:

Code: Select all

<ns1:Print2FlashDoc x="10" y="41" width="733" height="549" id="doc" onUnloadCompleted = "ongetUnloadCompleted(event)" onLoaded="doc.getNumberOfPages(ongetNumberOfPages)" onPageChanged="SetPageNo(event.page)"/>
To staring unloading you may use this code:

Code: Select all

And your onUnloadCompleted event handler may look like this:

Code: Select all

public function ongetUnloadCompleted(event:Event):void {

Posts: 2
Joined: Tue Feb 17, 2009 10:00 am

Re: load and unload

Post by solisarg » Tue Feb 17, 2009 11:13 am

I'm at the same point, loading different documents in the Print2FlashDoc component, using external controls to handle the document manipulation.
When unloading current one and loading the next, the LocalConnection seems to take some time (long time, between 20-60 seconds) to update the new data, showing meanwhile the old document data (page quantity i.e) while buttons don't work. After some time, data updates and quantity of pages and controls works ok.

Looking inside the print2FlashDoc component, I can see that the LocalConnection is closed and reopen ok when I load the next doc, but calls to OnAPILCStatus (LocalConnection StatusEvent handler) whit a null code and status level fires constantly until data is updated.

Aditionally, when you iterate trough the proccess (Load A, B, C then again A, B, C) the problems dissapears. Delay is similar between long and short documents, so I think is more related to something around LocalConnection or probably something around loaderInfo not unloading.

Since LocalConnection implementation is browser/OS dependant, probably this could vary. Anyway I,m working on a fairly general setup: Windows Vista + IE , Vista + FF , Flash Player 10, Flex 3 (sdk 3.2), Print2Flash SDK 2.7.3

Any idea about where to look or workarounds are welcome. Can post some example if needed


Posts: 4
Joined: Tue Dec 22, 2009 1:47 am

Re: load and unload

Post by Romeo » Thu Jan 14, 2010 3:29 am

Hi, after the unloading is completed, I've again put the source but now it says "undefined". Any ideas?

Posts: 4
Joined: Tue Dec 22, 2009 1:47 am

Re: load and unload

Post by Romeo » Thu Jan 14, 2010 4:47 am

Solved: I used p2f.callLater(..), seem's the p2f is not ready yet after I've unloaded.

Posts: 1
Joined: Sat Aug 06, 2011 8:33 pm


Post by GenueSafeveve » Sat Aug 06, 2011 8:36 pm


Posts: 3
Joined: Tue Feb 07, 2012 6:09 am

Re: load and unload

Post by Esmi » Tue Feb 07, 2012 6:45 am

Romeo wrote:Solved: I used p2f.callLater(..), seem's the p2f is not ready yet after I've unloaded.
callLater(function (someArg:String):void {
something.text = someArg;
}, 'Something')

Post Reply