能导入Html的自适应文本框 |
| 作者:佚名 来源:闪吧 作者: ppanyong 更新:2007-1-13 20:46:35 错误报告 我要投稿 |
小弟首次写教程,不周之处望见谅. 可能用过FlashMX2004组件的朋友,都知道有TextArea,虽然很实用,但是本人认为有两个缺点: 1.必须在第一帧导出,这样的话,即使做了Loading,也要preloading 32K的内容之后再显示Loading画面,对网上播放很不利; 2.更改TextArea介面不方便,很多时候只能用默认的Halo主题。
说了那么多,如果你有兴趣,不妨我们现在就开始把。
第一,新建2个按钮(箭头&BAR)和一个BAR的运动轨迹,如图。
第二,将BAR和BAR的运动轨迹 这两个MC合并成一个导航条,命名“scroll“。 然后将箭头、导航拖到场景上。同时,在场景上拖一个动态文本框。命名和位置如图。

第三,在upside按钮上写AS
on (release) { _root.my_text.scroll--;//用来改变文本的当前行 } 在downside按钮上写AS
on (release) { _root.my_text.scroll++;//用来改变文本的当前行 } 在时间轴上写AS
Listener = new Object(); Mouse.addListener(Listener); //给鼠标加入侦听器 Listener.onMouseWheel = function(delta) { my_text.scroll = my_text.scroll-delta/2; //这个最关键,delta 是数表滚轮滚动的距离,滚动1个刻度,delta=1 }; var ss:TextField.StyleSheet = new TextField.StyleSheet();//定义文本框的CSS ss.load("sample.css");//倒入CSS文件 my_text.styleSheet = ss; my_text.multiline = true; //定义文本框为多行 my_text.wordWrap = true; my_text.html = true; //定义文本框为HTML格式,这很重要。 my_text.borderStyle = "none"; my_text.setStyle("marginRight", "20");//定义文本框的变矩。 my_text.textIndent = "50"; story = new XML(); story.ignoreWhite = true; story.load("story.html");//倒入外部的story网页文件。并转换成XML格式。 story.onLoad = function() { my_text.htmlText = story;//将story指向文本框。 if (this.my_text.maxscroll == 1) { this.downside._visible = false; this.upside._visible = false; this.scroll._visible = false; } }; 第四,接下来都是写AS,要有点耐心哦。当初自己写,查AS的字典,眼都花(版主加分啊!!!!)。| 打开导航条的MC。定义Bar这个MC“show_scroll”, 定义长条的轨迹MC“show_scrollbg” 在时间轴上写AS:
show_scroll.onPress = function() { scroll_lock = "no";//定义BAR的锁锭,下同 }; show_scroll.onRelease = function() { scroll_lock = "yes"; show_scroll.stopDrag(); }; show_scroll.useHandCursor = false; show_scrollbg.onPress = function() { scroll_lock = "no"; }; show_scrollbg.onMouseUp = function() { scroll_lock = "yes"; }; total_height = Math.abs(show_scrollbg._height-show_scroll._height);//定义导航条的总高度。 show_scrollbg.useHandCursor = false; _root.onEnterFrame = function() { if (scroll_lock == "no") { show_scroll.startDrag(false, show_scroll._x, 2, show_scroll._x, total_height+2); //拖动BAR scroll_percent = Math.floor((Math.abs(show_scroll._y)/total_height)*100); _parent.my_text.scroll=Math.floor(scroll_percent*(_parent.my_text.maxscroll)/100); //计算拖动的百分比,调整文本框的对应位置。 } else { show_scroll.stopDrag(); if (_parent.my_text.scroll == _parent.my_text.maxscroll) { show_scroll._y = total_height; } else { show_scroll._y=(Math.floor((_parent.my_text.scroll-1)/_parent.my_text.maxscroll*100)*total_height)/100; } } //trace(_parent.my_text.scroll+"v"+_parent.my_text.maxscroll); }; trace(_parent.my_text.scroll);
以上不是很复杂。 最后,在show_scroll的MC上加AS如下
onClipEvent (enterFrame) { if (this._y<0) { this._y++; } if (this._y>262) { this._y--; } }//限制BAR的活动范围,具体数值自己算.
完成了.另外注意,要导入的HTML中的图片要符合Web标准,72bpi,不要用PS基线优化.否则无法显示.效果如下:
 源文件和成品例子,一同奉上,请 点击浏览该文件共同学习
|
|
| 文章录入:skyuu 责任编辑:skyuu |
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |