首页  韩国资源  酷站加油  我的展厅  设计名站  古典元素  推荐下载  设计欣赏  每周专访  招募精英  人才专区  网页教程  平面设计  编程开发  设计竞赛
当前位置:首页 > 网页教程 > Flash教程 > 正文
Google
Flash文本框局部文本样式的控制
来源:蓝光博客 作者:何足道 2007年10月16日 22:58 网友评论:0条 点击:
前几天写了一篇关于《Flash文本框文本样式的控制》后,有个网友提到:如果要设置文本框的局部文本样式该如何写代码?于是我查了一下Flash帮助文档,为大家写了这篇小实例!先看看效果:

/UploadTeach/200710/20071015124010161.swf

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() 的作用是得到获得焦点的文本框名称!从而可以据此判断文本框是否获得焦点!
上一篇:一步步用for循环制作烟花效果   下一篇:燃烧的火:纯代码火焰效果
收藏此页】【打印】【关闭
 相关文章  我要点评
·巧用Point类计算矢量
·动态文本框旋转后消失的解决方法
·关于建设flash全站所需要的最基本的知识点
·Flash打造铅笔png图标
·谨防“Flash蛀虫”病毒 已感染上万台电脑
·纯代码文本框效果
·FLASH解决声音和矢量图的问题
·flash cs3生成网页的flash插入方法研究

免责声明:本站刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。对本文有任何异议,请联络:68design#163.com
转载要求:作者及来源信息必需保留。转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印。



关于我们 | 在线反馈 | 广告报价 | 友情链接 | 联系我们 | 免责声明 | 在线投稿 | 网站地图
Copyright © 2003-2007 68design.net, All Rights Reserve 【找网页设计师,当然上网页设计师联盟】