您当前的位置: 首页 > 

Jave.Lin

暂无认证

  • 3浏览

    0关注

    704博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

AIR 程序多开

Jave.Lin 发布时间:2012-07-19 10:42:31 ,浏览量:3

原文:http://mad-roy.iteye.com/blog/1225788

AIR应用通常不能像QQ那样能进行多开操作。

 

为了让一个用AIR做的客户端能实现多任务,我找到得办法是运行程序时自动修改配置文件的id标签内的内容。

 

然后再关闭程序时又必须还原成原有的id,因为只有id一致才能实现更新功能。

 

 

主程序:multiapp.mxml



	
		.*/;
			
			protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
			{
				var df:DateFormatter = new DateFormatter();
				df.formatString = "YYYYMMDDHHNNSS";
				var time:String = df.format(new Date());
				var newid:String = "com.roy"+time+"";
				
				var f:File =new File(File.applicationDirectory.resolvePath(
					"META-INF/AIR/application.xml").nativePath);
				var fs:FileStream = new FileStream();  
				fs.open(f,FileMode.READ);      
				var str:String = new String(fs.readUTFBytes(fs.bytesAvailable));
				oldid = str.match(reg).toString();
				str = str.replace(reg,newid);  
				fs.open(f,FileMode.WRITE);
				fs.writeUTFBytes(str); 
				fs.close();
				
				label.text = newid;
				
				//有多个在运行的程序时只关闭一个运行程序就无法再打开新程序
				//必须监听系统最后一个相同程序关闭时,才能初始化id
				//解决办法:
				//记录运行前id,若为初始ID则在关闭该程序时初始化id,否则不操作
				
				if(oldid == "com.roy")
				{
					this.addEventListener(Event.CLOSE,returnId);
				}
			}
			
			protected function returnId(e:Event):void
			{
				var f:File =new File(File.applicationDirectory.resolvePath(
					"META-INF/AIR/application.xml").nativePath);
				var fs:FileStream = new FileStream();  
				fs.open(f,FileMode.READ);      
				var str:String = new String(fs.readUTFBytes(fs.bytesAvailable));
				str = str.replace(reg,oldid);  
				fs.open(f,FileMode.WRITE);
				fs.writeUTFBytes(str); 
				fs.close();
			}
			
		]]>
	
	
	
		
		
	

此程序中配置文件multiapp-app.mxml中,id标签必须为com.roy。
关注
打赏
1664331872
查看更多评论
立即登录/注册

微信扫码登录

0.0422s