I wish I had a dime for every flash forum post I have seen where the user was asking for very basic usage of the Flash ScrollPane component. I think at least some of the confusion stems from the differences between the version 1 component and the version 2 component. In v1 you could set the content to a movieclip that was already on the stage. In v2 you have to use either an external asset or a movieclip that is in the LIBRARY. You use the linkage id of that movieclip as the contentPath of the scrollpane.
Sometimes users get frustrated because they think that does not allow them to put multiple items into the scrollpane, but that is not the case. What you do is set the contentPath to the linkage id of an empty MC in your library (sometimes a movieclip with a small transparent square works better). Then use the scrollpane.content property to get stuff inside the scrollpane using attachMovie. Once you set the contentPath of your scroll pane, the scrollpane.content will give you a reference to the movieclip inside the scrollpane that represents the contents. You can attach content to that just like you would any other movieclip.
Another common issue I see in the forums is "the scroll pane does not update the scrollbars based on the size of my loaded content." First, if you are setting the contentPath to an external asset (an image or another swf file for example), you need to determine when that assset has finished loading. There are plenty of ways to do that using the complete event, or movieClipLoader class, or some logic involving getBytesLoaded / getBytesTotal etc... When the content is finished loading, call the scrollpane's invalidate method and that will cause it to redraw and the scrollbars will be rendered to reflect the size of your content. I've seen many people recommend calling redraw(true). I do not recommend doing that. This will cause the component to redraw on EVERY frame. If you just call invalidate() at the proper time you are only making the component redraw when it needs to... much more efficient.
So the key points to remember...
-
ScrollPane.contentPath cannot be set to a movieclip instance on the stage... you must use the linkage id of a library asset or the url to an external asset.
- Once you set the contentPath, you can reference the content movieclip with ScrollPane.content property.
- Use the invalidate method at the proper time to get the component to redraw if you need it to.