Flash CS3 ドキュメンテーション |
|||
| ActionScript 3.0 コンポーネントガイド > UI コンポーネントの使用 > RadioButton の使用 > RadioButton を使用したアプリケーションの作成 | |||
次の手順は、オーサリング時に RadioButton コンポーネントをアプリケーションに追加する方法を示しています。この例では、"はい" または "いいえ" で回答する質問を表示するために RadioButton を使用します。RadioButton で選択されたデータは TextArea に表示されます。
yesRb.label = "Yes";
yesRb.value = "For";
noRb.label = "No";
noRb.value = "Against";
yesRb.move(50, 100);
noRb.move(100, 100);
aTa.move(50, 30);
noRb.addEventListener(MouseEvent.CLICK, clickHandler);
yesRb.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
aTa.text = event.target.value;
}
次の例では、ActionScript を使用して、赤、青、緑の各カラーの 3 つの RadioButton を作成します。また、灰色のボックスを描画します。各 RadioButton の value プロパティでは、ボタンに関連付けられたカラーの 16 進数値を指定します。ユーザーがいずれかの RadioButton をクリックすると、clickHandler() 関数で drawBox() が呼び出され、RadioButton の value プロパティからカラーが渡されて、ボックスが塗られます。
import fl.controls.RadioButton;import fl.controls.RadioButtonGroup;var redRb:RadioButton = new RadioButton();var blueRb:RadioButton = new RadioButton();var greenRb:RadioButton = new RadioButton();var rbGrp:RadioButtonGroup = new RadioButtonGroup("colorGrp");var aBox:MovieClip = new MovieClip();drawBox(aBox, 0xCCCCCC);addChild(redRb);addChild(blueRb);addChild(greenRb);addChild(aBox);redRb.label = "Red";redRb.value = 0xFF0000;blueRb.label = "Blue";blueRb.value = 0x0000FF;greenRb.label = "Green";greenRb.value = 0x00FF00;redRb.group = blueRb.group = greenRb.group = rbGrp;redRb.move(100, 260);blueRb.move(150, 260);greenRb.move(200, 260);rbGrp.addEventListener(MouseEvent.CLICK, clickHandler);function clickHandler(event:MouseEvent):void {drawBox(aBox, event.target.selection.value);}function drawBox(box:MovieClip,color:uint):void {box.graphics.beginFill(color, 1.0);box.graphics.drawRect(125, 150, 100, 100);box.graphics.endFill();}
詳細については、『ActionScript 3.0 コンポーネントリファレンスガイド』の RadioButton クラスを参照してください。
このページに新しいコメントが追加された場合に、電子メールでの通知を希望する。 | コメントレポート
現在のページ: http://livedocs.adobe.com/flash/9.0_jp/main/00000459.html