首页  |  精品网站  |  原创作品秀   |  艺术设计  |  网络学院  |  信息中心  |  站内搜索  |  求职招聘  |  建站资源  |  服装网站  |  编程开发 |  设计论坛 
  平面设计 画册 VI欣赏 包装 CG-插画   酷站 个人网页 商业网站   Alexa排名 CSS 建站资源 下载专区 JS特效 品牌服装 服装院校   专题欣赏 SEO 图标欣赏
域名注册 虚拟主机 广州网站建设 广州网页设计 IDC赞助 设计资源下载 虚拟主机 域名注册 品牌网站建设 服装品牌网站建设 广告服务 网站推广 娱乐
当前位置:首 页 >> 网络学院 >> Flash ※ FreeHand >> Flash文本框局部文本样式的控制

Flash文本框局部文本样式的控制


中资源
转载请注明出处-中国设计秀-cnwebshow.com

 前几天写了一篇关于《Flash文本框文本样式的控制》后,有个网友提到:如果要设置文本框的局部文本样式该如何写代码?于是我查了一下Flash帮助文档,为大家写了这篇小实例!先看看效果:



Flash AS提供这样一个类:Selection类,通过它的两个方法(getBeginIndex(),getEndIndex()),我们可以获取我们想要的文本的起始位置!使用方法如下:
startIndex = Selection.getBeginIndex();//选择文本的起点
endIndex = Selection.getEndIndex();//选择文本的终点

获得起始位置之后,再使用setTextFormat()方法将样式附加到指定文本。
_root.style_txt.setTextFormat(startIndex, endIndex, Style)

实例详细代码如下:
var Style = new TextFormat();//定义一个文本格式
var startIndex:Number, endIndex:Number;//选择字符的起始位置
style_txt.borderColor = 0xdddddd;//style_txt文本框的边框样式
size_txt.borderColor = 0xdddddd;//size_txt文本框的边框样式
style_txt.htmlText = "<a href=’http://www.blue-sun.cn’>蓝光博客 BlueShine</a>"
+"<br>http://www.blue-sun.cn<br>当你选择部分文本后,修改下列样式,"+
"文本框中被选择的文本样式是不是发生了变化!?";
//
this.onEnterFrame = function() {
    if (Selection.getFocus() == String(style_txt)) {//判断文本框是否获得焦点
        startIndex = Selection.getBeginIndex();//选择文本的起点
        endIndex = Selection.getEndIndex();//选择文本的终点
    }
};
//修改字体大小
size_txt.onChanged = function() {
    Style=style_txt.getTextFormat(startIndex, endIndex);//获得改变之前的文本样式
    Style.size = this.text;//设置属性值
    _root.style_txt.setTextFormat(startIndex, endIndex, Style);//将样式附加到文本
};
//修改文本颜色
var listenOBJ_Com = new Object();
listenOBJ_Com.change = function() {
    Style=style_txt.getTextFormat(startIndex, endIndex);
    Style.color = color_Com.text;
    _root.style_txt.setTextFormat(startIndex, endIndex, Style);
};
color_Com.addEventListener("change", listenOBJ_Com);
//修改字体粗细
b_bt.onRelease = function() {
    Style=style_txt.getTextFormat(startIndex, endIndex);
    Style.bold = !Style.bold;
    _root.style_txt.setTextFormat(startIndex, endIndex, Style);
}
//切换斜体
i_bt.onRelease = function() {
    Style=style_txt.getTextFormat(startIndex, endIndex);
    Style.italic = !Style.italic;
    _root.style_txt.setTextFormat(startIndex, endIndex, Style);
}
//文本左对齐
l_bt.onRelease = function() {
    Style=style_txt.getTextFormat(startIndex, endIndex);
    Style.align ="left";
    _root.style_txt.setTextFormat(startIndex, endIndex, Style);
}
//文本居中
c_bt.onRelease = function() {
    Style=style_txt.getTextFormat(startIndex, endIndex);
    Style.align ="center";
    _root.style_txt.setTextFormat(startIndex, endIndex, Style);
}
//文本右对齐
r_bt.onRelease = function() {
    Style=style_txt.getTextFormat(startIndex, endIndex);
    Style.align ="right";
    _root.style_txt.setTextFormat(startIndex, endIndex, Style);
}
说明:Selection.getFocus() 的作用是得到获得焦点的文本框名称!从而可以据此判断文本框是否获得焦点!

转载请注明出处-中国设计秀-cnwebshow.com



投稿 】【对本文进行评论】 【字体: 】【发布于2007-10-16 11:30】

相关专题:暂无相关专题

上一篇:this的使用   下一篇:Flash加载外部文件的各种方法与技巧
 认证LOGO下载
     
Copyright © 2005-2007 中国设计秀_网页设计教程_优秀网页设计欣赏_平面设计欣赏 All Right Reserved.
做最专业的设计服务网站,秀出自我,秀出精彩!中国设计秀,秀---无处不在!!
QQ:54292427  8208442 MSN:kingvisual#hotmail.com 交流群:9107036 3848215 8850631
粤ICP备05067046号 RSS