PDA

View Full Version : Making componement scrollable?


remco-v
03-21-2005, 09:46 AM
Hello ,

I want to make my componement scrollable but have no idea how to properly go and do this. Ive tried with the scrollpane and dynamicly adding movie clips but ive failed in my attempts. I mean this way http://www.actionscript.org/forums/showthread.php3?t=49347&highlight=scrollpane+contentPath+dynamic


Is their anyone that can point me in the direction of a good tutorial or something on making movie clips scrollable?

Docta J3kyl
03-21-2005, 12:04 PM
Hi,

Attached is a doc which shows the steps to attach a movieClip to a scrollpane to make it scrollable. (The movie clip is not dynamically called, but is present in the same fla library only).

I hope this is what u were asking for, n hope it helps.

Credit: Flashkit.

remco-v
03-21-2005, 12:57 PM
Thank you but this is not what i was looking for.
Rebuilding my whole componement so that all the items are stored in the scrollPane instead of the movie clip is not the thing i am looking for.

Ive created my own solution and its working rather nicely if you ask me.
Fixed a few bugs in this edit of my post. I hope others find this usefull when creating their own scrollable movie clips/ componements.

What ive done is: Created a mask that hides the part of the movie that is beyond the max height size. When you use the scrollbar it will reposition all items in the movie clip with some exceptions. Ive still got to fix it for horizontal scrolling and make an array when you can store the exception items:) Updates coming soon. If you have any suggestions to make it more flexible, fast or stable please reply here.


//This is the code that makes my class scrollable at the moment.
class scrollableComponement
{
private var maxHeight:Number;
private var maxWidth:Number;
private var movieMask:MovieClip;
private var scrollBar;
private var objectYoffset:Array;
//--------------------------------------------------------------------
function scrollable()
{
if(this._height > maxHeight )
{
movieMask = this.attachMovie( "BoundingBox","movieMask",this.getNextHighestDepth(),{_x:0,_y:-20,_height:maxHeight,_width:maxWidth} );
this.setMask(movieMask);

objectYoffset = new Array();
this.createClassObject(mx.controls.UIScrollBar,"scrollBar",this.getNextHighestDepth()) ;
scrollBar.setScrollProperties(20, 0, (_height - maxHeight));
trace (this._height - 20);
scrollBar.setSize(20, (maxHeight - 20) );
scrollBar._x = this._width - scrollBar._width - 4;
scrollListener = new Object();
//_scrollPosition
scrollListener.scroll = function(eventObj)
{
for( id in eventObj.target._parent )
{
// save the initial y value of the object
if(!eventObj.target._parent.objectYoffset[id]) eventObj.target._parent.objectYoffset[id] = eventObj.target._parent[id]._y;

if(id != "titleLabel" && id != "scrollBar" && id != "dragger" && id != "movieMask")
{
eventObj.target._parent[id]._y = eventObj.target._parent.objectYoffset[id] - (eventObj.target._scrollPosition );
}
}

}
scrollBar.addEventListener("scroll", scrollListener);
}
}
}