It works except for the first time I call my moveToCenter function because the maxHorizontalScrollPosition is still 0 (see the comments below):
public function moveToCenter():void
{
trace( "moveToCenter()" );
var x:Number = useFixedCenter ? content.width/2 : contentCenter.x;
var y:Number = useFixedCenter ? content.height/2 : contentCenter.y;
var sx:Number = useFixedCenter ? 1 : content.scaleX;
var sy:Number = useFixedCenter ? 1 : content.scaleY;
horizontalScrollPosition = (x * sx) - (width/2);
trace( "horizontalScrollPosition: " + horizontalScrollPosition ); //this gives me the right number, but...
trace( "max hsp: " + this.maxHorizontalScrollPosition ); // the max horizontal scroll position is still zero the first time this function is called, so the scrollbar doesn't actually move
verticalScrollPosition = (y * sy) - (height/2);
}
If I store the new horizonatlScrollPosition in an instance variable and then set the horizontalScrollPosition property in updateDisplayList, it works but I know that's not the right way to do this. The following code shows what I mean:
public function moveToCenter():void
{
trace( "moveToCenter()" );
var x:Number = useFixedCenter ? content.width/2 : contentCenter.x;
var y:Number = useFixedCenter ? content.height/2 : contentCenter.y;
var sx:Number = useFixedCenter ? 1 : content.scaleX;
var sy:Number = useFixedCenter ? 1 : content.scaleY;
trace( "x: " + x );
horizontalScrollPosition = (x * sx) - (width/2);
trace( "horizontalScrollPosition: " + horizontalScrollPosition );
//I added this to hack it so it works the first time. see updateDisplayList below
_hsp = horizontalScrollPosition;
trace( "max hsp: " + this.maxHorizontalScrollPosition );
verticalScrollPosition = (y * sy) - (height/2);
}
override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ):void
{
super.updateDisplayList( unscaledWidth, unscaledHeight );
trace( "update display list" );
trace( maxHorizontalScrollPosition + ", " + horizontalScrollPosition );
horizontalScrollPosition = _hsp;
}
What's the right way to do this?
Thanks,
Tom
__._,_.___
SPONSORED LINKS
| Custom software development | Database development software | Embedded software development |
| Offshore software development | Software development |
Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe
__,_._,___
