I'm trying to write some AS to take text that a user inputs and then show it in another place
I currently have
import flash.text.TextField;
import flash.events.TextEvent;
stop(); // stop frame from progressing
// This AS sourced and adapted from Adobe ActionScript 3.0 Help Files - Capturing Text Input
// http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d8b.html
// setting variables for Players Name
var playersNameInput:TextField = new TextField();
var playersNameOutput:TextField = new TextField();
// Capture the text input by user
function CaptureUserInput()
{
captureText();
}
function captureText():void
{
playersNameInput.type = TextFieldType.INPUT;
addChild(playersNameInput);
playersNameInput.addEventListener(TextEvent.TEXT_INPUT, textInputCapture);
}
function textInputCapture(event:TextEvent):void
{
var playersNameOutput:String = playersNameInput.text;
}
// register the Enter Key as being pressed so the game can continue
// intentionally blank at this time
// output the text entered by the user
addChild(playersNameOutput);
playersNameOutput.text = playersNameOutput;
When I run it, I'm getting the error code
1067: Implicit coercion of a value of type flash.text:TextField to an unrelated type String.
Can anyone please point me to where I am getting this error from and how I might be able to fix it please?
I already have Dynamic Text Box with the playersNameOutput instance name set up on screen where the inputted text is supposed to display.
Thanks
Go to Publish Settings and turn on Permit debugging, so you get line numbers with errors. That being said you have:
var playersNameOutput:TextField = new TextField();
and then:
playersNameOutput.text = playersNameOutput;
playersNameOutput is a text field... not a string. What you have inside the function does nothing:
function textInputCapture(event:TextEvent):void
{
var playersNameOutput:String = playersNameInput.text;
}
There, playersNameOutput is a local variable - it does not exist outside the function. You need to use different variable names...
North America
Europe, Middle East and Africa
Asia Pacific