public static setFocus(newFocus:Object) : Boolean
newFocus パラメータで指定する選択可能 (編集可能) なテキストフィールド、ボタン、またはムービークリップにフォーカスを設定します。ドットまたはスラッシュ表記を使用してパスを指定できます。相対パスと絶対パスのいずれでも使用できます。ActionScript 2.0 の場合は、ドット表記を使用する必要があります。
null を渡すと、現在のフォーカスは削除されます。
newFocus:Object - ボタン、ムービークリップ、テキストフィールドの各インスタンスなどのオブジェクト、またはボタン、ムービークリップ、テキストフィールドの各インスタンスへのパスを指定するストリング。
Boolean - ブール値。フォーカスの試行が成功した場合は true、失敗した場合は false を返します。
次の例では、ブラウザウィンドウで実行中に、テキストフィールドが username_txt テキストフィールドにフォーカスを設定します。必要なテキストフィールド (username_txt と password_txt) のいずれかが未入力である場合、カーソルはデータが未入力のテキストフィールドに自動的にフォーカスを与えます。たとえば、ユーザーが username_txt テキストフィールドに何も入力せずに送信ボタンをクリックすると、エラーメッセージが表示され、カーソルは username_txt テキストフィールドにフォーカスを与えます。
this.createTextField("status_txt", this.getNextHighestDepth(), 100, 70, 100, 22);
this.createTextField("username_txt", this.getNextHighestDepth(), 100, 100, 100, 22);
this.createTextField("password_txt", this.getNextHighestDepth(), 100, 130, 100, 22);
this.createEmptyMovieClip("submit_mc", this.getNextHighestDepth());
submit_mc.createTextField("submit_txt", this.getNextHighestDepth(), 100, 160, 100, 22);
submit_mc.submit_txt.autoSize = "center";
submit_mc.submit_txt.text = "Submit";
submit_mc.submit_txt.border = true;
submit_mc.onRelease = checkForm;
username_txt.border = true;
password_txt.border = true;
username_txt.type = "input";
password_txt.type = "input";
password_txt.password = true;
Selection.setFocus("username_txt");
fscommand("activateTextField");
//
function checkForm():Boolean {
if (username_txt.text.length == 0) {
status_txt.text = "fill in username";
Selection.setFocus("username_txt");
fscommand("activateTextField");
return false;
}
if (password_txt.text.length == 0) {
status_txt.text = "fill in password";
Selection.setFocus("password_txt");
fscommand("activateTextField");
return false;
}
status_txt.text = "success!";
Selection.setFocus(null);
return true;
}
このページに新しいコメントが追加された場合に、電子メールでの通知を希望する。 | コメントレポート