Class ch.component.scrollbar.ScrollBarModel

Description

Manager of content that can be scrolled.

Field Index

onScroll

Method Index

new ScrollBarModel()
addListener(), adjust(), fireScrollPerformed(), getContent(), getMask(), getScrollManager(), getType(), isScrollable(), refresh(), removeListener(), scroll(), setMargins(), setScrollManager(), toString()

Constructor Detail

ScrollBarModel

public function ScrollBarModel(scrollManager:ScrollManager)

Create a new ScrollBarModel.

The ScrollManager is the manager that will be used for the scroll calculation and the position adjustment. So the target of the ScrollManager should be the content and the delimiter should be the mask.

Parameters

scrollManagerThe ScrollManager to use.

Throws

ErrorIf scrollManager is null.

Field Detail

onScroll

public onScroll:Function
Called when a scroll is performed.

Prototype :
scb.onScroll = function(eventSource:Object, scrolled:Number, ratio:Number, position:Number, refreshOnly:Boolean):Void { }

Method Detail

addListener

public function addListener(listener:ScrollListener):Void

Add a listener.

Parameters

listenerThe listener to add.

removeListener

public function removeListener(listener:ScrollListener):Void

Remove a listener.

Parameters

listenerThe listener to remove.

getScrollManager

public function getScrollManager(Void):ScrollManager

Get the ScrollManager of the model.

Note that if you call directly a method from the ScrollManager, the events won't be dispatched. It may cause problems on the listeners of the ScrollBarModel.

Return

The ScrollManager

setScrollManager

public function setScrollManager(scrollManager:ScrollManager, fireEvent:Boolean):Void

Set the ScrollManager of the ScrollBarModel.

If the fireEvent is true, an event scrollPerformed will be dispatched to the listeners, so they can update them to the current state of the new ScrollManager. The scroll value will be 0.

Parameters

scrollManagerThe new ScrollManager.
fireEvent true to dispatch the event.

Throws

ErrorIf scrollManager is null.

setMargins

public function setMargins(topLeft:Number, bottomRight:Number):Void

Set the margins of the ScrollManager.

This method set margin1 and margin2 into the ScrollManager and call the adjust method with a ratio of 0 to reset the ScrollBar.

If you want to manually set the margins and readjust the ScrollBar, simply get the ScrollManager, set margin1 and margin2, and finally call the adjust method within your own ratio.

Parameters

topLeftThe top/left margin (depend of the ScrollBarModel type).
bottomRightThe bottom/right margin (depend of the ScrollBarModel type).

See Also

getContent

public function getContent(Void):MovieClip

Get the content clip.

Return

The content.

getMask

public function getMask(Void):MovieClip

Get the mask of the content.

Return

The mask.

getType

public function getType(Void):ScrollType

Get the scroll type.

Return

The ScrollType used.

scroll

public function scroll(value:Number, source:Object):Number

Scroll the target clip relatively with the specified value.

This method checks automatically the value to scroll. If the value is too big (or small), the it is automatically adjusted to scroll the exact value to reach the maximum (or minimum point). If this method returns 0, then no more scroll is available in the same direction.

The direction of the scroll is determinated by the sign of value. If value is less thant 0, then the content clip will be scrolled down. It means that it has the same effect as if you click the up arrow on a classical scroll bar.

Parameters

valueThe value to scroll.
sourceThe object that is changing the scroll or null.

Return

The number of pixels scrolled.

See Also

adjust

public function adjust(ratio:Number, source:Object):Number

Adjust the scroll within the specified ratio.

This method ajust the content to the mask at the specified ratio. The ratio of the content position is calculated on the size of the content minus the size of the mask.

Since the version 1.8.1 the ratio value is automatically adjusted to 0 if the value is less than 0 and to 1 if the value is greater than 1.

Parameters

ratioA Number between 0 and 1 inclusive.
sourceThe object who is adjusting the scroll or null.

Return

The number of pixels scrolled.

See Also

refresh

public function refresh(source:Object, updateContent:Boolean):Void

Refresh the ScrollBarModel.

This method simply dispatch an event where the scroll value is 0. This will update all the listeners of the ScrollBarModel. Note that you can use this method when you update the content position directly ! It is important to not have tweens working on the content when you call this method, because the positions will not be correct.

Parameters

sourceThe source object that perform the refresh or null.
updateContentIndicates if the content must be moved when it is out of bounds (false by default).

See Also

isScrollable

public function isScrollable(Void):Boolean

Get if the content can be scrolled.

If this method returns false, then a ScrollBar is not useful because the content can be completely shown in the mask.

Return

true if a ScrollBar is needed.

fireScrollPerformed

public function fireScrollPerformed(scrolled:Number, source:Object, refreshOnly:Boolean):Void

Dispatch the scrollPerformed event to the listeners.

This method is conceptually public in order to be called by the subclasses ! It should not be called by the other classes. Use the refresh method in place.

Parameters

scrolledThe number of pixels scrolled.
sourceThe object performing the event or null.

See Also

toString

public function toString(Void):String

Represent the current instance into a String.

Return

A String representing the ScrollBarModel instance.