Skip navigation
KTK1975
Currently Being Moderated

Error 1067: Can anyone point me to the problem?

Aug 14, 2012 3:33 AM

Tags: #problem #error #flash #cs5.5 #code_snippets #as3.0 #actionscript3

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

 
Replies
  • Currently Being Moderated
    Aug 14, 2012 5:00 AM   in reply to KTK1975

    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...

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points