《Flexpaper二次开发入门教程》(十四) 增加(修改)自己的mxml应用程序(5.2节) ... .. ...

【转自】http://ajava.org/article-694-1.html

 

5.2 增加(修改)自己的mxml应用程序

做完二次开发准备工作后,大家可以测试:
a) 重新编译后会发现bin-debug有ajavaflexpaper.swf,改名成FlexPaperViewer.swf后使用,刷新页面后发现空白页面,无任何效果。
b)把原有的FlexPaperViewer.mxml右键设置为默认应用程序,重新编译后,会发现空白页面,无任何效果。

 

针对a点,我们先看看ajavaflexpaper.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" minWidth="955" minHeight="600">
 <fx:Declarations>
  <!-- 将非可视元素(例如服务、值对象)放在此处 -->
 </fx:Declarations>
</mx:Application>
里面没有作任何处理,所以显示空白页面是很正常的。


针对b点,我们看看FlexPaperViewer.mxml
<fp:FlexPaperViewer_Base xmlns:mx="http://www.adobe.com/2006/mxml" 
       xmlns:fp="com.devaldi.controls.flexpaper.*" 
       xmlns:ct="com.devaldi.controls.*" 
       xmlns:st="com.devaldi.skinning.*"
       
       addedToStage="bindStageEvents(event)"
       >
我们查找bindStageEvents(e:Event)方法,发现没有获取web页面传递的FlexPaper参数处理方法,FlexPaperViewer_base.mxml里有getUrlParamaters()方法,但发现fullUrl是web页面页面URL地址,不包含FlexPaper参数,具体用法没研究。

 

