[akabana-user:134] Re: Air 対応について
Masanobu Shimura
[E-MAIL ADDRESS DELETED]
2007年 7月 22日 (日) 22:00:13 JST
ふなくらさん
下記のような、settting.xmlを、resourceのSubdirectory等において置き、
env.txtの内容で、modeを切り替えたものを取得する Classを
書いてみました。
参考まで。
志村
<?xml version="1.0" encoding="UTF-8"?>
<body >
<run mode="ut">
<gatewayUrl>http://localhost:8080/s2flex2-example/gateway</gatewayUrl>
</run>
<run mode="exe">
<gatewayUrl>http://localhost/s2flex2-example/gateway</gatewayUrl>
</run>
</body>
package com.shimura.rcp.util {
import flash.filesystem.*;
import flash.system.*;
import mx.controls.Alert;
import mx.events.*
public class Setting {
public function Setting (resourceDir:String, fileName:String="setting.xml"
, envFileName:String="env.txt" ) {
_resourceDir=resourceDir;
_fileName=fileName;
_envFileName=envFileName;
var settingFile:File=File.applicationResourceDirectory;
_setting= new XML(ReadFromFile(settingFile, resourceDir, fileName));
}
private var _setting:XML;
private var _resourceDir:String;
private var _fileName:String;
private var _envFileName:String;
private var _mode:String;
public function get mode ():String {
return _mode;
}
private function ReadFromFile(file:File, resourceDir:String,
fname:String):String {
file=file.resolve(resourceDir+"/"+fname);
var fstream:FileStream= new FileStream();
try {
fstream.open(file, FileMode.READ);
var buffer:String=fstream.readUTFBytes(fstream.bytesAvailable);
} catch(error:Error) {
trace(file.nativePath+" not found!!!");
Alert.show(file.nativePath+" not found!!!","",4,null,exit1);
} finally {
fstream.close();
}
//trace(buffer);
return buffer;
}
public function getParameter(param:String):String {
return _setting.run.(@mode == _mode).child(param);
}
private function exit1(event:CloseEvent):void {
Shell.shell.exit(1);
}
}
}
07/07/21 に Masanobu Shimura<[E-MAIL ADDRESS DELETED]> さんは書きました:
> ふなくらさん
>
> ご返事ありがとうございました。
>
> Airはファイルが読めるので、Railsみたいに設定 Fileに、
> 本番とテストの両方のGatewayのURLを設定しておき、
> env.txtか、設定ファイルでモードを切り替えるのも良いかもしれませんね。
>
> 志村
>
akabana-user メーリングリストの案内