Scrollbar with intertia Actionscript 2.0

var item_title:Array = new Array();
var item_url:Array = new Array();
var item_description:Array = new Array();
var total:Number;
var i:Number = 0;
var p:Number = 0;
var item_spacing:Number = 10;
var scrolling_speed:Number = 0.30; // 0.00 to 1.00
var cv:Number = 0;
var cv_old:Number = 0;
var on_drag:Boolean;
var xml:XML = new XML();
item_list_area._visible = false;
item_list.setMask(item_mask);
stop();

xml.onLoad = function()
{
item_list.fm_item._visible = false;
var nodes = this.firstChild.childNodes;
total = nodes.length;

for( i = 0; i < total; i++)
{
item_title[i] = nodes[i].attributes.title;
item_url[i] = nodes[i].attributes.url;
item_description[i] = nodes[i].attributes.description;
}
create_item_list();
scroller();
}
xml.load( “flashmo_077_news.xml” );
xml.ignoreWhite = true;
function create_item_list():Void
{
for( i = 0; i < total; i++)
{
var item = item_list.fm_item.duplicateMovieClip(“fm_item”+i, i);
item._y = i * (item_list.fm_item._height + item_spacing);
item.item_title.text = item_title[i];
item.item_description.text = item_description[i];
item.no = i;

item.item_button.onRelease = function()
{
getURL(item_url[this._parent.no]);
}
}
}
function scroller():Void
{
scroller_mc._y = scrollable_area_mc._y;
item_list._y = item_list_area._y;
sr = item_list_area._height/item_list._height;
scroller_mc._height = scrollable_area_mc._height * sr;
sd = scrollable_area_mc._height – scroller_mc._height;
cd = item_list._height – item_list_area._height;
cr = cd / sd;

if( item_list._height <= item_list_area._height )
{
scroller_mc._visible = scrollable_area_mc._visible = false;
}
else
{
scroller_mc._visible = scrollable_area_mc._visible = true;
}
scroller_mc.onPress = function()
{
this.startDrag(false, this._x, scrollable_area_mc._y, this._x,
scrollable_area_mc._y + scrollable_area_mc._height – this._height);
on_drag = true;
this.onEnterFrame = function()
{
new_y = item_list_area._y + scrollable_area_mc._y*cr – this._y*cr;
cv = (new_y – item_list._y) * scrolling_speed;
item_list._y += cv;
if( on_drag == false && cv_old == cv )
delete this.onEnterFrame;
cv_old = cv;
}
}
scroller_mc.onRelease = scroller_mc.onReleaseOutside = function()
{
this.stopDrag();
on_drag = false;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s