flexpaper 的二次开发总结及探讨

1、如创建 ceshi Flex项目  ,把下面代码覆盖项目ceshi.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:Metadata>
		[ResourceBundle("FlexPaper")]
		[Event(name="onDocumentLoaded", type="com.devaldi.events.DocumentLoadedEvent")]
		[Event(name="onLoadingProgress", type="flash.events.ProgressEvent")]
		[Event(name="onDocumentLoadedError", type="flash.events.ErrorEvent")]
		[Event(name="onCurrPageChanged", type="com.devaldi.events.CurrentPageChangedEvent")]
		[Event(name="onDocumentLoading", type="flash.events.Event")]
		[Event(name="onExternalLinkClicked", type="com.devaldi.events.ExternalLinkClickedEvent")]
		[Event(name="onDocumentPrinted", type="com.devaldi.events.DocumentPrintedEvent")]
		[Event(name="onPageLoaded", type="com.devaldi.events.PageLoadedEvent")]
		[Event(name="onPageLoading", type="com.devaldi.events.PageLoadingEvent")]
		[Event(name="onErrorLoadingPage", type="com.devaldi.events.ErrorLoadingPageEvent")]
	</mx:Metadata>
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import com.devaldi.events.CurrentPageChangedEvent;
			import com.devaldi.events.CursorModeChangedEvent;
			import com.devaldi.events.DocumentLoadedEvent;
			import com.devaldi.events.DocumentPrintedEvent;
			import com.devaldi.events.ErrorLoadingPageEvent;
			import com.devaldi.events.ExternalLinkClickedEvent;
			import com.devaldi.events.FitModeChangedEvent;
			import com.devaldi.events.ScaleChangedEvent;
			import com.devaldi.events.ViewModeChangedEvent;
			
			public var _aid:Number = 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;
			
			
			//------------------------
			[Bindable]
			public var _SearchMatchAll:Boolean = true;
			
			[Bindable]
			public var _PrintPaperAsBitmap:Boolean = false;
			
			[Bindable]
			public var _ViewModeToolsVisible:Boolean = true;
			
			[Bindable]
			public var _ZoomToolsVisible:Boolean = true;
			
			[Bindable]
			public var _NavToolsVisible:Boolean = true;
			
			[Bindable]
			public var _CursorToolsVisible:Boolean = true;
			
			[Bindable]
			public var _SearchToolsVisible:Boolean = true;
			//初始化参数
			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"];
				
				_SearchMatchAll=getBoolean(params, "SearchMatchAll", true);
				_PrintPaperAsBitmap=getBoolean(params, "PrintPaperAsBitmap", false);
				_ViewModeToolsVisible=getBoolean(params, "ViewModeToolsVisible", true);
				_ZoomToolsVisible=getBoolean(params, "ZoomToolsVisible", true);
				_NavToolsVisible=getBoolean(params, "NavToolsVisible", true);
				_CursorToolsVisible=getBoolean(params, "CursorToolsVisible", true);
				_SearchToolsVisible=getBoolean(params, "SearchToolsVisible", true);
				//注册事件监听
				this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
				this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
				this.addEventListener(MouseEvent.CLICK,setFocusTo);	
				this.addEventListener("onPageLoaded",pageLoadedEventHandler);	
				
				//开放给外部(javascript)调用
				ExternalInterface.addCallback("hasFocus", hasFocus);
				ExternalInterface.addCallback("setViewerFocus", setViewerFocus); 
				ExternalInterface.addCallback("gotoPage", gotoPage);
				ExternalInterface.addCallback("fitWidth", fitWidth);
				ExternalInterface.addCallback("fitHeight", fitHeight);
				ExternalInterface.addCallback("loadSwf", loadSwf);
				ExternalInterface.addCallback("printPaperRange", printPaperRange);
				ExternalInterface.addCallback("searchText", searchText);
				ExternalInterface.addCallback("prevSearchMatch", prevSearchMatch);
				ExternalInterface.addCallback("nextSearchMatch", nextSearchMatch);
				ExternalInterface.addCallback("switchMode", switchMode);
				ExternalInterface.addCallback("Zoom", Zoom);
				ExternalInterface.addCallback("nextPage", nextPage);
				ExternalInterface.addCallback("getCurrPage", getCurrPage);
				ExternalInterface.addCallback("prevPage", prevPage);
				ExternalInterface.addCallback("printPaper", printPaper);
				ExternalInterface.addCallback("getTotalPages", getTotalPages);
				
			}
			//---------------------------事件------------------------------
			protected function onLoadedError(event:ErrorEvent):void{
				dispatchEvent(event);	
			}
			private function setFocusTo(e:MouseEvent):void{
				stage.stageFocusRect = false;
				stage.focus = e.target as InteractiveObject;
			}
			private function onMouseOver(event:MouseEvent):void{
				this.isFocus = true;
			}
			
			private function onMouseOut(event:MouseEvent):void{
				this.isFocus = false;
			}
			protected function onCurrPageChanged(event:CurrentPageChangedEvent):void{
				dispatchEvent(event);
			}
			protected function documentLoadedErrorHandler(event:Event):void{
				dispatchEvent(event);
			}
			
			protected function onExternalLinkClickedHandler(event:ExternalLinkClickedEvent):void{
				dispatchEvent(event);
			}
			
			protected function onDocumentLoadingProgressHandler(event:ProgressEvent):void{
				dispatchEvent(event);
			}
			
			protected function papersLoadingHandler(event:Event):void{
				dispatchEvent(event);
			}
			
			protected function pageLoadingEventHandler(event:Event):void{
				dispatchEvent(event);
			}
			
			protected function documentPrintedHandler(event:DocumentPrintedEvent):void{
				dispatchEvent(event);
			}
			
			protected function documentLoadedHandler(event:Event):void{
				dispatchEvent(event);
			}	
			
			protected function pageLoadedEventHandler(event:Event):void{
				dispatchEvent(event);
			}
			
			protected function errorLoadingPageEventHandler(event:ErrorLoadingPageEvent):void{
				dispatchEvent(event);
			}
			//----------------------------函数-----------------------------
			public function getTotalPages():Number{
				return FlexPaper.getTotalPages();
			}
			
			public function printPaper(e:Event):void{
				FlexPaper.printPaper(e);
			}
			
			public function printPaperRange(range:String):void{
				FlexPaper.printPaperRange(range);
			}
			public function searchText(text:String):void{
				FlexPaper.searchText(text);				
			}		
			
			public function prevSearchMatch():void{
				FlexPaper.prevSearchMatch();
			}
			
			public function nextSearchMatch(text:String):void{
				FlexPaper.nextSearchMatch(text);
			}
			
			public function switchMode(mode:String=null):void{
				FlexPaper.switchMode(mode);
			}
			public function Zoom(factor:Number):void{
				FlexPaper.Zoom(factor);
			}
			
			public function nextPage():void{
				FlexPaper.nextPage();
			}	
			
			public function prevPage():void{
				return FlexPaper.prevPage();
			}
			public function getCurrPage():Number{
				return FlexPaper.getCurrPage();
			}
			public dynamic function loadSwf(s:String):void{
				FlexPaper.SwfFile = s;
			}
			public function fitHeight():void{
				FlexPaper.fitHeight();
			}	
			public function fitWidth():void{
				FlexPaper.fitWidth();
			}
			public function gotoPage(p:Number):void{
				FlexPaper.gotoPage(p);
			}			
			
			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%" 
						onDocumentLoaded="documentLoadedHandler(event)" 
						onDocumentLoading="papersLoadingHandler(event)"
						onDocumentLoadedError="documentLoadedErrorHandler(event)"					
						onLoadingProgress="onDocumentLoadingProgressHandler(event)"
						onCurrPageChanged="onCurrPageChanged(event)"
						onExternalLinkClicked="onExternalLinkClickedHandler(event)" 
						onDocumentPrinted="documentPrintedHandler(event)"
						onPageLoaded="pageLoadedEventHandler(event)"
						onPageLoading="pageLoadingEventHandler(event)"
						onErrorLoadingPage="errorLoadingPageEventHandler(event)"
						
						Scale="{_Scale}" 
						SwfFile="{_SwfFile}" 
						ZoomTransition="{_ZoomTransition}" 
						ZoomTime="{_ZoomTime}" 
						MinZoomSize="{_MinZoomSize}"
						MaxZoomSize="{_MaxZoomSize}"
						ZoomInterval="{_ZoomInterval}"
						FitPageOnLoad="{_FitPageOnLoad}"
						FitWidthOnLoad="{_FitWidthOnLoad}"
						EncodeURI="{_EncodeURI}"
						FullScreenAsMaxWindow="{_FullScreenAsMaxWindow}"
						ProgressiveLoading="{_ProgressiveLoading}"
						
						SearchMatchAll="{_SearchMatchAll}"
						PrintPaperAsBitmap="{_PrintPaperAsBitmap}"
						ViewModeToolsVisible="{_ViewModeToolsVisible}"
						ZoomToolsVisible="{_ZoomToolsVisible}"
						NavToolsVisible="{_NavToolsVisible}"
						CursorToolsVisible="{_CursorToolsVisible}"
						SearchToolsVisible="{_SearchToolsVisible}"
						locale="{_localeChain}"
						PrintEnabled="{_PrintEnabled}"
						/>
