Created
July 23, 2010 07:30
-
-
Save micapam/487127 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.greenchord.components | |
{ | |
import flashx.textLayout.container.ContainerController; | |
import flashx.textLayout.events.CompositionCompleteEvent; | |
import flashx.textLayout.events.TextLayoutEvent; | |
import mx.controls.VScrollBar; | |
import mx.events.ScrollEvent; | |
public class TlfScrollBar extends VScrollBar | |
{ | |
public function get controller():ContainerController | |
{ return _controller; } | |
public function set controller(value:ContainerController):void | |
{ | |
_controller = value; | |
controller.textFlow.addEventListener( | |
CompositionCompleteEvent.COMPOSITION_COMPLETE, | |
handleCompositionComplete); | |
controller.textFlow.addEventListener(TextLayoutEvent.SCROLL, | |
handleTextScroll); | |
} | |
private var _controller:ContainerController; | |
public function TlfScrollBar() | |
{ | |
super(); | |
addEventListener(ScrollEvent.SCROLL, handleScroll); | |
} | |
private function handleCompositionComplete( | |
event:CompositionCompleteEvent):void | |
{ | |
var contentHeight:int = Math.ceil( | |
controller.getContentBounds().height); | |
var oldPos:Number = controller.verticalScrollPosition; | |
if (contentHeight < controller.compositionHeight) | |
{ | |
enabled = false; | |
} | |
else | |
{ | |
enabled = true; | |
minScrollPosition = 0; | |
maxScrollPosition = contentHeight | |
- controller.compositionHeight; | |
lineScrollSize = 20; | |
pageSize = controller.compositionHeight; | |
} | |
controller.verticalScrollPosition = oldPos; | |
} | |
private function handleScroll(event:ScrollEvent):void | |
{ | |
controller.textFlow.removeEventListener(TextLayoutEvent.SCROLL, | |
handleTextScroll); | |
controller.verticalScrollPosition = event.position; | |
controller.textFlow.addEventListener(TextLayoutEvent.SCROLL, | |
handleTextScroll); | |
} | |
private function handleTextScroll(event:TextLayoutEvent):void | |
{ | |
removeEventListener(ScrollEvent.SCROLL, handleScroll); | |
scrollPosition = Math.ceil(controller.verticalScrollPosition); | |
addEventListener(ScrollEvent.SCROLL, handleScroll); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment