PHPのtrimと同様の関数を作成してみた。
FlexBuilderだと mx.utils.StringUtil クラスにtrimメソッドが用意されているが、Flashには mx.utils.StringUtil が無いので。。。
PHPのtrimでも全角スペースは対象としていないので、今回はあえて全角スペースは対応させていたい。
内容は 先頭、末尾の 半角スペース or 改行 or キャリッジリターン を削除するというものになる。
▼サンプルと関数
var Str1 = "\n\n\r\r" + ' tests ' + "\n"
+ ' yrdydyry ' + "\n\n\r\r";
trace(Str1);
trace(trim(Str1));
function trim (str) {
var regexHead:RegExp = new RegExp('^[ \n\r]*');
var regexFoot:RegExp = new RegExp('[ \n\r]*$');
return str.replace(regexHead, '').replace(regexFoot, '');
}
2009年11月17日火曜日
2009年11月16日月曜日
FlashDevelopを入れてみた
今回入れたのは FlashDevelop Ver3.0.6 です。
・まず本体は下記からダウンロード
http://www.flashdevelop.org/wikidocs/index.php?title=Main_Page
All Downloads ⇒ FlashDevelop 3.0.6 RTM released
・続いて Flex SDK を下記からダウンロード
http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3
Stable Builds ⇒ 「3.4.1.10084 Fri Sep 18, 2009」 ⇒ Adobe Flex SDK
・ダウンロードしてきた lashDevelop-3.0.6-RTM.exe をインストール。
・ダウンロードしてきた flex_sdk_3.4.1.10084.zip をフォルダを作成して解凍
※自分の場合 D:\usr\local\flex_sdk_3.4.1.10084 へ解凍した
・FlashDevelopを起動して Tools ⇒ Program Settings で AS3Context を選択して Flex SDK Location という項目があるので、そこに D:\usr\local\flex_sdk_3.4.1.10084 を設定。
・次に FlashViewer を選択して External Player Path という項目があるので、そこにFlashPlayerのパスを設定する。
※自分の場合は「D:\usr\local\flex_sdk_3.4.1.10084\runtimes\player\win\FlashPlayer.exe」でした。
・まず本体は下記からダウンロード
http://www.flashdevelop.org/wikidocs/index.php?title=Main_Page
All Downloads ⇒ FlashDevelop 3.0.6 RTM released
・続いて Flex SDK を下記からダウンロード
http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3
Stable Builds ⇒ 「3.4.1.10084 Fri Sep 18, 2009」 ⇒ Adobe Flex SDK
・ダウンロードしてきた lashDevelop-3.0.6-RTM.exe をインストール。
・ダウンロードしてきた flex_sdk_3.4.1.10084.zip をフォルダを作成して解凍
※自分の場合 D:\usr\local\flex_sdk_3.4.1.10084 へ解凍した
・FlashDevelopを起動して Tools ⇒ Program Settings で AS3Context を選択して Flex SDK Location という項目があるので、そこに D:\usr\local\flex_sdk_3.4.1.10084 を設定。
・次に FlashViewer を選択して External Player Path という項目があるので、そこにFlashPlayerのパスを設定する。
※自分の場合は「D:\usr\local\flex_sdk_3.4.1.10084\runtimes\player\win\FlashPlayer.exe」でした。
ラベル:
ActionScript3,
Flash
2009年11月12日木曜日
ActionScript3(Flash) ComboBoxのフォント色が変わならい。。。
1フレーム目でComboBoxのdataProviderをセットした後にすぐ文字色を変更しようとすると変わらない。。。何なんこれ。。。
RadioButtonのフォントカラーは変わるのに。。。
ソースはこんな感じ。
this._root.sendDate.dataProvider = new DataProvider(this.getDateList());
var format3 = new TextFormat();
format3.color = 0xCCCCCC;
this._root.sendDate.setStyle("textFormat", format3);
どうやら予め設置されたコンボボックスの色を変更するのがダメみたい。
4フレーム目で実行してみると色が変わるところを見たらオブジェクトが生成される前にTextFormatを指定しようとしているみたいだ。。。
コンポーネントインスペクタのパラーメータにフォントカラーとかがあったらいいのにな。。。
何か方法あるのかな。。。
addChildでrootに追加したものはコンボボックス生成の際に指定するから色がちゃんと変わってる。。。
フォームオブジェクトなんかは基本的にスクリプトから追加するのがセオリーって事なのかな。。。
結局クラス内でフォームオブジェクトを管理するようにした。
var textFormat:TextFormat = new TextFormat();
textFormat.color = 0xCCCCCC;
this._forms.sendDate = new ComboBox();
this._forms.sendDate.name = 'sendDate';
this._forms.sendDate.dataProvider = new DataProvider(this.getDateList());
this._forms.sendDate.dropdown.iconField = null;
this._forms.sendDate.labelField = "label";
this._forms.sendDate.textField.setStyle("textFormat", textFormat);
this._forms.sendDate.dropdown.setRendererStyle("textFormat", textFormat);
this._forms.sendDate.width = 130;
this._forms.sendDate.move(160, 469);
this._root.addChild(this._forms.sendDate);
こんな感じ。 。。
この時に気付いたんだけど、 rootにaddChildで追加してnameでインスタンス名付けてるのに、this._root.sendDateで参照できない。。。undefinedになる。。。
フレームも跨いで現れるし、どういう追加になってるんだろうか。。。
RadioButtonのフォントカラーは変わるのに。。。
ソースはこんな感じ。
this._root.sendDate.dataProvider = new DataProvider(this.getDateList());
var format3 = new TextFormat();
format3.color = 0xCCCCCC;
this._root.sendDate.setStyle("textFormat", format3);
どうやら予め設置されたコンボボックスの色を変更するのがダメみたい。
4フレーム目で実行してみると色が変わるところを見たらオブジェクトが生成される前にTextFormatを指定しようとしているみたいだ。。。
コンポーネントインスペクタのパラーメータにフォントカラーとかがあったらいいのにな。。。
何か方法あるのかな。。。
addChildでrootに追加したものはコンボボックス生成の際に指定するから色がちゃんと変わってる。。。
フォームオブジェクトなんかは基本的にスクリプトから追加するのがセオリーって事なのかな。。。
結局クラス内でフォームオブジェクトを管理するようにした。
var textFormat:TextFormat = new TextFormat();
textFormat.color = 0xCCCCCC;
this._forms.sendDate = new ComboBox();
this._forms.sendDate.name = 'sendDate';
this._forms.sendDate.dataProvider = new DataProvider(this.getDateList());
this._forms.sendDate.dropdown.iconField = null;
this._forms.sendDate.labelField = "label";
this._forms.sendDate.textField.setStyle("textFormat", textFormat);
this._forms.sendDate.dropdown.setRendererStyle("textFormat", textFormat);
this._forms.sendDate.width = 130;
this._forms.sendDate.move(160, 469);
this._root.addChild(this._forms.sendDate);
こんな感じ。 。。
この時に気付いたんだけど、 rootにaddChildで追加してnameでインスタンス名付けてるのに、this._root.sendDateで参照できない。。。undefinedになる。。。
フレームも跨いで現れるし、どういう追加になってるんだろうか。。。
ラベル:
ActionScript3,
Flash
Flash ActionScript3 文字色を変更してみよう
テキストを設置する。
次に設置したテキストをプロパティから「ダイナミックテキスト」へ変更する。
するとインスタンス名が付けれるようになるので、「name01」とでも付けておく。
次に1フレームでも何でもいいからステージ上に下記スクリプトを書く。
var format = name01.getTextFormat();
format.color = 0xFF0000; // とりあえず赤色
name01.setTextFormat(format);
実行すると色が変更されている。
まずname01のTextFormatというオブジェクトを取得して、そのオブジェクトには色々なプロパティがあるので、そいつを編集する。
そして編集したものを今度はセットしてやるというわけ。
その色々なプロパティはここを参考に
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextFormat.html
次に設置したテキストをプロパティから「ダイナミックテキスト」へ変更する。
するとインスタンス名が付けれるようになるので、「name01」とでも付けておく。
次に1フレームでも何でもいいからステージ上に下記スクリプトを書く。
var format = name01.getTextFormat();
format.color = 0xFF0000; // とりあえず赤色
name01.setTextFormat(format);
実行すると色が変更されている。
まずname01のTextFormatというオブジェクトを取得して、そのオブジェクトには色々なプロパティがあるので、そいつを編集する。
そして編集したものを今度はセットしてやるというわけ。
その色々なプロパティはここを参考に
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextFormat.html
ラベル:
ActionScript3,
Flash
2009年11月10日火曜日
ActionScript3 で文字コードSJISを利用する
System.useCodePage = true;
を1フレーム目の一番上にでも書いておく。
以上。。。
を1フレーム目の一番上にでも書いておく。
以上。。。
ラベル:
ActionScript3,
Flash
ActionScript3 URLLoaderDataFormat.VARIABLES の使い方が解らない。。。
var load:URLLoader = new URLLoader();
load.dataFormat = URLLoaderDataFormat.VARIABLES;
load.addEventListener(Event.COMPLETE, this.ExecResAction);
load.load(request);
上記のようなスクリプトを書いていたら下記のようなエラーが出ました。。。
Error: Error #2101: URLVariables.decode() に渡される文字列は、名前/値のペアを含む、URL エンコーディングされたクエリー文字列でなければなりません。
原因は
load.dataFormat = URLLoaderDataFormat.VARIABLES;
どうやら dataFormat は不用意に指定しない方が良いのかもしれません。。。
この行を削除するとうまく動くようになりました。
load.dataFormat = URLLoaderDataFormat.VARIABLES;
load.addEventListener(Event.COMPLETE, this.ExecResAction);
load.load(request);
上記のようなスクリプトを書いていたら下記のようなエラーが出ました。。。
Error: Error #2101: URLVariables.decode() に渡される文字列は、名前/値のペアを含む、URL エンコーディングされたクエリー文字列でなければなりません。
原因は
load.dataFormat = URLLoaderDataFormat.VARIABLES;
どうやら dataFormat は不用意に指定しない方が良いのかもしれません。。。
この行を削除するとうまく動くようになりました。
ラベル:
ActionScript3,
Flash
ActionScript3 日にちの取得はgetDayじゃなくてgetDateだ。。。
最初下記のようにしていたらなんか日が1ケタになってる。。。
なぜ。。。10分位ハマった orz
var date:Date = new Date();
(date.getMonth()+1) + '月' + date.getDay() + '日',
で、調べてみたらgetDayじゃなくてgetDateか。。。
そらそうか。。。
var date:Date = new Date();
(date.getMonth()+1) + '月' + date.getDate() + '日',
なぜ。。。10分位ハマった orz
var date:Date = new Date();
(date.getMonth()+1) + '月' + date.getDay() + '日',
で、調べてみたらgetDayじゃなくてgetDateか。。。
そらそうか。。。
var date:Date = new Date();
(date.getMonth()+1) + '月' + date.getDate() + '日',
ラベル:
ActionScript3,
Flash
登録:
投稿 (Atom)