Search code examples
actionscript-3textboxaddchild

addChild(); - Adding a movieclip to a frame in AS3


I am trying to create a function which adds a text box (a blue rectangle) and a textfield on the box. I have a class in the library named textBox, no external classes used. I started actionscript 3 (before even learning many of the programming fundamentals) about a month ago, so I am not experienced with this.

function createTextBox() {
    var textBoxCoordX:int = 305;
    var textBoxCoordY:int = 80;
    var dialogueBox:textBox = new textBox;
    var dialogueText:TextField = new TextField();

    addChild(dialogueBox);

    dialogueBox.x = textBoxCoordX;
    dialogueBox.y = textBoxCoordY;
    dialogueText.x = textBoxCoordX+5;
    dialogueText.y = textBoxCoordY+5;
    dialogueText.text = "Insert Text Here";
}

After playing, I immediately get two errors that link me to "var dialogueBox:textBox = new textBox;" These errors' descriptions say "1046: Type was not found or was not a compile-time constant: textBox." and "1180: Call to a possibly undefined method textBox."


Solution

  • Ensure that the linkage is set. Right click, advanced, tick Export for ActionScript.