Created
January 5, 2009 08:51
-
-
Save shimarin/43330 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mx:Script> | |
<![CDATA[ | |
// 使うクラスをimportする。どんなクラスがあるのかは Flex Builderのヘルプ→ヘルプ目次で | |
// ヘルプを開き、Adobe Flex3ヘルプ→Adobe Flex3 リファレンスガイドあたりをたぐって調べる。 | |
// 名前が分かっている場合は検索する。 | |
import mx.controls.Alert; | |
// 変数定義などをここに書く | |
[Bindable] private var baseURI:String = "https://{server.name}/"; | |
]]> | |
</mx:Script> | |
<mx:creationComplete> | |
<![CDATA[ | |
// アプリケーション起動時の処理をここに書く | |
if (Application.application.url.indexOf("file://") == 0) { | |
// URLを調べて、file:// ならサーバに載せずに Flex Builderで動かしてるとみなして | |
// 通信先を書き換える | |
baseURI = "http://localhost:8080/"; | |
} | |
]]> | |
</mx:creationComplete> | |
<!-- 特定のラジオボタンが選択されていたら入力が可能になるテキスト入力ボックスの例 --> | |
<mx:TextInputとか enabled="{radioButton.selected}"/> | |
<mx:Buttonとか> | |
<!-- ボタン定義の内側 --> | |
<mx:click> | |
<![CDATA[ | |
// ボタンがクリックされたときの処理をここに書く | |
svc.joinRequest("引数","引数","引数"...); | |
// ↑この書式だと返り値がもらえない | |
// 返り値をもらうには、下記のようにサーバ上で関数が実行完了したときに呼び出される関数を登録する | |
svc.joinRequest("引数","引数","引数"...) | |
.addResponder(new AsyncResponder(result, fault)); // 関数 result, fault | |
function result(event:Object, token:Object = null):void | |
{ | |
// resultにサーバ側関数の実行結果が入る | |
var result:Object = (event as ResultEvent).result; | |
// resultを使って完了処理をする(ユーザに完了メッセージを表示するとか) | |
// もし返値の型がわかっている(例えばBoolean)なら、下記のように直接 Boolean型で得る | |
var boolResult:Boolean = (event as ResultEvent).result as Boolean; | |
} | |
function fault(event:Object, token:Object= null):void | |
{ | |
// faultに実行失敗の理由などが文字列で入る(通信断、サーバ落ちてるなど) | |
var fault:String = (event as FaultEvent).fault.faultString; | |
// faultの内容をユーザに表示する | |
Alert.show("エラー:" + fault); | |
} | |
]]> | |
</mx:click> | |
</mx:Buttonとか> | |
<!-- mx:RemoteObject要素で通信先のサーバを定義する --> | |
<mx:RemoteObject id="svc" destination="memberService" | |
endpoint="{baseURI}stbbsnet/jrubyamf/amf"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- バリデータ(入力検証器)のリスト --> | |
<mx:Array id="validators"> | |
<!-- 1から100までの数値であることを検証する --> | |
<mx:NumberValidator source="{amount}" property="text" minValue="1" maxValue="100"/> | |
<!-- 任意の文字列が最低1文字入力されていることを検証する --> | |
<mx:StringValidator source="{fullname}" property="text" minLength="1" triggerEvent=""/> | |
<!-- 他にもEmailValidatorとか PhoneNumberValidatorとかある --> | |
</mx:Array> | |
<mx:なんかのイベント処理> | |
<![CDATA[ | |
// 検証器で全ての入力が正しいかどうかをチェック | |
if (Validator.validateAll(validators).length != 0) { | |
// 正しくない奴がひとつでもあれば、エラーメッセージを出してreturnしてしまう | |
Alert.show("入力に誤りがあります。赤枠の表示された項目を確認して下さい", "確認"); | |
return; | |
} | |
// ... 入力値検証に問題がなかった場合の処理をここから先に記述 | |
]]> | |
</mx:なんかのイベント処理> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" | |
layout="vertical" currentState="firstState"> | |
<mx:states> | |
<mx:State name="firstState"> | |
<mx:AddChild position="lastChild"> | |
<mx:Label text="最初のステート" fontSize="24"/> | |
</mx:AddChild> | |
<mx:AddChild position="lastChild"> | |
<mx:Button label="もう一つのステートに切り替える"> | |
<mx:click> | |
<![CDATA[ | |
currentState = "anotherState"; | |
]]> | |
</mx:click> | |
</mx:Button> | |
</mx:AddChild> | |
</mx:State> | |
<mx:State name="anotherState"> | |
<mx:AddChild position="lastChild"> | |
<mx:Label text="もう一つのステート" fontSize="24"/> | |
</mx:AddChild> | |
<mx:AddChild position="lastChild"> | |
<mx:Button label="最初のステートに戻る"> | |
<mx:click> | |
<![CDATA[ | |
currentState = "firstState"; | |
]]> | |
</mx:click> | |
</mx:Button> | |
</mx:AddChild> | |
</mx:State> | |
</mx:states> | |
<mx:Label text="ステート機能のサンプルです。"/> | |
</mx:Application> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment