PDA

View Full Version : Scrollpane


rickid
07-29-2006, 05:15 PM
Hi,

I've looked through loads of posts about this question but I can't find a solution and just wondered if any flash genius out there can provide it once and for all!

I'm loading an swf into a scrollpane:

1. Firstly I want the content to be centered in the scrollpane. When I use the following code, any redraw function of moving the scrollbars resets the position to the top left.


var scrollwidth = myscrollpane.width / 2;
var scrollheight = myscrollpane.height / 2;

var contentX = (myscrollpane.content.width / 2) + myscrollpane.content._x;
var contentY = (myscrollpane.content.height / 2) + myscrollpane.content._y;

myscrollpane.content._x = (scrollwidth) - (contentX);
myscrollpane.content._y = (scrollheight) - (contentY);

2. I want a zoom in/out button to zoom the movie at the center of the scrollpane. I'm currently using 'myscrollpane.content._xscale'


Many thanks!

Rik

rickid
07-29-2006, 06:02 PM
Hi,

I've looked through loads of posts about this question but I can't find a solution and just wondered if any flash genius out there can provide it once and for all!

I'm loading an swf into a scrollpane:

1. Firstly I want the content to be centered in the scrollpane. When I use the following code, any redraw function of moving the scrollbars resets the position to the top left.


var scrollwidth = myscrollpane.width / 2;
var scrollheight = myscrollpane.height / 2;

var contentX = (myscrollpane.content.width / 2) + myscrollpane.content._x;
var contentY = (myscrollpane.content.height / 2) + myscrollpane.content._y;

myscrollpane.content._x = (scrollwidth) - (contentX);
myscrollpane.content._y = (scrollheight) - (contentY);

2. I want a zoom in/out button to zoom the movie at the center of the scrollpane. I'm currently using 'myscrollpane.content._xscale'


Many thanks!

Rik

rickid
07-29-2006, 06:18 PM
Ok. I've found the solution to question 1:


var paneListener:Object = new Object();
paneListener.complete = function() {

var scrollwidth = scrollpane.width / 2;
var scrollheight = scrollpane.height / 2;

var contentX = (scrollpane.content.width / 2) + scrollpane.content._x;
var contentY = (scrollpane.content.height / 2) + scrollpane.content._y;

scrollpane.content._x = (scrollwidth) - (contentX);
scrollpane.content._y = (scrollheight) - (contentY);

scrollpane.hPosition = (scrollpane._width / 2) - (scrollpane.hSB._width / 2);
scrollpane.vPosition = (scrollpane._height / 2) - (scrollpane.vSB._height / 2);

};


scrollpane.addEventListener("complete", paneListener);
scrollpane.contentPath = "wddx21.swf";


Now I just need to work out the zooming thing. If anyone's got any advice I'd be really grateful.

Thanks!

oldnewbie
07-29-2006, 06:40 PM
Edited out!

rickid
07-29-2006, 07:21 PM
Thanks Old Newbie,

This works if the content is bigger than the scrollpane:

// Scale content
_root.scrollpane.content._xscale *= 2;
_root.scrollpane.content._yscale *= 2;

// New offset
var hPos = 2*_root.scrollpane.hPosition + _root.scrollpane.width/2;
var vPos = 2*_root.scrollpane.vPosition + _root.scrollpane.height/2;

// Refresh the pane to auto-add scrollbars
_root.scrollpane.setSize(_root.scrollpane.width, _root.scrollpane.height);

// Set the new positions
_root.scrollpane.hPosition = hPos;
_root.scrollpane.vPosition = vPos;

However on initial load, my content is smaller than the scrollpane. This is why my initial code needs this line which centers the content as opposite to the scrollbars:

scrollpane.content._x = (scrollwidth) - (contentX);

I'm a bit out of my depth here and not sure how to solve this!