Flex air는 Excel, Word, PDF, Notepad, html 파일과 같은 로컬 파일을 호출합니다.

로컬 프레젠테이션을 하는 과정에서 Flex, AIR가 로컬 파일을 조작해야 한다. 예를 들어 Excel, Word, PDF, Notepad 등 파일은 AIR 2.0 이하에서 주로 Native Process라는 종류를 사용하여 이루어지고 관련 설정 작업을 해야 한다.주의해라, 내가 있는 이곳의 작업 환경은 flex 4.5이다.구체적인 실현은 다음과 같다.
      1.여기서 간단한 Notepad 작업을 예로 들면 다음과 같습니다.
package com.floor.screen.redevelop.app
{
	import flash.desktop.NativeApplication;
	import flash.desktop.NativeProcess;
	import flash.desktop.NativeProcessStartupInfo;
	import flash.display.MovieClip;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.filesystem.File;
	import flash.system.fscommand;
	
	
	public class CallEXE extends MovieClip
	{
		
		private var file:File=new File();
		private var nativeProcessStartupInfo:NativeProcessStartupInfo;
		
		
		public function CallEXE():void{
			
			//  NativeApplication.nativeApplication   NativeApplication  
			
			// 。
			
			/*  autoExit   true( ) , , 。  exiting   exit  。  autoExit   false,  NativeApplication.nativeApplication.exit()  。*/
			
			NativeApplication.nativeApplication.autoExit=true;
			
			// 
			
			file=file.resolvePath("C:/windows/notepad.exe"); //    C:/windows/notepad.exe
			//file=file.resolvePath("C:/Users/LONMID/Desktop/flex.bat");  //assertThat.doc
			//C:/Program Files/UltraEdit/Uedit32.exe
			trace("file :",file.nativePath);
			
			nativeProcessStartupInfo = new NativeProcessStartupInfo();
			
			nativeProcessStartupInfo.executable = file;
			
			
			//fscommand("exec","D:\\M1\\clockv1.bat");
		}
		
		
		
		public  function runTest():void
			
		{
			
			var process:NativeProcess = new NativeProcess();
			
			process.start(nativeProcessStartupInfo);
			
		}
		
	}
}

2. 다음과 같이 WORD, EXCEL, PPT 파일을 조작합니다.
package com.floor.screen.redevelop.app
{
	import flash.display.Sprite;
	import flash.desktop.NativeProcess;
	import flash.desktop.NativeProcessStartupInfo;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.events.IOErrorEvent;
	import flash.events.NativeProcessExitEvent;
	import flash.filesystem.File;
	
	public class NativeProcessDemo extends Sprite
	{
		public var process:NativeProcess;
		public function NativeProcessDemo()
		{
			if(NativeProcess.isSupported)
			{
				setupAndLaunch();
			}
			else
			{
				trace("NativeProcess not supported.");
			}
		}
		
		public function setupAndLaunch():void
		{     
			var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
			var file:File = File.applicationDirectory.resolvePath("C:/Program Files/Microsoft Office/Office12/POWERPNT.EXE");  
			//C:/windows/notepad.exe
			//C:/Program Files/UltraEdit/Uedit32.exe
			//C:\Program Files\Microsoft Office\Office12
			//WINWORD.EXE
			
			nativeProcessStartupInfo.executable = file;
			var processArgs:Vector.<String> = new Vector.<String>();
			processArgs[0] = "C:/Users/LONMID/Desktop/Java 1.ppt"
			//"C:/Users/LONMID/Desktop/lamp.doc"; 
			//C:\\Users\\LONMID\\Desktop\\info.txt
			//C:\Users\LONMID\Desktop
			//D:/new/8FloorScreenRedevelop/src/_readme.txt
			//
			
			nativeProcessStartupInfo.arguments = processArgs;
			process = new NativeProcess();
			process.start(nativeProcessStartupInfo);
			process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
			process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
			process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
			process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
			process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
			process.closeInput();
		}
		public function onOutputData(event:ProgressEvent):void
		{
			trace("Got: ", process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable)); 
		}
		
		public function onErrorData(event:ProgressEvent):void
		{
			trace("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable)); 
		}
		
		public function onExit(event:NativeProcessExitEvent):void
		{
			if(event.exitCode.toString()=="0")
			{
			//	GameModel.getInstance().state=false;
			}
			else if(event.exitCode.toString()=="1")
			{
			//	GameModel.getInstance().state=true;
			}
			this.dispatchEvent(new Event("refresh"));
		}
		public function onIOError(event:IOErrorEvent):void
		{
			trace(event.toString());
		}
	}
}

