ステージには6つのテキストフィールドと0〜9の数字のキーパッドがあります。
最終的に、これはAndroidアプリになります。また、テキストフィールドを選択してから、キーパッドボタンを押して、アクティブなテキストフィールドに数字を表示できるようにしたいと思います。
Googleのアクティブフィールドや同様の検索を試みましたが、参照が見つからないようです。
複数のチュートリアルから収集しようとしたものから、暗闇の中でいじくり回していることを覚えておいてください。このコードはおそらく完全なゴミです:
package {
public class main {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import fl.managers.FocusManager;
var focus:FocusManager = new FocusManager(this);
btn_1.addEventListener(MouseEvent.MOUSE_DOWN, inputNumber);
public function inputNumber(m:MouseEvent){
focus.text = 1;
}
public function main() {
// constructor code
}
}
}
現在のエラー:
C:\Users\Otaku\Documents\lottocount\main.as, Line 19, Column 35 1118: Implicit coercion of a value with static type flash.display:InteractiveObject to a possibly unrelated type flash.text:TextField.
C:\Users\Otaku\Documents\lottocount\main.as, Line 14, Column 44 1120: Access of undefined property onMyButtonClick.
C:\Users\Otaku\Documents\lottocount\main.as, Line 14, Column 3 1120: Access of undefined property btn_1.
C:\Users\Otaku\Documents\lottocount\main.as, Line 13, Column 47 1120: Access of undefined property onFocusIn.
C:\Users\Otaku\Documents\lottocount\main.as, Line 13, Column 3 1120: Access of undefined property stage.
focus
オブジェクトにアクセスすると、現在アクティブな(フォーカスされている)オブジェクトへの参照があります。
しかし実際には、入力を許可するTextFieldがあるだけで、それに触れるとキーボードビュー(モバイルのみ)が開きます。
キーボードを自動的に表示しないようにFlashに指示することもできます。独自のキーボードを使用する場合は、フォーカスを使用するか、最後のタッチがあった場所に応じて適切なTextFieldを追跡する独自のシステムを作成できます。
編集:
これは、それがどのように行われるかについての単純な例です。
この例では、tf1とtf2の2つのTextFieldがあります。また、具体的なタイプのオブジェクトに最後のフォーカスを保存する必要がある状況をカバーするために、ボタンを追加しました。ボタンの名前はmyButtonです。
var lastSelectedTextField:TextField; // this will hold our last selected TextField
// make sure stage exists. If you're writing script in a frame, don't mind, if you use OOP approach you can do so by adding an eventListener for the event ADDED_TO_STAGE
stage.addEventListener(FocusEvent.FOCUS_IN, onFocusIn); // onFocusIn will trigger every time a focus is changed.
myButton.addEventListener(MouseEvent.CLICK, onMyButtonClick);
function onFocusIn(e:FocusEvent):void
{
if (stage.focus is TextField)
lastSelectedTextField = stage.focus as TextField;
}
function onMyButtonClick(e:MouseEvent):void
{
trace("Text of the last selected text field is:", lastSelectedTextField.text);
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加