I have a fast question. I am setting up a variable with a
data type of Number, when I declare the variable it has a default
value.
I am trying to pass data to the variable from a input text
box but I am getting an error when I run the Movie. I have tried
both a input text box and a Dynamic Text box, but they both produce
the same error.
If I remove the data typing from the variable declaration the
Movie runs and it updates the variable data but from all that I
have read this is not a good practice.
I have attached the code, could someone Please help me out. I
do not remember having these types of problems with ActionScript 2.
Thanks for the help.
Code:
var rectangle:Shape;
var thick :Number = 2; // line thickness
var color:Number= 0×000000; // Holds the color value
myButton_btn.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void
{
color = colorField_txt.text; (Line 11)
thick = lineThick_txt.text; (Line 12)
rectangle = new Shape();
rectangle.graphics.lineStyle(thick, color, .5);
rectangle.graphics.drawRect(10, 10, 100, 150);
addChild(rectangle);
}
myButton_btn.buttonMode = true;
ERROR MESSAGE:
1067: Implicit coercion of a value of type String to an
unrelated type Number. (Refers to line 11)
1067: Implicit coercion of a value of type String to an
unrelated type Number. (Refers to line 12)
Thanks again for any help.
Mike|||
the text property of a textfield is of type String, so to
place that String into a variable of type Number, you need to first
convert it to a Number
eg.
thick = Number(lineThick_txt.text);
ActionScript 2 performed this conversion
automatically.|||
Craig.
Thanks for the fast response. I tried it and it works great.
I don’t think I would have ever found that in my manuals.
I really appreciate the help.
Mike
Related posts:
- How to dynamically check what kind of data type it is inside an Arraycollection?
- Assign data grid field to variable?
- Defining the data type of SELECT result data
- Error using SQL data in javascript vars
- Before adding a new TF, remove any TF containing “Type Here”
Related posts brought to you by Yet Another Related Posts Plugin.