2012-01-04 17 views
11

का उपयोग कर एक टेक्स्ट फ़ील्ड में दो रंग क्या एक्शनस्क्रिप्ट 3.0 का उपयोग करके एक टेक्स्ट फ़ील्ड में दो टेक्स्ट रंग होना संभव है?एक्शनस्क्रिप्ट 3

पूर्व: मैं पहली स्ट्रिंग ब्लैक और दूसरी स्ट्रिंग लाल की तरह कैसे बना सकता हूं?

public function logs(txt) 
    { 
     if (txt == '') 
     { 
      textLog.text = "Let's Open up our treasure boxes !!!"; 
     } 
     else 
     { 
      textLog.text = '' + txt + ''; 
     } 
     textLog.x = 38.60; 
     textLog.y = 60.45; 
     textLog.width = 354.50; 
     textLog.height = 31.35; 
     textLog.selectable = false; 
     textLog.border = false; 
     var format:TextFormat = new TextFormat(); 
     var myFont:Font = new Font1(); 
     format.color = 0x000000; 
     format.font = myFont.fontName; 
     format.size = 18; 
     format.align = TextFormatAlign.CENTER; 
     format.bold = false; 
     textLog.embedFonts = true; 
     textLog.setTextFormat(format); 
     this.addChild(textLog); 
    } 

उत्तर

16

setTextFormat में आप सूचकांक और अंत प्रारंभ अनुक्रमणिका निर्दिष्ट कर सकते हैं:

यहाँ मेरी कोड जब एक ही रंग का उपयोग कर रहा है। आप textLog.htmlText का उपयोग कर HTML के रूप में टेक्स्ट भी प्रस्तुत कर सकते हैं।

पहले उस पाठ

var t:TextField = new TextField(); 
t.text = "BLUEGREEN"; 
addChild(t); 

सेट तो विधि 1

var format1:TextFormat = t.getTextFormat(0, 4); 
format1.color = 0x0000ff; 
t.setTextFormat(format1, 0, 4); 


var format2:TextFormat = t.getTextFormat(5, t.length); 
format2.color = 0x00ff00; 
t.setTextFormat(format2, 5, t.length); 

या विधि 2

t.htmlText = '<font color="#0000ff">BLUE</font><font color="#00ff00">GREEN</font>'; 
+0

मैं उस ब्रो को कैसे कर सकता हूं? क्या आप एक उदाहरण देना चाहते हैं? –

+0

मैंने नमूना के साथ जवाब संशोधित किया है। कृपया जांचें। याद रखें कि पाठ को सेट करने के बाद आपको प्रारूप लागू करने की आवश्यकता है। – Diode

+0

यदि आप हार्ड कोड नहीं चाहते हैं तो कृपया इंडेक्स सेट करने के लिए स्ट्रिंग की 'लम्बाई' प्रॉपर्टी का उपयोग करें। – Diode

0

आप ऐसा करना चाहते हैं, तो आप नियंत्रण करने के लिए एक समारोह बनाने की जरूरत है । charAt (यहां STRING का डेफिन इंडेक्स)।

var format2:TextFormat = textbox.defaultTextFormat; 
    format2.color = 0x000000; 
    textbox.defaultTextFormat = format2; 

    if((textbox.text.charAt(3) == "d") && (textbox.text.charAt(4) == "i")){    
     var format1:TextFormat = textbox.defaultTextFormat; 
     format1.color = 0xFF0000; 
     textbox.setTextFormat(format1, 3, 5);} 
    else{ 
     textbox.setTextFormat(textbox.defaultTextFormat);} 
संबंधित मुद्दे