If you want to make a Elastic scroller, with some elastic effects depending on how you move the mouse, check this post.
This code is intend to help you to make a scroller bar which we use to drag, so we can scroll the content:
onClipEvent (load)
{
buttonSize = 0;
viewHeight = _parent.scroll_bg._height;
viewWidth = _parent.scroll_bg._x;
scrollContent = _parent.for_text;
heightCorect = false;
mouseWheelHitTest = true;
wheelStep = 1;
pageStep = 10;
pageStep2 = 10;
pageDelay = 200;
arroyStep = 10;
arroyStep2 = 5.000000E-001;
arroyDelay = 3;
speedDec = 6.500000E-001;
scrollStep = _parent.speed;
setProperty(“”, _x, scrollContent._x + viewWidth);
setProperty(“”, _y, scrollContent._y);
dragButtonIsDraging = false;
scrollPos = 0;
upButton._y = 0;
pageUpButton._x = 0;
pageDownButton._x = 0;
contentHeight = heightCorect ? (scrollContent.height) : (scrollContent._height);
scrollHeight = viewHeight – buttonSize * 2;
dragButtonHeight = viewHeight < contentHeight ? (viewHeight * scrollHeight / contentHeight) : (scrollHeight);
dragButton._yscale = dragButtonHeight;
dragButton._y = buttonSize;
downButton._y = buttonSize + scrollHeight;
blanckDown._y = downButton._y;
blanckUp._x = 0;
blanckUp._y = 0;
blanck._x = 0;
blanck._y = buttonSize;
blanckDown._x = 0;
pageUpButton._y = buttonSize;
blanck._height = scrollHeight;
blanckUp._visible = viewHeight < contentHeight ? (false) : (true);
blanck._visible = viewHeight < contentHeight ? (false) : (true);
blanckDown._visible = viewHeight < contentHeight ? (false) : (true);
upButton._visible = viewHeight < contentHeight ? (true) : (false);
dragButton._visible = viewHeight < contentHeight ? (true) : (false);
downButton._visible = viewHeight < contentHeight ? (true) : (false);
_parent.drag._visible = viewHeight < contentHeight ? (true) : (false);
_parent.down._visible = viewHeight < contentHeight ? (true) : (false);
mouseListener = new Object();
mouseListener.onMouseWheel = function (delta)
{
if (!mouseWheelHitTest || scrollContent.hitTest(_root._xmouse, _root._ymouse, false) || hitTest(_root._xmouse, _root._ymouse, false))
{
dragButton._y = dragButton._y – delta * wheelStep;
if (dragButton._y < buttonSize)
{
dragButton._y = buttonSize;
} // end if
if (dragButton._y > buttonSize + scrollHeight – dragButtonHeight)
{
dragButton._y = buttonSize + scrollHeight – dragButtonHeight;
} // end if
} // end if
};
Mouse.addListener(mouseListener);
curY = -scrollContent._y;
vY = 0;
mask = scrollContent._parent.createEmptyMovieClip(“mask”, scrollContent._parent.getNextHighestDepth());
with (mask)
{
} // End of with
}
onClipEvent (enterFrame)
{
blanckUp._visible = viewHeight < contentHeight ? (false) : (true);
blanck._visible = viewHeight < contentHeight ? (false) : (true);
blanckDown._visible = viewHeight < contentHeight ? (false) : (true);
upButton._visible = viewHeight < contentHeight ? (true) : (false);
dragButton._visible = viewHeight < contentHeight ? (true) : (false);
downButton._visible = viewHeight < contentHeight ? (true) : (false);
_parent.drag._visible = viewHeight < contentHeight ? (true) : (false);
_parent.down._visible = viewHeight < contentHeight ? (true) : (false);
_parent.scroll_bg._visible = viewHeight < contentHeight ? (true) : (false);
if (incDelay < 0)
{
dragButton._y = dragButton._y – inc;
if (dragButton._y < buttonSize)
{
dragButton._y = buttonSize;
} // end if
if (dragButton._y > buttonSize + scrollHeight – dragButtonHeight)
{
dragButton._y = buttonSize + scrollHeight – dragButtonHeight;
} // end if
} // end if
–incDelay;
contentHeight = heightCorect ? (scrollContent.height) : (scrollContent._height);
scrollHeight = viewHeight – buttonSize * 2;
dragButtonHeight = viewHeight < contentHeight ? (viewHeight * scrollHeight / contentHeight) : (scrollHeight);
dragButton._yscale = dragButtonHeight;
downButton._y = buttonSize + scrollHeight;
pageDownButton._y = dragButton._y + dragButtonHeight;
pageDownButton._yscale = scrollHeight – dragButtonHeight – dragButton._y + buttonSize – scrollPos;
pageUpButton._yscale = dragButton._y – buttonSize;
if (dragButtonIsDraging)
{
stopDrag ();
startDrag (dragButton, false, 0, buttonSize, 0, buttonSize + scrollHeight – dragButtonHeight + 1);
} // end if
if (dragButton._y > buttonSize + scrollHeight – dragButtonHeight)
{
dragButton._y = buttonSize + scrollHeight – dragButtonHeight;
} // end if
newY = (dragButton._y – buttonSize) / dragButtonHeight * viewHeight;
vY = vY + (curY – newY) / scrollStep;
vY = vY * speedDec;
curY = curY – vY;
scrollContent._y = Math.floor(-curY + _y);
}
onClipEvent (enterFrame)
{
if (_parent.down_but == true)
{
with (_parent.scroll)
{
if (dragButton._y < buttonSize + scrollHeight – dragButtonHeight – _parent.step)
{
dragButton._y = dragButton._y + _parent.step;
}
else
{
dragButton._y = buttonSize + scrollHeight – dragButtonHeight;
} // end if
} // End of with
} // end else if
if (_parent.drag_but == true)
{
if (_parent.scroll.dragButton._y > _parent.step)
{
_parent.scroll.dragButton._y = _parent.scroll.dragButton._y – _parent.step;
}
else
{
_parent.scroll.dragButton._y = 0;
} // end if
} // end else if
}
I will link to a source file soon. Just have to arrange some place where to host sample files. Is there anyone can tell me a good free hosting where can i put files to be visited and downloaded?
Leave your comments.
Tags: actionscript 2, Adobe, code, elastic, Flash, scroller, Source
| Copy and Paste the code below | |
| Email and IM | |
| Websites | |
| Forums | |
follow:
January 25th, 2007 at 12:27 am
if you want a place to upload files go to http://www.filefront.com, or try http://www.divshare.com
January 25th, 2007 at 9:12 am
Hi m8, tnx for yr comment. It was the 1st at my blog!!! Tell me, is there any hosting server, could handle asp .net scripts for free?
Just want to start my web site with flash, but i will use some scripts to connect with e-mail and access database. Can you give me an help?
Mny tnx
January 26th, 2007 at 8:04 pm
If you want ASP check this listing over here: http://www.free-webhosts.com/free-asp-hosting.php
March 11th, 2007 at 10:24 am
can you please upload the fla. thanks.
May 29th, 2007 at 12:39 am
wondering if you can explain how to adjust the mask size of the scrolled content?
March 24th, 2009 at 5:54 pm
Thank you, but how increase button size? if is a long text?