Class ch.component.scrollbar.ScrollManager

Description

Manage the scrolling of a MovieClip behind a mask.

This class manages the calculation of the scroll and the effect of the scroll. If you want to customize your scroll effects on the content, you can simply override the move(MovieClip,String,Number) method to set your personnal effect.

Field Index

margin1, margin2

Method Index

new ScrollManager()
getAllowedScroll(), getContentRatio(), getCurrentPosition(), getDelimiter(), getMaxMove(), getMinMove(), getRatio(), getRealRatio(), getTarget(), getType(), getVirtualPosition(), init(), move(), scroll(), setCurrentPosition(), setRatio(), setScrollType(), toString(), updateCurrentPosition()

Constructor Detail

ScrollManager

public function ScrollManager(target:MovieClip, delimiter:MovieClip, scrollType:ScrollType)

Create a new ScrollManager.

The target represent the clip that will be behind the mask. The delimiter is supposed to be the mask of the target. The scrollType set the direction of the scroll.

Parameters

targetThe target clip.
delimiterThe target clip delimiter (mask).
scrollTypeThe ScrollType to use.

Throws

ErrorIf target is null.
ErrorIf delimiter is null.

Field Detail

margin1

public margin1:Number
Represent the top/left margin.

By default, this value is 0.

margin2

public margin2:Number
Represent the bottom/right margin.

By default, this value is 0.

Method Detail

getTarget

public function getTarget(Void):MovieClip

Get the target clip.

Return

The target clip.

getDelimiter

public function getDelimiter(Void):MovieClip

Get the target clip delimiter.

Return

The clip delimiter.

setScrollType

public function setScrollType(type:ScrollType):Void

Set the scroll type to use on the target content.

Parameters

typeThe ScrollType to set.

Throws

ErrorIf type is null.

init

public function init(Void):Void

Initilalize the content.

This method simply set the _x/_y position (depending on the scroll type) of the content MovieClip. It is automatically called when the setScrollType method is called.

getType

public function getType(Void):ScrollType

Get the scroll type.

Return

The ScrollType used.

getMinMove

public function getMinMove(Void):Number

Get the minimum allowed position.

The returned value is an integer rounded with Math.floor()

Return

The minimum allowed position.

getMaxMove

public function getMaxMove(Void):Number

Get the maximum allowed position.

The returned value is an integer rounded with Math.round()

Return

The maximum allowed position.

getVirtualPosition

public function getVirtualPosition(Void):Number

Get the virtual position of the content.

This position is the real position where the target content should be. Instead of the getCurrentPosition method, this method returns the real virtual position.

Return

The virtual position.

getCurrentPosition

public function getCurrentPosition(Void):Number

Get the current position of the target relatively to 0.

This method return the position where the target should be if the center point is 0.

Return

A Number between 0 and getMaxMove()-getMinMove() inclusive.

setCurrentPosition

public function setCurrentPosition(position:Number):Number

Set the current position of the target.

Parameters

positionA Number between 0 and getMaxMove()-getMinMove() inclusive.

Return

The number of pixel scrolled.

Throws

ErrorIf position is invalid.

updateCurrentPosition

public function updateCurrentPosition(updateContentPosition:Boolean):Void

Update the current position of the target.

This method simple take the current position of the target. If you call it, it is recommended to stop all the tweens in order to have the correct value. Note that if the value of the target is lower that getMinMove() or greater that getMaxMove(), the virtual position will be set to the maximum or the minimum, so the ratio won't exceed 1 or be lower thant 0 !

Parameters

updateContentPositionIndicates whethever the content position must be updated (false by default).

getRealRatio

public function getRealRatio(Void):Number

Get the current real ratio of the position between the target clip and the delimiter clip.

This method take the current position of the content. So if you have a Tween affecting it, the value returned by this method will be altered.

Return

A Number between 0 and 1 inclusive.

See Also

getRatio

public function getRatio(Void):Number

Get the ratio of the position between the target clip and the delimiter clip.

This method return the ratio calculated on the target virtual position. It means that if a Tween is currently acting on the content MovieClip, your ratio won't change : it will be calculated as if the content was on his final place.

Parameters

See Also

setRatio

public function setRatio(ratio:Number):Number

Set the ratio of the target.

Parameters

ratioA Number between 0 and 1 inclusive.

Return

The number of pixels scrolled.

Throws

ErrorIf ratio is invalid.

getContentRatio

public function getContentRatio(Void):Number

Get the size ratio between the content and the background.

Return

The size ratio of the content.

getAllowedScroll

public function getAllowedScroll(value:Number):Number

Get the allowed scroll value.

If this method returns 0, then no more scroll is available in the specified position.

Parameters

valueThe number of pixels to scroll.

Return

The number of pixels that can be scrolled.

Throws

ErrorIf value is null.

scroll

public function scroll(value:Number):Number

Scroll the target clip relatively with the specified value.

This method checks automatically the value.

Parameters

valueThe value to scroll.

Return

The number of pixels scrolled.

move

public function move(target:MovieClip, property:String, valueToMove:Number):Void

Move the specified property of the specified target within the specified valueToMove value.

By default, this method set the property of the target to the virtual position.

Parameters

targetThe MovieClip to move.
propertyThe property to use for the moving ( _x or _y).
valueToMoveThe number of pixels to move.

toString

public function toString(Void):String

Represent the current instance into a String.

Return

A String representing the ScrollManager instance.