Flash as TextField format settings

Source: Internet
Author: User
Tags addchild event listener
For two days, I'd like to design a as3+xml news list (http://www.towncool.com/Samples/1/index.html) for the Tang cool. But has been TextField plus monitoring and textformat problems affect, very tangled. But finally the problem is solved. Two basic problems were found through multiple tests:
First, the TextFormat must be set after the Textfield.text assignment. Otherwise, the TextFormat style call does not go in. This is especially true for Chinese. However, in practical applications, the text class is usually set, and then the value is assigned when called. In this way, the role of TextFormat is lost. Therefore, the emphasis is given to text assignment, and then set TextFormat.
Second, the original thought TextField belongs to the Interactiveobjec class, can interact, can directly trigger the TextEvent monitoring event, in fact, it is necessary to set the XML href= "Event:mytext" before listening. I understand: The text can not go to the event, you need to write the name of "events:", in addition, TextField need. HTMLText form assignment. Set the TextField content assignment form and XML, you can add monitoring.


Here are some common control methods for you to learn:
TextField The following example provides three ways to control text display, as to which method to use in the actual application, to see everyone's hobby ~ ~:


Program Code Program code


HTMLText Method:
var tmp1_text:textfield=new TextField ();
tmp1_text.x=10;
tmp1_text.y=10;
tmp1_text.width=200;
tmp1_text.height=60;
Tmp1_text.htmltext = "<font color= ' #0033FF ' > Blue </font><font color= ' #ff0000 ' > Red </font>< Font color= ' #FF6600 ' > Orange </font> ' + ' \ n ' +
"<font color= ' #666666 ' size= ' one ' > ' Gray </font><font color= ' #000000 ' > Black </font><b>< Font color= ' #33CC00 ' size= ' > Green </font></b> ' + ' \ n ';
AddChild (Tmp1_text);


//----------------------------------------------------------------------------------
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 particle Simulator for Garrett ...";


format1.size=15;
format2.size=25;
format1.color=0xff0000;
format2.color=0x00ff00;


Tmp2_text.settextformat (format1,3,7);
Tmp2_text.settextformat (format2,8,11);


AddChild (Tmp2_text);


//----------------------------------------------------------------------------------
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 = style;
tmp3_text.htmltext= "<a href= ' # ' > Hyperlink </a>sdfwewe<span class= ' Style1 ' >sdlfjsiodf fwekfw</span ><span class= ' style2 ' > Look at it </span> ";


AddChild (Tmp3_text);




Add event Listener in HTMLText, replace content:
Program Code Program code


var tmp_txt:textfield=new TextField ();
AddChild (Tmp_txt);
tmp_txt.htmltext= "<a href= ' event:th ' > Replace </a>";
Tmp_txt.addeventlistener (Mouseevent.click,txthandler);
function Txthandler (evt:mouseevent): void {
var xtxt:string= (Tmp_txt.htmltext). Split ("Replace"). Join ("very good!");
Tmp_txt.htmltext=xtxt;
}




MP3 List Tracks listen and apply styles:
Program Code 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);
}




tags mouse click to listen:
Program Code Program code
var txt:textfield=new TextField ();
txt.width=300;
txt.;
Txt.htmltext = ' <div id= ' Blogmar ' > ' +
' <br>" +
' 999999999999999999999999999999999999999</div> ';
A

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.