FLASH AS3 TextField

Source: Internet
Author: User
1. TextFormat must be set after textField. text Value assignment. Otherwise, the TextFormat style cannot be called. Especially for Chinese. However, in practice, text classes are usually set first, and the values are assigned when the call is made. In this way, the function of TextFormat is lost. Therefore, assign a value to text and then set TextFormat.
2. Assume that textField belongs to the InteractiveObjec class and can interact. The TextEvent listener event can be directly triggered. Otherwise, set XML href = "event: myText" before adding the listener ". My understanding: the Text cannot start the event, and you need to write the name "event: event, and textfield=.html Text to assign values. Set the content assignment form and XML of textfield to add the listener.

 

Program code
// HtmlText method: var tmp1_text: textField = new plain Text = "<font color = '# 0033FF'> blue </font> <font color = '# ff000000'> Red </font> <font color =' # FF6600 '> orange </font> "+" \ n "+" <font color =' #666666 'size = '11'> gray </font> <font color = '# 000000'> black </font> <B> <font color =' # 33cc00' size = '18'> green </font> </B> "+ "\ n "; addChild (tmp1_text); // adjust // TextFormat method: var tmp2_text: TextField = new TextField (); var format1: TextFormat = new TextFormat (); var format2: textFormat = new TextFormat (); tmp2_text.x = 10; tmp2_text.y = 60; tmp2_text.width = 300; tmp2_text.height = 30; tmp2_text.text = "Case Study: The E8 Simulator for Garret... "; format1.size = 15; format2.size = 25; format1.color = 0xff0000; format2.color = 0x00ff00; tmp2_text.setTextFormat (format1, 3, 7); convert (format2, 8, 11); addChild (tmp2_text ); // adjust // htmlText + css method: var tmp3_text: TextField = new TextField (); var style: StyleSheet = new StyleSheet (); tmp3_text.x = 10; tmp3_text.y = 100; tmp3_text.width = 300; tmp3_text.height = 20; style. setStyle (". style1 ", {color: '#000000', fontWeight: 'bold '}); style. setStyle (". style2 ", {color: '# ff0000', fontSize: '15'}); style. setStyle ("a: link", {color: '#006600', textDecoration: 'underline', fontSize: '12'}); style. setStyle ("a: hover", {color: '#003399', fontSize: '12'}); style. setStyle ("a: visited", {color: '#990000', fontSize: '12'}); style. setStyle ("a: active", {color: '#000000', fontSize: '12 '}); tmp3_text.styleSheet = plain Text = "<a href = '#'> hyperlink </a> sdfwewe <span class = 'style1'> sdlfjsiofwekfw </span> <span class = 'style2 '> let's see </span> "; addChild (tmp3_text );

  

Add event listening to Htmltext and replace the following content:

Program code
Var tmp_txt: TextField = new textfield();addchild(tmp_txt(;tmp_txt.html Text = "<a href = 'event: th'> replace </a>"; tmp_txt.addEventListener (MouseEvent. CLICK, txtHandler); function txtHandler (evt: MouseEvent): void {var xtxt: string((tmp_txt.html Text ). split ("replace "). join ("Great! "); Tmp_txt.htmlText = xtxt ;}

  

Listen to mp3 list tracks and apply the style:

Program code
var style:StyleSheet = new StyleSheet();style.setStyle("a:link", { color: '#006600', textDecoration: 'underline',fontSize:'12' });style.setStyle("a:hover",{color:'#003399',fontSize:'12'});style.setStyle("a:visited",{color:'#990000',fontSize:'12'});style.setStyle("a:active ",{color:'#000000',fontSize:'12'});var list:TextField = new TextField();list.autoSize = TextFieldAutoSize.LEFT;list.multiline = true;list.styleSheet = style;list.htmlText = "<a href="event:track1.mp3">Track 1</a><br>";list.htmlText += "<a href="event:track2.mp3">Track 2</a><br>";addEventListener(TextEvent.LINK, linkHandler);addChild(list);function linkHandler(linkEvent:TextEvent):void {        trace(linkEvent.text);}

  

tag, click, and listen:

 

var txt:TextField=new TextField();txt.width=300;txt.;txt.htmlText = '<div id="blogMar">'+' <br>'+'999999999999999999999999999999999999999</div>';addChild(txt);var emb :Loader= txt.getImageReference("icon") as Loader;emb.addEventListener(MouseEvent.CLICK, onTextClick);function onTextClick(e:MouseEvent):void {    trace("click");    //launch URL or whatever}

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.