// Copyright 2007. Adobe Systems Incorporated. All Rights Reserved.
package fl.controls {
import Error;
import fl.controls.ScrollBar;
import fl.controls.ScrollBarDirection;
import fl.core.InvalidationType;
import fl.core.UIComponent;
import fl.events.ScrollEvent;
import flash.events.Event;
import flash.events.TextEvent;
import flash.text.TextField;
//--------------------------------------
// Class description
//--------------------------------------
/**
* The student_ar_fl_controls_UIScrollBar class includes all of the scroll bar functionality, but
* adds a scrollTarget()
method so it can be attached
* to a TextField component instance.
*
*
Note: When you use ActionScript to update properties of
* the TextField component that affect the text layout, you must call the
* update()
method on the student_ar_fl_controls_UIScrollBar component instance to refresh its scroll
* properties. Examples of text layout properties that belong to the TextField
* component include width
, height
, and wordWrap
.
scrollTarget
text field
* is added using ActionScript, and the scroll bar needs to be refreshed.
*
* @see #scrollTarget
*
* @includeExample examples/student_ar_fl_controls_UIScrollBar.update.1.as -noswf
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function update():void {
inEdit = true;
updateScrollTargetProperties();
inEdit = false;
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override protected function draw():void {
if (isInvalid(InvalidationType.DATA)) {
updateScrollTargetProperties();
}
super.draw();
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
protected function updateScrollTargetProperties():void {
if (_scrollTarget == null) {
setScrollProperties(pageSize,minScrollPosition,maxScrollPosition,pageScrollSize);
scrollPosition = 0;
} else {
var horizontal:Boolean = (direction == ScrollBarDirection.HORIZONTAL);
var pageSize:Number = horizontal ? _scrollTarget.width : 10;
setScrollProperties(pageSize, (horizontal ? 0 : 1), horizontal?_scrollTarget.maxScrollH:_scrollTarget.maxScrollV, pageScrollSize);
scrollPosition = horizontal?_scrollTarget.scrollH:_scrollTarget.scrollV;
}
}
/**
* @copy fl.controls.ScrollBar#setScrollProperties()
*
* @see ScrollBar#pageSize ScrollBar.pageSize
* @see ScrollBar#minScrollPosition ScrollBar.minScrollPosition
* @see ScrollBar#maxScrollPosition ScrollBar.maxScrollPosition
* @see ScrollBar#pageScrollSize ScrollBar.pageScrollSize
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override public function setScrollProperties(pageSize:Number,minScrollPosition:Number,maxScrollPosition:Number,pageScrollSize:Number=0):void {
var maxScrollPos:Number = maxScrollPosition;
var minScrollPos:Number = (minScrollPosition<0)?0:minScrollPosition;
if (_scrollTarget != null) {
if (direction == ScrollBarDirection.HORIZONTAL) {
maxScrollPos = (maxScrollPosition>_scrollTarget.maxScrollH) ? _scrollTarget.maxScrollH : maxScrollPos;
} else {
maxScrollPos = (maxScrollPosition>_scrollTarget.maxScrollV) ? _scrollTarget.maxScrollV : maxScrollPos;
}
}
super.setScrollProperties(pageSize,minScrollPos,maxScrollPos,pageScrollSize);
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override public function setScrollPosition(scrollPosition:Number, fireEvent:Boolean=true):void {
super.setScrollPosition(scrollPosition, fireEvent);
if (!_scrollTarget) { inScroll = false; return; }
updateTargetScroll();
}
// event default is null, so when user calls setScrollPosition, the text is updated, and we don't pass an event
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
protected function updateTargetScroll(event:ScrollEvent=null):void {
if (inEdit) { return; } // Update came from the user input. Ignore.
if (direction == ScrollBarDirection.HORIZONTAL) {
_scrollTarget.scrollH = scrollPosition;
} else {
_scrollTarget.scrollV = scrollPosition;
}
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
protected function handleTargetChange(event:Event):void {
inEdit = true;
setScrollPosition((direction == ScrollBarDirection.HORIZONTAL)?_scrollTarget.scrollH:_scrollTarget.scrollV, true);
updateScrollTargetProperties();
inEdit = false;
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
protected function handleTargetScroll(event:Event):void {
if (inDrag) { return; }
if (!enabled) { return; }
inEdit = true;
updateScrollTargetProperties(); // This needs to be done first!
scrollPosition = (direction == ScrollBarDirection.HORIZONTAL)?_scrollTarget.scrollH:_scrollTarget.scrollV;
inEdit = false;
}
}
}