加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex air执行Bat文件,打开关闭文件

发布时间:2020-12-15 04:50:31 所属栏目:百科 来源:网络整理
导读:RunFile.as文件,这个文件负责脚本打开文件,关闭文件操作,里面有调用Bat文件的操作,当然,也是通过NativeProcess类来实现的。 具体代码如下所示: package com.floor.screen.redevelop.app{import flash.desktop.NativeProcess;import flash.desktop.Nati


RunFile.as文件,这个文件负责脚本打开文件,关闭文件操作,里面有调用Bat文件的操作,当然,也是通过NativeProcess类来实现的。
具体代码如下所示:

package com.floor.screen.redevelop.app
{
	import flash.desktop.NativeProcess;
	import flash.desktop.NativeProcessStartupInfo;
	import flash.filesystem.File;
	
	public class RunFile
	{
		//var file:File = new File(); 
		// 文件路径  
		//C:/Users/LONMID/Desktop/一卡通茶话会_一卡通.docx
		public var urlStr:String = "C:/Users/LONMID/Desktop/结网.pdf"; 
		public  var file:File ;
		public function RunFile()
		{
			file = new File(urlStr); 
		}
		
		public function openFile():void{
			file = new File(urlStr); 
			file.openWithDefaultApplication();
		}
		
		/**
		 * 关闭文件
		 **/ 
		public function closeFile():void{
			
//			file = new File("C:/Users/LONMID/Desktop/ccc.exe"); 
//			file.openWithDefaultApplication();
			var cmdFile:File=new File();
			cmdFile = cmdFile.resolvePath("C:/WINDOWS/system32/cmd.exe");
			var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
			nativeProcessStartupInfo.executable = cmdFile;
			
			var processArgs:Vector.<String> = new Vector.<String>();
			processArgs[0] = "/c C:/Users/LONMID/Desktop/ccc.bat "; 
			//上面执行批处理的方式方法
			// C:/Users/LONMID/Desktop/ccc.bat
			
			nativeProcessStartupInfo.arguments=processArgs;
			var process:NativeProcess = new NativeProcess();
			
			process.start(nativeProcessStartupInfo); 


		}
		
	}
}

2.调用这个as的mxml文件,如下所示:
<?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">
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	
	<fx:Script>
		<![CDATA[
			import  com.floor.screen.redevelop.app.RunFile ;
			
			/**
			 * 打开文件测试
			 **/ 
			protected function button1_clickHandler(event:MouseEvent):void
			{
				var f:RunFile = new RunFile();
				f.openFile();
				
			}
			
			/**
			 * 打开下一个文件测试
			 * 要回来半闭生一个文件
			 **/ 
			protected function button2_clickHandler(event:MouseEvent):void
			{
				var f:RunFile = new RunFile();
				f.closeFile();
				
			}
		]]>
	</fx:Script>
	
	<s:Button x="112" y="83"  label="txt" click="button1_clickHandler(event)"/>
	<s:Button x="201" y="83" label="paf" click="button2_clickHandler(event)"/>
</s:WindowedApplication>

注意:也要在配置文件中添加如下代码:
    <supportedProfiles>extendedDesktop</supportedProfiles>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读