NEU: Alle Visual Codes als Code Snippets für Flash CS5:
jetzt hier downloaden .

Scrollbox

Code Actionscript 2.0

Instanz-Aktion bar

onClipEvent (load) {
// highest and lowest possible position of scrollbar:
top = _parent.box._y + 2;
bottom = (_parent.box._height - 2) + _parent.box._y - this._height;

// range of possible values:
scrollrange = bottom - top;

// proportion between height of scrolled content and scrollrange:
scrollfactor = (_parent.content._height - (_parent.box._height - 8)) / scrollrange;
py = top;
mousepressed = 0;
}
on (press) {
mousepressed = 1;
}
on (release, releaseOutside) {
mousepressed = 0;
}
onClipEvent (enterFrame) {
if (mousepressed == 1) {
py = _parent._ymouse - this._height / 2;
}
if (py < top) {
py = top;
}
if (py > bottom) {
py = bottom;
}
this._y = py;
_parent.content._y = 2 - scrollfactor * (py - top);
}

Code Actionscript 3.0

stage.addEventListener(Event.ENTER_FRAME, enterFrame); stage.addEventListener(MouseEvent.MOUSE_UP, releaseOutside); bar.addEventListener(MouseEvent.MOUSE_DOWN, press); bar.addEventListener(MouseEvent.MOUSE_UP, release); // highest and lowest possible position of scrollbar: var top = box.y + 2; var bottom = (box.height - 2) + box.y - bar.height; // range of possible values: var scrollrange = bottom - top; // by how much does content exceed box: var scrollfactor = (content.height - (box.height - 8)) / scrollrange; var py = top; var mousepressed = 0; function press(e:MouseEvent) { mousepressed = 1; } function release(e:MouseEvent){ mousepressed = 0; } function releaseOutside(e:MouseEvent) { mousepressed = 0; } function enterFrame(event:Event) { if (mousepressed == 1) { py = mouseY - bar.height / 2; } if (py < top) { py = top; } if (py > bottom) { py = bottom; } bar.y = py; content.y = top - scrollfactor * (py - top); }

Infos

Mit diesem Scrollbar können verschiedene Inhalte gescrollt werden (Text oder Bild), die insgesamt grösser sind als die umgebende Box. Die Variablen top bottom bezeichnen die Koordinaten der Begrenzungsbox. Der scrollfactor bezeichnet das Verhältnis zwischen der Höhe des überstehenden Inhalts und der Höhe der Box. Zum Scrollen von anderen Objekten als Text muss die Instanz "content" durch ein Bild oder eine sonstige Instanz ersetzt werden.

verwandt mit: Maus Position, Slider

Download

Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File


Share