2015-06-13 32 views

回答

0

你可以指望在字符串中的這個人物確切字符和字符串splited使用長度:

var my_str:String = "This text is black: and this text is white"; 
var my_array:Array = my_str.split(":"); 

var testText:TextField = new TextField(); 
testText.text = my_str; 
addChild(testText); 

var format1:TextFormat = testText.getTextFormat(0, my_array[0].length); 
format1.color = 0x000000; 
testText.setTextFormat(format1, 0, my_array[0].length); 


var format2:TextFormat = testText.getTextFormat(my_array[0].length+1, testText.length); 
format2.color = 0xffffff; 
testText.setTextFormat(format2, my_array[0].length+1, testText.length);