as3滚动条控制元件移动 带缓冲效果

来源:互联网 发布:有没有免费的域名 编辑:程序博客网 时间:2024/06/05 05:23
由于带滚动条的动态文本框无法竖着显示文字,于是通过把竖着显示得静态文本框转换成元件,遮罩层盖在内容层上,实现拉滚动条,元件左右移动,在遮罩层的帮助下,实现竖排文字左右移动的效果,然后通过代码加入移动的缓冲效果,注意最后一帧的代码是跳转到前一帧,通过循环才能实现移动缓冲的效果,而不是在同一帧内实现。。。


<code>drag.addEventListener(MouseEvent.MOUSE_DOWN,dragMouseDown);
stage.addEventListener(MouseEvent.MOUSE_WHEEL,scrolldrag);
stage.addEventListener(Event.ENTER_FRAME,scrollText);
drag.buttonMode = true;</code>


function dragMouseDown(evt:MouseEvent):void
{
drag.startDrag(false,new Rectangle(dx,dy,0,bar.height - drag.height));
stage.addEventListener(MouseEvent.MOUSE_UP,dragMouseUp);
addEventListener(Event.ENTER_FRAME,scrollText);
}
function dragMouseUp(evt:MouseEvent):void
{
drag.stopDrag();
//stage.removeEventListener(MouseEvent.MOUSE_UP,dragMouseUp);
//removeEventListener(Event.ENTER_FRAME,scrollText);
}


function scrollText(evt:Event):void
{


var percentScrolled:Number = (drag.y - dy) / 239;


var moveto:Number = infox + percentScrolled * 423;
if(moveto &gt; info_text.x)
{
info_text.x += (moveto - info_text.x)*0.1;
if(Math.abs(moveto - info_text.x) {
info_text.x = moveto;
}
}
if(moveto &lt; info_text.x)
{
info_text.x -= (info_text.x - moveto)*0.1;
if(Math.abs(info_text.x - moveto) {
info_text.x = moveto;
}
}


}


function scrolldrag(evt:MouseEvent):void
{


var percentScrolled:Number = 0;
var moveto:Number = 0;
if(evt.delta &lt; 0 &amp;&amp; drag.y &lt; dy + 239 ) {
drag.y = drag.y + 10;
percentScrolled = (drag.y - dy) / 239;
moveto = infox + percentScrolled * 423;
info_text.x += (moveto - info_text.x)*0.1;
if(Math.abs(moveto - info_text.x) {
info_text.x = moveto;
}
}


if(evt.delta &gt; 0 &amp;&amp; drag.y &gt; dy ) {
drag.y = drag.y - 10;
percentScrolled = (drag.y - dy) / 239;
moveto = infox + percentScrolled * 423;
info_text.x -= (info_text.x - moveto)*0.1;
if(Math.abs(info_text.x - moveto) {
info_text.x = moveto;
}


}


}



点此立即下载实例源码
0 0
原创粉丝点击