Here’s an example. A dynamic scroll, that changes speed according to your mouse. Here is the code for it as well, I tried to keep it pretty generic, just put this onto a movie clip I named “scroll.” And change the variables to fit your needs. Enjoy, and let me know what you make with it.
- onClipEvent(load) {
- //variables
- scrollMovieClipW = this._width - Stage.width;
- leftScrollMargin = 175;
- rightScrollMargin = 275;
- verticalScrollMargin = 250;
- //Note: The lower acceleration value the faster the scroll will be.
- acceleration = 3;
- }
- onClipEvent (enterFrame) {
- //to move left
- //if mouse is right of 0 (left edge)
- if (_root._xmouse >= 0 &&
- //if mouse is left of left scroll margin
- _root._xmouse <= leftScrollMargin &&
- //if mouse is vertically below green line (over the scroll movie clip)
- _root._ymouse >= verticalScrollMargin &&
- //if the scroll movie clip can still scroll further
- _root.scroll._x <= 0) {
- this._x -= (_root._xmouse - leftScrollMargin) / acceleration;
- }
- //to move right
- else if (_root._xmouse >= rightScrollMargin &&
- _root._xmouse <= Stage.width &&
- _root._ymouse >= verticalScrollMargin &&
- _root.scroll._x >= -scrollMovieClipW) {
- //move right
- this._x -= (_root._xmouse - rightScrollMargin) / acceleration;
- }
- }
download the source.
Tags: actionscript, as2, download, experiment, flash, interactive, open source, tutorial
(2 votes, average: 4 out of 5)
