[转载][Flash AS3]TextField 文本显示控制示例
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’>蓝色</font><font color=’#ff0000′>红色</font><font color=’#FF6600′>橙色</font>” +”\n” +
“<font color=’#666666′ size=’11′>灰色</font><font color=’#000000′>黑色</font><b><font color=’#33CC00′ size=’18′>绿色</font></b>” +”\n”;
addChild(tmp1_text);
//———————————————————————————-
//TextFormat方法:
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方法:
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=’#'>超链接</a>sdfwewe<span class=’style1′>sdlfjsiodf fwekfw</span><span class=’style2′> 看吧看吧</span>”;
addChild(tmp3_text);
Htmltext中加入事件侦听,替换内容:
addChild(tmp_txt);
tmp_txt.htmlText=”<a href=’event:th’>替换</a>”;
tmp_txt.addEventListener(MouseEvent.CLICK,txtHandler);
function txtHandler(evt:MouseEvent):void {
var xtxt:String=(tmp_txt.htmlText).split(“替换”).join(“非常棒!”);
tmp_txt.htmlText=xtxt;
}
mp3列表曲目侦听,并应用样式:
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);
}
<img>标签鼠标单击侦听:
txt.width=300;
txt.autoSize = ‘center’;
txt.htmlText = ‘<div id=”blogMar”>’+
‘ <img id=”icon” src=”http://img1.qq.com/blog/pics/15256/15256935.jpg” alt=”" /><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
}
/*
txt.addEventListener(MouseEvent.CLICK, onTextClick);
var emb :Loader= txt.getImageReference(“icon”) as Loader;
function onTextClick(e:MouseEvent):void {
var p:Point = new Point(e.localX, e.localY);
var r:Rectangle = emb.getRect(e.target as TextField);
if (r.containsPoint(p)) {
trace(“click”);
//launch URL or whatever
}
}
*/
| anyShare分享到: | |
| |
文章作者:微水网
本文地址:http://vshui.com/archives/224
版权所有 © 转载时必须以链接形式注明作者和原始出处!
