主题:FlexPaper使用小记

记录一下自己在改造FlexPaper的过程,
这是应用网站:http://www.uqbook.cn/,有兴趣可以看看。

1.下载FlexPaper源码;
2.新建Flex Libary工程(提供下载的工程就是Flex库工程),编译的是FlexPaper.swc;
3.新建Flex工程,引用FlexPaper.swc,最后编译成在HTML中使用的flash版本。但作者没有提供FlexPaperViewer.mxml源文件下载,所以,自己在摸索中写出了一个,用于编译flash版本。
Java代码
<?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 _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 _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");  
                _ZoomTransition = getString(params, "ZoomTransition", "easeOut");  
                _ZoomTime = getNumber(params, "ZoomTime", 0.6);  
                _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{  
                //Alert.show("hasFocus");  
                return isFocus;  
            }  
              
            public function setViewerFocus(isFocus:Boolean):void{  
                //Alert.show("setViewerFocus");  
                this.paperViewer.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{  
                //Alert.show("比较:"+name);  
                if(params[name] != null){  
                    return params[name] == "true";  
                }  
                return def;  
            }  
        ]]>  
    </mx:Script>  
    <!--mx:Panel x="165" y="76" width="250" height="200" layout="absolute" title="一个人">  
    <mx:Label x="59" y="37" text="{Scale}" width="88"/>  
    </mx:Panel-->  
      
    <fp:FlexPaperViewer id="paperViewer" 
        width="100%"   
        height="100%"   
        Scale="{_Scale}"   
        SwfFile="{_SwfFile}"   
        ZoomTransition="{_ZoomTransition}"   
        ZoomTime="{_ZoomTime}"   
        ZoomInterval="{_ZoomInterval}" 
        FitPageOnLoad="{_FitPageOnLoad}" 
        FitWidthOnLoad="{_FitWidthOnLoad}" 
        PrintEnabled="{_PrintEnabled}" 
        FullScreenAsMaxWindow="{_FullScreenAsMaxWindow}" 
        ProgressiveLoading="{_ProgressiveLoading}" />  
</mx:Application> 

你可能感兴趣的:(JavaScript,html,xml,Flex,Flash)