views:

1761

answers:

1

I'm building a Flash project that creates a menu system with dynamically loaded movie clips for the menu items themselves.

I want a scroll bar to appear once the menu has enough items that it's larger than the menu area.

I was thinking that I could just put a mask over the menu area and have the movie clip where the controls where loaded scroll up and down within the mask, but the dynamically loaded movie clips don't seem to appear in the mask.

I have searched around the internet for this, but all the scroll bar tutorials that I can find deal with text areas rather than an area with dynamically loaded movie clips.

Does anyone know of a good tutorial for this or have a suggestion as to an elegant way of doing this so I don't have to make a bunch of math hacks to make it work?

Thanks

+1  A: 

Hi,

Not sure exactly what you are after.

I just did a quick test with Flash CS3/AS3 and got loaded items to move around inside a mask (the base of a scroll box).

First I created a Mask layer then a new layer as a child of the mask. I added a new empty MovieClip to the Mask layer child. I named this MovieClip 'mcItems'.

I then attached the following frame script (of course using a Class would be preferable).

    for (var i:Number=0; i < 3; ++i)
    {
        var loader:Loader = new Loader();
        loader.load(new URLRequest('Content.swf'));
        mcItems.addChild(loader);
        loader.x = i * 120;
    };
    function update (event:Event)
    {
        mcItems.x = 120*Math.sin(getTimer()/500) - 60;
    };
    addEventListener(Event.ENTER_FRAME, update);

Now, Content.swf is just a 120x120 pixel gray box. My mask is 240x120. Upon execution the 3 Content.swf boxes are loaded and slide around inside the masked area as expected.

As for the scrollbar code, I am not sure what you mean by 'math hacks' but the basic principal is you are converting from one set of units to another. You are converting your "mask width / total items loaded with" units to your "scroll handle width / scroll bar width" units.

I recommend reviewing the appropriate manual pages for clarification of the code used above.

Regards, Jotham.

Jotham
It turns out my textboxes were dynamic and they won't show up under a mask unless you include the glyphs. Thanks.
Ryan Smith
That's pretty typical flash behavior.
Jotham