Skip to main content
August 31, 2010
Answered

I have a strange error here that I do not understand

  • August 31, 2010
  • 3 replies
  • 1134 views

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::SimpleButton@28cfdfa1 to fl.text.TLFTextField.
at editor/setmyFormat().

There is no SimpleButton in this project, so I cannot figure this one out.

this is the line of code causing the problem.

var mainText:TLFTextField = TLFTextField(e.target);

Does anyone have a clue what to check for????

This topic has been closed for replies.
Correct answer

Did you trace e.target? Maybe you want e.currentTarget? I'm not sure if you're trying to get a reference or make a field (I assume reference), but if you're trying to make a field you're missing new.

3 replies

August 31, 2010

When I changed the line of code to read:

var mainText:TLFTextField = TLFTextField(e.currentTarget);

That cured the problem.

Ned Murphy
Legend
August 31, 2010

Based on the error, e.target is a SimpleButton object, and you cannot force that into becoming a TLFTextField.  If there is a textfield inside a SimpleButton object, you are likely up a creek without a paddle in terms of being able to target that textfield.  SimpleButton objects have an extremely limited number of properties and cannot have new ones dynamically assigned like MovieClip symbols can (this assumes CS5 hasn't changed this aspect).  So if you have a button that has a textfield in it and you want to be able to target the textfield, you either need to build a class that extends the SimpleButton to have a textfield property, or use a MovieClip instead.

Correct answer
August 31, 2010

Did you trace e.target? Maybe you want e.currentTarget? I'm not sure if you're trying to get a reference or make a field (I assume reference), but if you're trying to make a field you're missing new.