flash mx 2004 自定义滚动条代码

本文介绍了一个使用ActionScript实现的Flash滚动条组件。该组件通过定义滚动区域的长度和位置来控制文本滚动,并且能够根据文本的最大滚动距离调整滚动条的位置。文章详细描述了滚动条的初始化设置、绘制边界、开始及停止滚动等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


//定义scroll的总长
var totalDist = Math.floor((myText._height-myText._y)-down_btn._height-scrollBar_mc._height);
var target = "text.txt";
var target1="aa.htm";

//设置按钮和滑块的位置
up_btn._x = myText._x+myText._width;
up_btn._y = myText._y+up_btn._height;
down_btn._x = myText._x+myText._width;
down_btn._y = myText._y+myText._height-down_btn._height;
scrollBar_mc._x = myText._x+myText._width;
scrollBar_mc._y = myText._y+up_btn._height;

//绘制边
drawBorder = function (depth, pos_x, pos_y, par1, par2) {
 border = createEmptyMovieClip("border", depth);
 with (border) {
  lineStyle(1, 0xcccccc, 100);
  moveTo(pos_x, pos_y);
  lineTo(pos_x+par1, pos_y);
  lineTo(pos_x+par1, pos_y+par2);
  
  //lineTo(pos_x, pos_y+par2);
  //lineTo(pos_x, pos_y);
  trace(pos_x);
  trace(pos_y);
 }
};
//创建scroll函数
startScroll = function (texto, direction) {
 this.createEmptyMovieClip("loop", this.getNextHighestDepth());
 loop.onEnterFrame = function() {
  myText.scroll += direction;
  var percent = Math.floor((myText.scroll/myText.maxscroll)*100);
  var position = Math.floor((totalDist/100)*percent);
  scrollBar_mc.txte.percenty=percent+"%";
  
  if (myText.scroll == 1) {
   scrollBar_mc._y = myText._y+up_btn._height;
   scrollBar_mc.txte._visible=false;
   
  } else {
   scrollBar_mc.txte._visible=true;
   scrollBar_mc._y = position;
  }
 };
};
//停止SCROLL
stopScroll = function () {
 delete loop.onEnterFrame;
};
down_btn.onPress = function() {
 startScroll(texto, 1);
};
up_btn.onPress = function() {
 startScroll(texto, -1);
};
down_btn.onRelease = down_btn.onReleaseOutside=function () {
 stopScroll();
};
up_btn.onRelease = up_btn.onReleaseOutside=function () {
 stopScroll();
};
var myLoadText = new LoadVars();
myLoadText.onLoad = function(success) {
 if (success) {
  myText.html = true;
  myText.htmlText=myLoadText.texto;
  drawBorder(100, myText._x, myText._y, myText._width, myText._height);
  scrollBar_mc.txte._visible=false;
  if (myText.maxscroll == 1) {
   up_btn._visible = false;
   down_btn._visible = false;
   scrollBar_mc._visible = false;
   } else {
   drawBorder(200, myText._x+myText._width, myText._y, 15, myText._height);
  }
 } else {
  myText.html = "不能载入文本";
 }
};
myLoadText.load(target);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值