flex 加载flashpaper
http://my.oschina.net/Boder/blog/933
//
主应用loadFp.mxml
<!-- l version = " 1.0 " encoding = " utf-8-->
<!-- [CDATA[
import com.magReader.FlashPaperLoader;
// flashpaper加载器
private var magReader:FlashPaperLoader;
private function initType(): void
{
var urlStr:String = " Fpl.swf?url=template.swf " ;
magReader = new FlashPaperLoader();
magReader.source = urlStr;
magReader.visible = false ;
magContainer.addChild(magReader);
// loadingBar.visible = true;
magReader.addEventListener(FlashPaperLoader.FLASH_PAPER_LOADED,fpLoaded);
}
// flashpaper已经加载完成
private function fpLoaded(evt:Event): void
{
// trace("magContainer width = " + magContainer.width + " magContainer height = " + magContainer.height);
magReader.setSize(magContainer.width,magContainer.height);
magReader.visible = true ;
// loadingBar.visible = false;
// 去掉进度条
// magContainer.removeChild(loadingBar);
// 删除事件侦听
magReader.removeEventListener(FlashPaperLoader.FLASH_PAPER_LOADED,fpLoaded);
}
/**
*
* 改变容器显示大小
* */
public function changSize(): void
{
if (magReader != null )
{
magReader.setSize(magContainer.width,magContainer.height);
}
}
]] -->
<!-- l version = " 1.0 " encoding = " utf-8-->
<!-- [CDATA[
import com.magReader.FlashPaperLoader;
// flashpaper加载器
private var magReader:FlashPaperLoader;
private function initType(): void
{
var urlStr:String = " Fpl.swf?url=template.swf " ;
magReader = new FlashPaperLoader();
magReader.source = urlStr;
magReader.visible = false ;
magContainer.addChild(magReader);
// loadingBar.visible = true;
magReader.addEventListener(FlashPaperLoader.FLASH_PAPER_LOADED,fpLoaded);
}
// flashpaper已经加载完成
private function fpLoaded(evt:Event): void
{
// trace("magContainer width = " + magContainer.width + " magContainer height = " + magContainer.height);
magReader.setSize(magContainer.width,magContainer.height);
magReader.visible = true ;
// loadingBar.visible = false;
// 去掉进度条
// magContainer.removeChild(loadingBar);
// 删除事件侦听
magReader.removeEventListener(FlashPaperLoader.FLASH_PAPER_LOADED,fpLoaded);
}
/**
*
* 改变容器显示大小
* */
public function changSize(): void
{
if (magReader != null )
{
magReader.setSize(magContainer.width,magContainer.height);
}
}
]] -->
//
flash cs3代码,生成所需要的fpl.swf
import flash.display.Stage;
Stage.align = " LT " ;
// Stage.scaleMode = "showAll";
var url = " template.swf " ;
var fp;
// localConnection通讯接口
var caller:LocalConnection = new LocalConnection();
var sender:LocalConnection = new LocalConnection();
caller.connect( " _flashpaperloader " );
caller.allowDomain( " * " );
sender.allowDomain( " * " );
Security.allowDomain( " * " );
// 设置页面
// caller.setPage = function(n:Number)
// {
// fp.setCurrentPage(n);
// }
// 设置大小
caller.setPaperSize = function(w:Number,h:Number)
{
trace( " fpLoader width= " + w + " height = " + h) ;
fp.setSize(w,h);
}
// 设置缩放
// caller.setCurrentZoom = function(zoom:Object)
// {
// fp.setCurrentZoom(zoom);
// sendCurrentZoom();
// }
// 设置下一页
// caller.nextPage = function()
// {
// var p:Number = fp.getCurrentPage();
// if(p + 1 <= fp.getNumberOfPages())
// fp.setCurrentPage(p + 1);
// }
// 设置上一页
// caller.prePage = function()
// {
// var p:Number = fp.getCurrentPage();
// if(p - 1 > 0)
// fp.setCurrentPage(p - 1);
// }
// 卸载
caller.unload = function()
{
caller.close();
caller = null ;
sender = null ;
fp.destroy();
fp = null ;
unloadAndStop();
paper.unloadMovie();
paper = null ;
}
// function: loadFlashPaper
// ------------------------
// Load FlashPaper document, size it,
// Parameters:
// path_s: Path of SWF to load
// dest_mc: Movie clip to hold the imported SWF
// width_i: New size of the dest MC
// height_i: New size of the dest MC
// loaded_o: (optional) Object to be notified that loading is complete
function loadFlashPaper(path_s, dest_mc, loaded_o) {
var intervalID = 0 ;
var loadFunc = function(){
trace( " 加载开始. " );
dest_mc._visible = false ;
fp = dest_mc.getIFlashPaper();
if ( ! fp) {
return ;
} else if ( ! fp.setSize( 0 , 0 )){
trace( " 没有设置窗口大小 " );
return ;
} else {
trace( " flashPaper加载成功了 " );
clearInterval(intervalID);
// var pages_i = fp.getNumberOfPages();
// paper.toolbar_mc.brandClip_mc.swapDepths(1000);
// paper.toolbar_mc.brandClip_mc.removeMovieClip();
// ctrlHolder_mc.swapDepths(_root.control_mc);
dest_mc._visible = true ; // Now show the document
// _root.control_mc._visible = true; // Now show the controller
loaded_o.onLoaded(fp);
}
}
intervalID = setInterval(loadFunc, 100 );
dest_mc.loadMovie(path_s);
}
// function: onLoaded()
// ------------------------
// Called once loading is complete
// Parameters:
// fp: FlashPaper interface (returned by getIFlashPaper())
function onLoaded() {
// We can now call the FlashPaper API functions.
// Remove the standard user interface features:
// fp.showUIElement("PrevNext", false);
fp.showUIElement( " Print " , false );
// fp.showUIElement("Find", false);
// fp.showUIElement("Tool", false);
// fp.showUIElement("Pop", false);
// fp.showUIElement("Zoom", false);
// fp.showUIElement("Page", false);
// fp.showUIElement("Overflow", false);
// fp.enableScrolling(false);
// Some additional API features (here commented out):
fp.setCurrentZoom( 100 );
// sendCurrentZoom();
sender.send( " _flexloader " , " fpLoaded " );
}
// Hide the navigation controller until after the document is loaded:
// _root.control_mc._visible = false;
// Create movie clip to hold the document:
var paper = this .createEmptyMovieClip( " paper " , 100 );
// Create movie clip to exchange the depth with the navigation controller clip:
// var ctrlHolder_mc = this.createEmptyMovieClip("ctrlHolder",200);
// Position the document clip on the stage:
paper._x = 0 ;
paper._y = 0 ;
// Load the FlashPaper document:
loadFlashPaper(url, paper, this );
import flash.display.Stage;
Stage.align = " LT " ;
// Stage.scaleMode = "showAll";
var url = " template.swf " ;
var fp;
// localConnection通讯接口
var caller:LocalConnection = new LocalConnection();
var sender:LocalConnection = new LocalConnection();
caller.connect( " _flashpaperloader " );
caller.allowDomain( " * " );
sender.allowDomain( " * " );
Security.allowDomain( " * " );
// 设置页面
// caller.setPage = function(n:Number)
// {
// fp.setCurrentPage(n);
// }
// 设置大小
caller.setPaperSize = function(w:Number,h:Number)
{
trace( " fpLoader width= " + w + " height = " + h) ;
fp.setSize(w,h);
}
// 设置缩放
// caller.setCurrentZoom = function(zoom:Object)
// {
// fp.setCurrentZoom(zoom);
// sendCurrentZoom();
// }
// 设置下一页
// caller.nextPage = function()
// {
// var p:Number = fp.getCurrentPage();
// if(p + 1 <= fp.getNumberOfPages())
// fp.setCurrentPage(p + 1);
// }
// 设置上一页
// caller.prePage = function()
// {
// var p:Number = fp.getCurrentPage();
// if(p - 1 > 0)
// fp.setCurrentPage(p - 1);
// }
// 卸载
caller.unload = function()
{
caller.close();
caller = null ;
sender = null ;
fp.destroy();
fp = null ;
unloadAndStop();
paper.unloadMovie();
paper = null ;
}
// function: loadFlashPaper
// ------------------------
// Load FlashPaper document, size it,
// Parameters:
// path_s: Path of SWF to load
// dest_mc: Movie clip to hold the imported SWF
// width_i: New size of the dest MC
// height_i: New size of the dest MC
// loaded_o: (optional) Object to be notified that loading is complete
function loadFlashPaper(path_s, dest_mc, loaded_o) {
var intervalID = 0 ;
var loadFunc = function(){
trace( " 加载开始. " );
dest_mc._visible = false ;
fp = dest_mc.getIFlashPaper();
if ( ! fp) {
return ;
} else if ( ! fp.setSize( 0 , 0 )){
trace( " 没有设置窗口大小 " );
return ;
} else {
trace( " flashPaper加载成功了 " );
clearInterval(intervalID);
// var pages_i = fp.getNumberOfPages();
// paper.toolbar_mc.brandClip_mc.swapDepths(1000);
// paper.toolbar_mc.brandClip_mc.removeMovieClip();
// ctrlHolder_mc.swapDepths(_root.control_mc);
dest_mc._visible = true ; // Now show the document
// _root.control_mc._visible = true; // Now show the controller
loaded_o.onLoaded(fp);
}
}
intervalID = setInterval(loadFunc, 100 );
dest_mc.loadMovie(path_s);
}
// function: onLoaded()
// ------------------------
// Called once loading is complete
// Parameters:
// fp: FlashPaper interface (returned by getIFlashPaper())
function onLoaded() {
// We can now call the FlashPaper API functions.
// Remove the standard user interface features:
// fp.showUIElement("PrevNext", false);
fp.showUIElement( " Print " , false );
// fp.showUIElement("Find", false);
// fp.showUIElement("Tool", false);
// fp.showUIElement("Pop", false);
// fp.showUIElement("Zoom", false);
// fp.showUIElement("Page", false);
// fp.showUIElement("Overflow", false);
// fp.enableScrolling(false);
// Some additional API features (here commented out):
fp.setCurrentZoom( 100 );
// sendCurrentZoom();
sender.send( " _flexloader " , " fpLoaded " );
}
// Hide the navigation controller until after the document is loaded:
// _root.control_mc._visible = false;
// Create movie clip to hold the document:
var paper = this .createEmptyMovieClip( " paper " , 100 );
// Create movie clip to exchange the depth with the navigation controller clip:
// var ctrlHolder_mc = this.createEmptyMovieClip("ctrlHolder",200);
// Position the document clip on the stage:
paper._x = 0 ;
paper._y = 0 ;
// Load the FlashPaper document:
loadFlashPaper(url, paper, this );