0

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.

  • Your question isn't clear to me. I don't know what this means: "However when I set the event within that component, remove public from the function definition, it acts as expected." Maybe you could add some code that shows what you do when it works as expected, or at least clarify what you mean by "when I set the event within that component". – Sunil D. Aug 20 '13 at 15:45
  • I need to programmatically scroll the contents of an . – Jacob Gaiski Aug 20 '13 at 16:25

1 Answers1

0

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.

Sunil D.
  • 17,983
  • 6
  • 53
  • 65
  • Ok...Wow, thank you. That solved my issue entirely. Spent 5 or so days on this trying to implement a scrollRect object.... All to need one line of code. Thanks! – Jacob Gaiski Aug 20 '13 at 16:43