简体   繁体   中英

AS3 create a textField from a class

I created a document class for an empty stage and would like to create an output class which is imported into the document class.

Inside the output class I would like to create a textField with the methods to set and read the text.

a) empty stage with document class "tommy"

b) document class "tommy"

package  {
  import flash.display.MovieClip;
  import cOutput;

  public class tommy extends MovieClip {
    var _loc_1:cOutput;

    public function tommy() {
      _loc_6 = new cOutput;
      _loc_6.setOutput();//("hurra");       
    }
  }
}

c) output class cOutput (with or without extends Movieclip)

package {
  //import flash.display.MovieClip;
  import fl.controls.TextInput;

  public class cOutput{ //extends MovieClip {
    public var texteField:TextInput;

    public function cOutput() {
      texteField = new TextInput();
      addChild(texteField);
      texteField.text = "Seriously... I need to be displayed."
    }
    public function setOutput(printValue:String){
      texteField.text = printValue;
    }
  }
}

I am receiving "Definition fl.controls:TextInput could not be found".

I read that you need to have this in the library (I dragged a text field as classic text, input text on stage). Seems I am not getting this working.

Any idea what I am doing wrong?

Use the TextField class instead of the TextInput class. The TextField class is the most basic text component: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html

On a side note, your addChild() call won't do anything, as cOutput isn't a display object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM