отображение текста ввода в другое текстовое поле flash as3

#actionscript-3

#actionscript-3

Вопрос:

Пожалуйста, помогите мне…

Я пытаюсь отобразить вводимый текст в другое текстовое поле во время выполнения. Я хочу показать myOutputBox with в видеоролике. Код приведен ниже:

Actionscript 3

 package
  

{

 import flash.display.Sprite;

import flash.display.Stage;

import flash.text.*;

import flash.events.*;



public class CaptureUserInput extends Sprite

{

    private var myTextBox:TextField = new TextField();

    private var myOutputBox:TextField = new TextField();

    private var myText:String = "Type your text here.";



    public function CaptureUserInput()

    {

        captureText();

    }



    public function captureText():void

    {

        myTextBox.type = TextFieldType.INPUT;

        myTextBox.background = true;

        addChild(myTextBox);

        myTextBox.text = myText;

        myTextBox.addEventListener(TextEvent.TEXT_INPUT, textInputCapture);

    }



    public function textInputCapture(event:TextEvent):void

    {

        var str:String = myTextBox.text;

        createOutputBox(str);

    }



    public function createOutputBox(str:String):void

    {

        myOutputBox.background = true;

        myOutputBox.x = 200;

        addChild(myOutputBox);

        myOutputBox.text = str;

    }



}
  

}

Комментарии:

1. Является CaptureUserInput ли ваш класс документа? Также откуда взялся myTextBox and myOutputBox ?

Ответ №1:

Немного исправил ваш код и добавил кое-что, надеюсь, это вам поможет:

   public class CaptureUserInput extends Sprite
  {

    private var initialText:String = "Type your text here.";

    public var myTextBox:TextField = new TextField();

    public var myOutputBox:TextField = new TextField();

    public function CaptureUserInput()
    {
        captureText(); 
    }

    public function captureText():void 
    { 
        createInputBox();

        createOutputBox(); 

        myTextBox.text = initialText;

        //reset input field so user can write
        myTextBox.addEventListener(FocusEvent.FOCUS_IN, focusInputIn);

        //capture text
        myTextBox.addEventListener(TextEvent.TEXT_INPUT, textInputCapture);

    }

    //this is almost your code, refactored in a function for clarity
    public function createInputBox():void
    {

        myTextBox.type = TextFieldType.INPUT; 
        myTextBox.background = true; 

        myTextBox.y = 100;
        addChild(myTextBox);
    }

    //just set the text of the output to the contents of the input  
    public function textInputCapture(event:TextEvent):void 
    { 
      myOutputBox.text = myTextBox.text;
    }

    public function createOutputBox():void 
    { 

       myOutputBox.y = 200;
       addChild(myOutputBox); 

    } 

    public function focusInputIn(event:Event):void
    {
      if(myTextBox.text == initialText)
        myTextBox.text ="";
    }

 }
  

Комментарии:

1. Могу ли я поместить текстовое поле out put внутри видеоролика?

2. Да, конечно, просто измените addChild внутри функции createOutputBox() на это: my_movieclip.addChild(muyOutputBox). Просто убедитесь, что my_movieclip существует графически! (или объявить и добавить его с помощью кода). Если вы скажете мне, откуда взялся этот видеоролик, я обновлю код ответа.