PDA

Просмотр полной версии : горизонтальный скролл


spacey999
08.02.2010, 14:01
Люди помогите, скачал прикольный горизонтальный скролл полностью на AS, как присоединить любой другой дизайн к полосе прокрутки?

import mx.transitions.Tween;
import mx.transitions.easing.*;

var myGalleryXML = new XML();
myGalleryXML.ignoreWhite = true;
myGalleryXML.load("gallery.xml");

myGalleryXML.onLoad = function() {

_root.gallery_width = myGalleryXML.firstChild.attributes.width;
_root.gallery_height = myGalleryXML.firstChild.attributes.height;
_root.gallery_y = myGalleryXML.firstChild.attributes.y;

_root.spacing = myGalleryXML.firstChild.attributes.vertical_spacing;
_root.bar_y = Number(_root.gallery_height)+Number(_root.spacing);
_root.bar_thickness = myGalleryXML.firstChild.attributes.bar_thickness;
_root.scroller_width = _root.bar_thickness*2;

_root.image_width = myGalleryXML.firstChild.attributes.image_width;

_root.myImages = myGalleryXML.firstChild.childNodes;
_root.myImagesTotal = _root.myImages.length;

createContainer();
callImages();
masking();
scrollbar();
scroller();

};

function createContainer() {
_root.myGallery_mc = _root.createEmptyMovieClip("myGallery_mc", _root.getNextHighestDepth());
_root.myGallery_mc._y = _root.gallery_y;
_root.myGallery_mc._x = (Stage.width-_root.gallery_width)/2;

}

function callImages() {

_root.myImages_mc = _root.myGallery_mc.createEmptyMovieClip("myImages_mc", _root.myGallery_mc.getNextHighestDepth());

var myMCL:MovieClipLoader = new MovieClipLoader();

for (i=0; i<_root.myImagesTotal; i++) {
imageURL = _root.myImages[i].attributes.url;
image_mc = _root.myImages_mc.createEmptyMovieClip(i, _root.myImages_mc.getNextHighestDepth());
image_mc._x = _root.image_width*i;

myMCL.loadClip(imageURL,image_mc);
}

}

function masking() {
_root.myMask_mc = _root.myGallery_mc.createEmptyMovieClip("myMask_mc", _root.myGallery_mc.getNextHighestDepth());

_root.myMask_mc.beginFill(0x000000,100);
_root.myMask_mc.lineTo(_root.gallery_width,0);
_root.myMask_mc.lineTo(_root.gallery_width,_root.gallery_height);
_root.myMask_mc.lineTo(0,_root.gallery_height);
_root.myMask_mc.lineTo(0,0);
_root.myMask_mc.endFill();

_root.myImages_mc.setMask(_root.myMask_mc);

}

function scrollbar() {
_root.scrollbar_mc = _root.myGallery_mc.createEmptyMovieClip("scrollbar_mc", _root.myGallery_mc.getNextHighestDepth());
_root.scrollbar_mc._y = _root.bar_y;

_root.scrollbar_mc.beginFill(0x000000,100);
_root.scrollbar_mc.lineTo(gallery_width,0);
_root.scrollbar_mc.lineTo(gallery_width,_root.bar_thickness);
_root.scrollbar_mc.lineTo(0,_root.bar_thickness);
_root.scrollbar_mc.lineTo(0,0);
_root.scrollbar_mc.endFill();

_root.scrollbar_mc.onPress = function() {
_root.scroller_mc._x = this._xmouse;

if (_root.scroller_mc._x>(this._width-_root.scroller_mc._width)) {
_root.scroller_mc._x = this._width-_root.scroller_mc._width;
}
mover();
};

}

function scroller() {
_root.scroller_mc = _root.myGallery_mc.createEmptyMovieClip("scroller_mc", _root.myGallery_mc.getNextHighestDepth());
_root.scroller_mc._y = _root.bar_y;

_root.scroller_mc.beginFill(0xFF0000,100);
_root.scroller_mc.lineTo(_root.scroller_width,0);
_root.scroller_mc.lineTo(_root.scroller_width,_root.bar_thickness);
_root.scroller_mc.lineTo(0,_root.bar_thickness);
_root.scroller_mc.lineTo(0,0);
_root.scroller_mc.endFill();

_root.scroller_mc.onPress = function() {
startDrag(this, false, 0, this._y, _root.scrollbar_mc._width-this._width, this._y);
moverInterval = setInterval(mover,250);
};

_root.scroller_mc.onRelease = _root.scroller_mc.onReleaseOutside=function () {
stopDrag();
clearInterval(moverInterval);
mover();
};
}

function mover() {
var scrollerLocation = _root.scroller_mc._x/(_root.scrollbar_mc._width-_root.scroller_mc._width);
var galleryLocation = scrollerLocation*(_root.myMask_mc._width-_root.myImages_mc._width);

new Tween(_root.myImages_mc, "_x", Strong.easeOut, _root.myImages_mc._x, galleryLocation, 1.5, true);
}

mooncar
08.02.2010, 15:21
Тут принцип другой, дизайн не "присоединяется", а программно рисуется в функции scrollbar().
Соответственно scrollbar_mc формируйте как-то по-другому, насколько хватит вашего опыта и фантазии.
Можете и "присоединить" с помощью аттачмента что-то свое вместо этого под этим же именем.