No one responded, but a friend helped me out with this. What I had not
understood is that the binding to verticalScrollPosition is one-way,
meaning that scrolling the app does not change the bound variable. So
when my code told the bound variable to reset to zero, nothing
happened because it was already zero.

I added an eventlistener on the scroll event of the app so that the
bound variable tracked the verticalScrollPosition properly, then
everything worked beautifully.

Also, note that setting the Application's width and height to 100%
makes the scrollbar appear in the browser so that you're scrolling the
app, not the browser, which makes this all doable and cool if you want
to dynamically scroll to the top of the app.

Jack

--- In flexcoders@yahoogroups.com, "jack_freud" <[EMAIL PROTECTED]> wrote:
>
> Hi,
> It seems that I can't bind a variable to the verticalScrollPosition
> property of my Flex app. 
> I want to do it using Cairngorm and my model locator, not sure how
> else to have a command scroll my application without breaking the
> paradigm and sending another message out that the app is listening to
> directly...
> 
> Here's a simple example that has 1 button setting a bound variable
> (doesn't work) and another button setting the property directly (works):
> 
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> layout="absolute" width="100%" 
>        verticalScrollPosition="{scrollPos}"
>       height="100%">
>       <mx:Script>
>               <![CDATA[
>                       [Bindable]
>                       public var scrollPos:int = 0;
>                       private function 
> setVerticalScrollPosition(pos:int):void{
>                               this.verticalScrollPosition=pos;
>                       }
>                       
>                       private function setScrollPos(pos:int):void{
>                               this.scrollPos = pos;
>                       }
> 
>               ]]>
>       </mx:Script>
>       <mx:DataGrid y="48.65" width="496" height="2000" horizontalCenter="-1">
>       
>               <mx:columns>
>                       <mx:DataGridColumn headerText="Column 1" 
> dataField="col1"/>
>                       <mx:DataGridColumn headerText="Column 2" 
> dataField="col2"/>
>                       <mx:DataGridColumn headerText="Column 3" 
> dataField="col3"/>
>               </mx:columns>
>       </mx:DataGrid>
>       <mx:Button x="648" y="2026" label="Change the bound variable"
> click="setScrollPos(0)"/>
>       <mx:Button x="848" y="2026" label="Change the property directly"
> click="setVerticalScrollPosition(0)"/>
>       <mx:Label x="112" y="10" text="Scroll to the bottom of this page"
> width="360" fontWeight="bold" fontSize="14"/>
>       
> </mx:Application>
> 
> 
> Thanks,
> Jack
>


Reply via email to