Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash AS2自动滚动文本字段_Flash_Actionscript - Fatal编程技术网

Flash AS2自动滚动文本字段

Flash AS2自动滚动文本字段,flash,actionscript,Flash,Actionscript,我正在寻找添加一个自我滚动功能到我的滚动字段,当用户在文本或任何控件上鼠标时停止。我对编程还是很陌生,不知道该怎么做 以下是工作滚动条的代码: // ---- Scroll Bar Code ---- // fscommand("allowscale", "false"); bar.useHandCursor = dragger.useHandCursor=false; space = 20; friction = 0.9; speed = 4; y = dragger._y; top

我正在寻找添加一个自我滚动功能到我的滚动字段,当用户在文本或任何控件上鼠标时停止。我对编程还是很陌生,不知道该怎么做

以下是工作滚动条的代码:

// ---- Scroll Bar Code ---- //    
fscommand("allowscale", "false");
bar.useHandCursor = dragger.useHandCursor=false;
space = 20;
friction = 0.9;
speed = 4;
y = dragger._y;
top = main._y;
bottom = (main._y + mask_mc._height) - (main._height - space);

//when scroll button is selected
dragger.onPress = function() {
    drag = true;
    this.startDrag(false, this._x, this._parent.y, this._x, this._parent.y + this._parent.bar._height - this._height);
    dragger.scrollEase();
};

//when scroll button is released
dragger.onMouseUp = function() {
    this.stopDrag();
    drag = false;
};

//when any of the scroll bar is pressed
bar.onPress = function() {
    drag = true;
    if (this._parent._ymouse > ((this._y + this._height) - this._parent.dragger._height)) {
        this._parent.dragger._y = this._parent._ymouse;
        this._parent.dragger._y = (this._y + this._height) - this._parent.dragger._height;
    } else {
        this._parent.dragger._y = this._parent._ymouse;
    }
    dragger.scrollEase();
};

//when scroll bar is released
bar.onMouseUp = function() {
    drag = false;
};

//when scroll button is dragged
moveDragger = function (d) {
    if ((dragger._y >= ((y + bar._height) - dragger._height) && d == 1) || (dragger._y <= y && d == -1)) {
        clearInterval(myInterval);
    } else {
        dragger._y += d;
        dragger.scrollEase();
        updateAfterEvent();
    }
};

//when up button is pressed
up_btn.onPress = function() {
    myInterval = setInterval(moveDragger, 18, -1);
};

//when down button is pressed
down_btn.onPress = function() {
    myInterval = setInterval(moveDragger, 18, 1);
};

//when up button is released
up_btn.onMouseUp = down_btn.onMouseUp = function () {
    clearInterval(myInterval);
};

MovieClip.prototype.scrollEase = function() {
    this.onEnterFrame = function() {
        if (Math.abs(dy) == 0 && drag == false) {
            delete this.onEnterFrame;
        }
        r = (this._y - y ) / (bar._height - this._height);
        dy = Math.round((((top - (top-bottom) * r) - main._y) / speed) * friction);
        main._y += dy;
    };
};


//End Scroll Bar Code
dragger.onRollOver = function() {
    dragger.useHandCursor = false;
}

// Start AutoScroll
var my_timedProcess:Number = setTimeout(autoScroll, 2000, "two second delay");

// Define AutoScroll
function autoScroll () {
    scrollInterval = setInterval(moveDragger, 150, 1);
}

//Stop AutoScroll on Rollover
mask_mc.onRollOver = down_btn.onRollOver = up_btn.onRollOver = dragger.onRollOver = bar.onRollOver = function () {
    clearInterval(scrollInterval);
};

//Start AutoScroll on RollOut
mask_mc.onRollOut = down_btn.onRollOut = up_btn.onRollOut = function () {
    scrollInterval = setInterval(moveDragger, 150, 1);
};

首先,我想说你应该考虑使用ActionScript 3而不是ActionScript 2 < /P> 现在谈谈你的问题;那个代码对于自动滚动来说太大了。如果我正确理解您的需求,请尝试我的代码,您应该会有一个良好的开端

将段落/文本区域转换为movieclip,并为其指定textblock_mc的实例名称 创建另一个movieclip并为其指定一个实例名mask_mc 创建一个按钮,并给它一个up_button的实例名 在时间表上:

mask_mc._height = 100;  //---- edit to suit your need
var speed:Number = 1;  //---- change scroll speed 

var startOver = mask_mc._y = textblock_mc._y;
var endPoint = textblock_mc._height - mask_mc._height;
mask_mc._width = textblock_mc._width;   
mask_mc._x = textblock_mc._x;
var i:Number = 0;
textblock_mc.setMask(mask_mc);

textblock_mc.onRollOver = function(){  //---- add more buttons if needed here
    _root.onEnterFrame = scrollTxt;
}

textblock_mc.onRollOut = function(){  //---- add more buttons if needed here
    delete _root.onEnterFrame;
}

up_button.onRelease = function (){
    textblock_mc._y = startOver;
      i=0;
}
function scrollTxt(){
    i=i+speed;
    if(i >= endPoint){
        delete _root.onEnterFrame;
    } else {
        textblock_mc._y -= speed;
    }
}

这就是你所需要的。此外,如果手动放置遮罩,还可以进一步减少代码。

autoScroll的最终代码:

// Start AutoScroll
var my_timedProcess:Number = setTimeout(autoScroll, 2000, "two second delay");

// Define AutoScroll
function autoScroll () {
    scrollInterval = setInterval(moveDragger, 150, 1);
}

//Stop AutoScroll on Rollover
mask_mc.onRollOver = down_btn.onRollOver = up_btn.onRollOver = dragger.onRollOver = bar.onRollOver = function () {
    clearInterval(scrollInterval);
};

//Start AutoScroll on RollOut
mask_mc.onRollOut = down_btn.onRollOut = up_btn.onRollOut = function () {
    scrollInterval = setInterval(moveDragger, 150, 1);
};

谢谢你的帮助。通过使用您的代码并重新检查我正在使用的内容,我能够找到一种使用moveDragger函数的方法,这种方法可以为我自动滚动。autoscroll代码可以在我的原始帖子底部找到。