Flash Component Unable to set scrollRect

449 views Asked by At

I have a component and I'm attempting to set a scrollRect from within the global application code.

When I define the function as

public function foo():void{ obj.scrollRect = new Rectangle(blah,blah,blah,blah); }

the scrollRect does not get applied, nor does the viewport change.

However when I set the event within that component, remove public from the function definition, it acts as expected.

I need to programmatically scroll the contents of an

This function works as expected with a gradual scroll:

function mouseClickNext(event:MouseEvent):void{
            var sum:Number = bookmark_navigator.width -x_holder;
            if( sum<= 310)return;
            if(bookmark_navigator.width >= 310){

                var obj:Rectangle = bookmark_navigator.scrollRect;
                var setWidth:Number = bookmark_navigator.numElements * 28;

                if(x_holder + 40 >= bookmark_navigator.width)
                    x_holder=bookmark_navigator.width;
                else x_holder += 40;
                bookmark_navigator.scrollRect = new Rectangle(x_holder,0,bookmark_navigator.width,30);
            }
        }

However, this function does not:

var np:Number = 0;
        public function check():void{
            return;
            np= 0;
            while(true){
                try{

                    var sum:Number = bookmark_navigator.width -np;
                    if( sum<= 310)break;
                    np += 40;
                }catch(e:Error){break;}
            }
            bookmark_navigator.scrollRect = new Rectangle(np,0,bookmark_navigator.width,30);
        }

The return was added in as a means of testing.

1

There are 1 answers

1
Sunil D. On BEST ANSWER

If you are using Flex, you probably should avoid using the scrollRect property, since Flex has it's own implementation of scrolling behavior.

Typically, you wrap your <s:HGgroup> in a <s:Scroller>. To adjust the scroll position, you can then change the horizontalScrollPosition or verticalScrollPosition properties of the Scroller.