</mx:Application>

 

2、去打印按钮

     我们找到FlexPaperViewer.mxml文件中的下面部分内容:

    

<mx:HBox styleName="toolbarBackground" width="100%" height="26" borderStyle="solid"
verticalScrollPolicy="off" horizontalScrollPolicy="off" paddingTop="2"
paddingLeft="2" horizontalGap="3">
<st:GradientImageButton icon="{MenuIcons.PRINT_ICON}" styleName="toolbttn"
width="20" click="printPaper(event)" toolTip="@Resource(key='Print',
bundle='FlexPaper')" visible="{!ReadOnly}" includeInLayout="{!ReadOnly}" />
<mx:Image source="{MenuIcons.BAR}" width="3" height="21" visible="{!ReadOnly}"
includeInLayout="{!ReadOnly}" />

 把上面代码的st:GradientImageButton部分代码注释掉就可以了

<!--
<st:GradientImageButton icon="{MenuIcons.PRINT_ICON}" styleName="toolbttn"
width="20" click="printPaper(event)" toolTip="@Resource(key='Print',
bundle='FlexPaper')" visible="{!ReadOnly}" includeInLayout="{!ReadOnly}" />
<mx:Image source="{MenuIcons.BAR}" width="3" height="21" visible="{!ReadOnly}"
includeInLayout="{!ReadOnly}" />
-->

 