다음 두 가지 방법 모두 해당 구성 파일에 추가해야 합니다.
   <supportedProfiles>extendedDesktop</supportedProfiles>

마지막에 포장할 때 또...
Signed AIR 패키지가 아닌 Signed native installer. 
3. 다음과 같이 PDF 파일로 작업합니다.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
					   xmlns:s="library://ns.adobe.com/flex/spark" 
					   xmlns:mx="library://ns.adobe.com/flex/mx"
					   initialize="initApp();"
					   showStatusBar="false" 
					   width="1558"  
					   height="740" 
					   >
	<fx:Declarations>
		<!--  ( 、 )  -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import flash.html.HTMLPDFCapability;    //use HTMLPDFCapability
			import flash.html.HTMLLoader;           //use HTMLLoader
			import mx.controls.Alert;               //use Alert
			//initialize
			private function initApp():void
			{
				// 
			 //	this.stage.nativeWindow.startMove();  
			 //this.stage.nativeWindow.alwaysInFront=true;
				
				//check Adobe Reader 8.1 or above capability
				if(HTMLLoader.pdfCapability==HTMLPDFCapability.STATUS_OK)
				{
					var request:URLRequest = new URLRequest("C:/Users/LONMID/Desktop/object-oriented Analysis & Design.pdf");//URLRequest example
					var pdf:HTMLLoader = new HTMLLoader();        //HTML Control
					pdf.height = 800;               //set pdf height
					pdf.width = 1280;                //set pdf width  
					pdf.load(request);              //load pdf
					container.addChild(pdf);        //put pdf in HTML container
				}
				else
					Alert.show("pdf cant display, not Adobe Reader 8.1 and above version");
			}
			private function htmlLoaded(event:Event):void
			{
				
			}  
		]]>
	</fx:Script>
	<mx:HTML id="container" width="1278" height="718"/>
	
</s:WindowedApplication>

4.html 파일 표시
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
					   xmlns:s="library://ns.adobe.com/flex/spark"
					   xmlns:mx="library://ns.adobe.com/flex/mx"
					   width="1280"
					   height="800"	  
				
					   >
	<fx:Declarations>
		<!--  ( 、 )  -->
	</fx:Declarations>
	
	<fx:Script>
		<![CDATA[
			import mx.controls.HTML;
			
			private function onComplete(evt:Event):void {
				
				var document:Object = HTML(evt.currentTarget).htmlLoader.window.document;
				
				var anchors:Object = document.getElementsByTagName("a");
				
				if(anchors != null) { //    :http://hi.baidu.com/taotao5453
					
					for(var i:Number=0; i < anchors.length; i++) {
						
						anchors[i].onmouseup = function():void {
							
							var request:URLRequest = new URLRequest(arguments[0].srcElement);
							
							navigateToURL(request,"_blank");
							
						}
						
					}
				}
			}
					
		]]>
	</fx:Script>
	
	<mx:Panel width="95%" height="98%" layout="absolute" horizontalCenter="0">
		<mx:HTML id="content" width="100%" location="http://www.baidu.com" height="90%"
				          complete="onComplete(event)" top="70" horizontalCenter="0"/>
	</mx:Panel>
	
</s:WindowedApplication>

결론: 필자는 Flex, AIR가 로컬 파일을 조작하는 방법의 총결을 실현하고 현지화 작업에 도움이 필요하다.행운을 빌어요!!!

좋은 웹페이지 즐겨찾기