做项目中总要用到文字滚动条,nshen那个滚动条类不能动态的加入文本,所以放弃使用了,自己写了个scrollClass,感觉还不错。导入scrollClass后,只要在Flash第一楨写
import Billow.util.scrollClass;
var inputText = "asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf";
var scrollSpeed = 4;
var backName = "background_mc";
var barName = "bar_mc";
var dragName = "drag_mc";
scrollClass.main(this, backName, barName, dragName, inputText, scrollSpeed);就可以了,
其中this表示_root,backName表示文字背景mc名字(可以随意改动它的长宽位置),barName表示舞台上的滚动条名字,dragName表示舞台上的滚动小球名字,input表示要在里面显示的文字,scrollSpeed表示滚动速度,这些都可以动态的改变。
5dblog不能提供源文件下载,只能提供代码了,希望能帮到大家。
scrollClass代码:
class Billow.util.scrollClass {
private var root:MovieClip;
private var backIDName:String;
private var back_mc:MovieClip;
private var bar_mc:MovieClip;
private var drag_mc:MovieClip;
private var initDragX:Number;
private var initDragY:Number;
private var myTextField:TextField;
private var mask_mc:MovieClip;
private var enterFrame_mc:MovieClip;
private var textField_mc:MovieClip;
private var inputText:String;
private var offsetX:Number = 50;
private var offsetTextY:Number = 50;
private var scrollSpeed:Number = 5;
public function scrollClass(__root:MovieClip, __backName, __barName, __dragName, __inputText:String, __scrollSpeed:Number) {
this.root = __root;
this.scrollSpeed = __scrollSpeed;
this.backIDName = __backName;
this.back_mc = root[__backName];
this.bar_mc = root[__barName];
this.drag_mc = root[__dragName];
this.inputText = __inputText;
initPos();
createTextField();
createMask();
dragHandle();
}
private function dragHandle():Void {
var self = this;
drag_mc.onPress = function() {
self.dragPrsssHandle();
};
drag_mc.onRelease = drag_mc.onReleaseOutside=function () {
self.dragReleaseHandle();
};
}
private function createMask():Void {
mask_mc = root.attachMovie(backIDName, backIDName+"_mask", root.getNextHighestDepth());
mask_mc._x = back_mc._x;
mask_mc._y = back_mc._y;
mask_mc._width = back_mc._width;
mask_mc._height = back_mc._height;
mask_mc._alpha = 0;
textField_mc.setMask(mask_mc);
}
private function createTextField():Void {
textField_mc = root.createEmptyMovieClip("mc", 0);
textField_mc._x = back_mc._x;
textField_mc._y = back_mc._y;
var alpha_mc = textField_mc.attachMovie(backIDName, backIDName, textField_mc.getNextHighestDepth());
alpha_mc._width = back_mc._width;
alpha_mc._height = back_mc._height;
alpha_mc._alpha = 0;
myTextField = textField_mc.createTextField("__text", textField_mc.getNextHighestDepth(), 0, 0, textField_mc._width, textField_mc._height);
myTextField.multiline = true;
myTextField.autoSize = true;
myTextField.wordWrap = true;
//myTextField.textColor = 0x000000;
//myTextField.textHeight = 20;
//myTextField.textWidth = 20;
myTextField.text = inputText;
}
private function initPos():Void {
bar_mc._x = back_mc._x+back_mc._width+50;
bar_mc._y = back_mc._y;
initDragX = bar_mc._x+bar_mc._width/2-drag_mc._width/2;
initDragY = bar_mc._y;
drag_mc._x = initDragX;
drag_mc._y = initDragY;
//trace("initDragY="+initDragY);
}
private function dragPrsssHandle():Void {
//left,up,right,down;
var left = initDragX;
var right = left;
var up = initDragY;
var endDragY = bar_mc._y+bar_mc._height-drag_mc._height;
var down = endDragY;
drag_mc.startDrag(false, left, up, right, down);
var self = this;
enterFrame_mc = root.createEmptyMovieClip("mc", 100);
enterFrame_mc.onEnterFrame = function() {
self.myOnEnterFrame();
};
}
private function myOnEnterFrame():Void {
var endDragY = bar_mc._y+bar_mc._height-drag_mc._height;
var percent = (drag_mc._y-initDragY)/(endDragY-initDragY);
var endY:Number = -(textField_mc._height-offsetTextY)*percent+initDragY;
textField_mc._y += (endY-textField_mc._y)/scrollSpeed;
}
private function dragReleaseHandle():Void {
drag_mc.stopDrag();
//enterFrame_mc.removeMovieClip();
}
public static function main(__root:MovieClip, __backName, __barName, __dragName, __inputText:String, __scrollSpeed:Number) {
new scrollClass(__root, __backName, __barName, __dragName, __inputText, __scrollSpeed);
}
}