3、去右键注释FlexPaperViewer_Base.mxml

     

contextMenu.customItems.push(cmi_about);

contextMenu.customItems.push(cmi_print);

 

4、去掉FP 关于我们按钮

找FlexPaperViewer.mxml文件会找到下面三行代码

//bttnInfo.visible = false;
//bttnInfo.visible = (new MenuIcons.SMALL_TRANSPARENT().width > 10);
//bttnInfo.visible = (new MenuIcons.SMALL_TRANSPARENT().width > 10);

 

5、右下角logo,FlexPaperViewer.mxml文件

 除去加载页的 LOGO 图标,

将<fp:FlexPaperViewer_Base ...>的属性最后行加入 creationComplete 处理:

<fp:FlexPaperViewer_Base xmlns:mx="http://www.adobe.com/2006/mxml"
addedToStage="bindStageEvents(event)"
xmlns:fp="com.devaldi.controls.flexpaper.*"
xmlns:ct="com.devaldi.controls.*"
xmlns:st="com.devaldi.skinning.*"
creationComplete="initApp()">

然后加入处理 initApp()函数到<mx:Script>中
//---------------------------二次编程加入
public function initApp():void {
paper1.removeElementAt(2);
}


 最 后 将 源 码 中 的 函 数
papersLoadingHandler(event:Event) 最 后 一 行 加
上:paper1.removeElementAt(2);

 

    protected override function onViewModeChanged(event:ViewModeChangedEvent):void{  
                    txtPage.text = formatPageNumber(viewer.currPage);  
                    super.onViewModeChanged(event);  
                    paper1.removeElementAt(2);  
                }  

 6、视图切换logo

源文件:DupImage.as
找到语句:private var _skinImgl:Bitmap = new MenuIcons.LOGO_SMALL();
替换为: private var _skinImgl:Bitmap = new Bitmap();

 

你可能感兴趣的:(FlexPaper)