flex加载flashpaper

FlashPaper加载与交互实现
本文介绍了如何使用ActionScript加载并显示FlashPaper文档,并通过LocalConnection进行页面控制及大小调整等操作。文中详细展示了如何创建电影剪辑容器、加载文档、设置页面大小以及卸载文档的过程。
//主应用loadFp.mxml 



  

	
		

 

//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);


 

转载于:https://my.oschina.net/Boder/blog/933

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值