通过几位朋友的文章介绍,mark修改ajavaflexpaper.mxml如下
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:fp="com.devaldi.controls.flexpaper.*"
    layout="absolute" width="100%" height="100%" 
    applicationComplete="initApp();">
 
 <mx:Script>
  <![CDATA[
   import mx.controls.Alert;
   
   public var _aid = 0;//文档ID
   
   [Bindable]
   public var _Scale:Number = 1;//缩放比例
   
   [Bindable]
   public var _EncodeURI:Boolean = true;
   
   [Bindable]
   public var _SwfFile:String = "";//SWF文件路径
   
   [Bindable]
   public var _ZoomTransition:String = "easeOut";
   
   [Bindable]
   public var _ZoomTime:Number = 0.6;
   
   [Bindable]
   public var _ZoomInterval:Number = 0.1;
   
   [Bindable]
   public var _MinZoomSize:Number = 0.3;
   
   [Bindable]
   public var _MaxZoomSize:Number = 5;
   
   [Bindable]
   public var _FitPageOnLoad:Boolean = false;//加载后适合高度
   
   [Bindable]
   public var _FitWidthOnLoad:Boolean = false;//加载后适合宽度
   
   [Bindable]
   public var _PrintEnabled:Boolean = true;//是否支持打印
   
   [Bindable]
   public var _FullScreenAsMaxWindow:Boolean = false;//是否支付全屏
   
   [Bindable]
   public var _ProgressiveLoading:Boolean = false;//是否延迟加载
   
   [Bindable]
   public var _localeChain:String = "zh_CN";//语言
   
   private var isFocus:Boolean = false;
   
   //初始化参数
   private function initApp():void{
    var params:Object = Application.application.parameters;
    _Scale = getNumber(params, "Scale", 1);
    _SwfFile = getString(params, "SwfFile", "Paper.swf");
    _EncodeURI = getNumber(params, "EncodeURI", 1);
    _ZoomTransition = getString(params, "ZoomTransition", "easeOut");
    _ZoomTime = getNumber(params, "ZoomTime", 0.6);
    _MinZoomSize = getNumber(params, "MinZoomSize", 0.2);
    _MaxZoomSize = getNumber(params, "MaxZoomSize", 5);
    _ZoomInterval = getNumber(params, "ZoomInterval", 0.1);
    _FitPageOnLoad = getBoolean(params, "FitPageOnLoad", false);
    _FitWidthOnLoad = getBoolean(params, "FitWidthOnLoad", false);
    _PrintEnabled = getBoolean(params, "PrintEnabled", true);
    _FullScreenAsMaxWindow = getBoolean(params, "FullScreenAsMaxWindow", false);
    _ProgressiveLoading = getBoolean(params, "ProgressiveLoading", true);
    _localeChain = params["localeChain"];
    //注册事件监听
    this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
    this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
    
    //开放给外部(javascript)调用
    ExternalInterface.addCallback("hasFocus", hasFocus);
    //ExternalInterface.addCallback("focus", focus);
    ExternalInterface.addCallback("setViewerFocus", setViewerFocus); 
   }
   
   private function onMouseOver(event:MouseEvent):void{
    this.isFocus = true;
   }
   
   private function onMouseOut(event:MouseEvent):void{
    this.isFocus = false;
   }
   
   public function hasFocus():Boolean{
    return isFocus;
   }
   
   public function setViewerFocus(isFocus:Boolean):void{
    this.FlexPaper.setViewerFocus();
   }
   
   /**
    * 
    * 获取String类型参数
    * 如果没有,则返回默认值
    **/
   private function getString(params:Object, name:String, def:String):String{
    if(params[name] != null){
     return params[name];
    }
    return def;
   }
   
   private function getNumber(params:Object, name:String, def:Number):Number{
    if(params[name] != null){
     return params[name];
    }
    return def;
   }
   
   private function getBoolean(params:Object, name:String, def:Boolean):Boolean{
    if(params[name] != null){
     return params[name] == "true";
    }
    return def;
   }
  ]]>
 </mx:Script>
 <fp:FlexPaperViewer id="FlexPaper"
      width="100%" 
      height="100%" 
      Scale="{_Scale}" 
      SwfFile="{_SwfFile}" 
      ZoomTransition="{_ZoomTransition}" 
      ZoomTime="{_ZoomTime}" 
      MinZoomSize="{_MinZoomSize}"
      MaxZoomSize="{_MaxZoomSize}"
      ZoomInterval="{_ZoomInterval}"
      FitPageOnLoad="{_FitPageOnLoad}"
      FitWidthOnLoad="{_FitWidthOnLoad}"
      EncodeURI="{_EncodeURI}"
      FullScreenAsMaxWindow="{_FullScreenAsMaxWindow}"
      ProgressiveLoading="{_ProgressiveLoading}" />
</mx:Application>


代码解释:
applicationComplete="initApp();" - 为初始化时调用initApp()方法
initApp() - 为获取web页面传递过来的FlexPaper参数、注册监听器
_xxxx:xxx - 存储web页面传递过来的FlexPaper参数
<fp:FlexPaperViewer id="FlexPaper"….. - 调用FlexPaperViewer.mxml组件xmlns:fp="com.devaldi.controls.flexpaper.*" - 定义fp,指向flexpaper包
xxxx="{_xxxx}" – 设置FlexPaperViewer.mxml组件的参数
注:由于以前完全未接触过FLEX,所以不知道上面的介绍是否符合FLEX的一般说法。
id="FlexPaper",这个id若改动请主要web页面和FlexPaperViewer.mxml对应的处理。

 

上面的代码中对比FlexPaperViewer.mxml,会发现有几个参数是没有用到的,如AutoAdjustPrintSize、PrintPaperAsBitmap等,如果我们想使用,只要:
1)在ajavaflexpaper.mxml添加AutoAdjustPrintSize="{_AutoAdjustPrintSize}",需要定义_PrintPaperAsBitmap。
2)在Web页面中增加AutoAdjustPrintSize=xx参数

 

Mark想应该可以自己定义一些FlexPaper参数,当然这些参数要有后续的处理,需要对源码进行更深入的修改,这些都等各位高手来尝试了。

 

转载请注明:转自http://ajava.org/,请保留文章的完整。

 

你可能感兴趣的:(FlexPaper)