actionscript - Why is TextFormat.color not a Number? -
var tf:textformat = mytextfield.gettextformat(); trace(typeof tf.color); // "number" trace(tf.color uint); // true var mycolor:uint = tf.color; // error: 1118: implicit coercion of value static type object possibly unrelated type number.
why?
var mycolor:uint = int(tf.color); // works. why have cast it?
from adobe's api reference:
color:object
so color type of object, second line traced out number type because assigned default or in code, not mean color can number. can assign string type color object well, type of tf.color can number or string:
tf.color = "0x00ff00"; mytextfield.settextformat(tf); // change text color green
if compare following 2 lines:
var mycolor:uint = "0x00ff00"; // 1067: implicit coercion of value of type string unrelated type uint. var mycolor:uint = tf.color; // 1118: implicit coercion of value static type object possibly unrelated type number. // var mycolor:uint = new object(); // line gives same 1118: implicit coercion of value static type object possibly unrelated type uint.
we can see compiler complaining needs explicit instructions perform conversion. point, have enough reason believe compiler designed way is. notice can use constructor of uint or int convert object number. uint , int both derived classes of object.
var mycolor:uint = new uint(tf.color);
i hope shed light.
Comments
Post a Comment