load and unload
Posted: Tue Jan 20, 2009 12:35 am
hi
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">
<mx:Script>
<![CDATA[
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
{
parentApplication.addEventListener(LoadedArtist.LOADEDARTIST,updateArtist);
}
function Init(){
}
public function updateArtist(event:LoadedArtist){
if(sourceSwf){
sourceSwf = "galleries/swf_files_flash2print/" + event.artistSource + ".swf"
doc.unload()
}else{
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" );
totalPages=num;
SetPageNo(1);
}
public function ongetUnloadCompleted(event):void {
//Alert.show( "Event","test " + sourceSwf );
var unloading = UnloadCompletedEvent(event);
unloading.addEventListener("loaded=",
function(event:DynamicLoadEvent):void
{
artistResult()
});
}
private function artistResult():void {
Alert.show( "Event","test doc " + sourceSwf );
doc.source = sourceSwf
}
]]>
</mx:Script>
<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"/>
</mx:Canvas>
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">
<mx:Script>
<![CDATA[
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
{
parentApplication.addEventListener(LoadedArtist.LOADEDARTIST,updateArtist);
}
function Init(){
}
public function updateArtist(event:LoadedArtist){
if(sourceSwf){
sourceSwf = "galleries/swf_files_flash2print/" + event.artistSource + ".swf"
doc.unload()
}else{
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" );
totalPages=num;
SetPageNo(1);
}
public function ongetUnloadCompleted(event):void {
//Alert.show( "Event","test " + sourceSwf );
var unloading = UnloadCompletedEvent(event);
unloading.addEventListener("loaded=",
function(event:DynamicLoadEvent):void
{
artistResult()
});
}
private function artistResult():void {
Alert.show( "Event","test doc " + sourceSwf );
doc.source = sourceSwf
}
]]>
</mx:Script>
<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"/>
</mx:Canvas>