选择显示字体大小

简单使用2.0制作滚动条

之前写过一个简单的教程,但有只是滚动条拖动的计算。。之后就有很多初学者一直pm来说textfield中的文字增加了,滚动条不会刷新。那么今天有空就拿回来改了一下,顺便弄成class的简单格式,当然有兴趣的朋友可以自己增加功能之后制作成自己的组件 :)
flash/index4//img_flash_ddvip/2004121812109722.swf" width="550" height="400" pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash type=application/x-shockwave-flash quality=high>

htmlcode>class scrolltext{
private var root:movieclip;
private var barobj:movieclip;
private var textobj:textfield;
private var text:string = "coding by super-tomato";
public var __width:number = 300;
public var __height:number = 200;
public var min:number;
public var max:number;
public var inc:number;

public function scrolltext(mc:movieclip, depth:number) {
var target:object = this;
root = mc.createemptymovieclip("__scrolltext", depth); //根据使用者提供的深度创建一个mc
createobj(); //建立文本和滚动条
barobj.onpress = function() { //滚动条按下进行拖动的动作
this.onenterframe = function() { //此循环是为了得到最新可拖动范围的值
this.startdrag(false, this._x, target.min, this._x, target.max); //设定拖动范围
target.textobj.scroll = int(this._y/target.inc); //根据滚动条的位置设定文字所滚动到的位置
};
}
barobj.onrelease = barobj.onreleaseoutside = function() { //放开滚动条的动作
this.stopdrag(); //停止拖动
delete this.onenterframe; //删除循环事件以减少计算量
}
setinterval(this, "refreshscroll", 100); //每100毫秒刷新一次
}
private function createobj():void {
root.createtextfield("__textarea",0,0,0,this.__width,this.__height); //创建文本
textobj = root.__textarea;
textobj.border = true; //显示文本的边框
textobj.text = this.text; //设定文本的文字
barobj = root.createemptymovieclip("__scrollbar",1); //建立滚动条
barobj._x = this.__width + 5; //设定滚动条的位置
with(barobj) { //画出滚动条
beginfill(0xff9900);
l.neto(20, 0);
l.neto(20, this.__height);
l.neto(0, this.__height);
l.neto(0,0);
endfill();
}
}
private function refreshscroll():void {
textobj.text = this.text; //每100毫秒设定一次文本的文字
var newheight:number = textobj._height / textobj.textheight; //计算文本的高度和文字高度的比例
if(newheight < 1) { //如果文字的高度大于文本所能够显示的高度
barobj._height = newheight * textobj._height; //更新滚动条的长度
} else { //文本内容少于显示范围
barobj._height = this.__height; //滚动条的长度就等于原来所设定的高度
}
this.min = textobj._y; //文本的顶点位置
this.max = this.min+(textobj._height - barobj._height); //滚动条所能拖动的最低范围
this.inc = int(math.abs(this.max-this.min)/textobj.maxscroll); //根据文本最大的滚动值计算滚动条能够拖动的距离
}
}


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons