Adobe Systems, Inc.

ScrollingField.as

Go to the documentation of this file.
00001 /******************************************************************
00002 ** Copyright 2005-2006 Adobe Systems Incorporated
00003 ** Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004 ** or a copy at http://opensource.adobe.com/licenses.html)
00005 **
00006 ** ScrollingField Class 
00007 ********************************************************************/
00008 
00009 import mx.xpath.XPathAPI;
00010 import amg.*;
00011 
00012 class amg.ScrollingField extends MovieClip {
00013         //member properties
00014         public var fieldName:String;
00015         private var _iControlWidth:Number;
00016         private var _iControlHeight:Number;
00017         private var ScrollingFieldBg:MovieClip;
00018         public var txtField:TextField;
00019         private var txtFieldStyle:TextField.StyleSheet;
00020         private var _iTextFieldSideSpacer:Number = 12;
00021         public var iScrollingFieldTextWidth:Number;
00022         public var iScrollingFieldTextHeight:Number;
00023         private var ScrollBtnUp:MovieClip;
00024         private var ScrollBtnDown:MovieClip;
00025         private var ScrollLine:MovieClip;
00026         private var ScrollThumb:MovieClip;
00027         private var ScrollBarBg:MovieClip;
00028         //private var ScrollThumbMarks:MovieClip;
00029         private var _bScrollUsed:Boolean;
00030         private var _iScrollDistance:Number = 100;
00031         private var _iScrollFieldMargin:Number = 6;
00032         private var _iScrollBarBorder:Number = 0x333333;
00033         private var _iScrollBarBorderAlpha:Number = 100;
00034         private var _iScrollBarFill:Number = 0xdddddd;
00035         private var _iScrollBarFillAlpha:Number = 100;
00036         
00037         //class constructor
00038         public function ScrollingField() {
00039                 
00040                 //this.ScrollingFieldBg = this.attachMovie("ScrollingFieldBg", "ScrollingFieldBg", this.getNextHighestDepth());
00041         
00042                 this.createTextField("txtField",this.getNextHighestDepth(),_iTextFieldSideSpacer,0,200,50);
00043                 this.txtField.html = true;
00044                 this.txtField.mouseWheelEnabled = true;
00045                 this.txtField.multiline = true;
00046                 this.txtField.wordWrap = true;
00047                 this.txtField.antiAliasType = "advanced";
00048                 this.txtField.border = false;
00049                 this.ScrollBarBg = this.createEmptyMovieClip("mask",this.getNextHighestDepth());
00050                 this.ScrollLine =  this.attachMovie("ScrollLine","ScrollLine",this.getNextHighestDepth());
00051                 this.ScrollBtnUp =  this.attachMovie("ScrollBtnUp","ScrollBtnUp",this.getNextHighestDepth());
00052                 
00053                 this.ScrollBtnDown =  this.attachMovie("ScrollBtnDown","ScrollBtnDown",this.getNextHighestDepth());
00054                 
00055                 this.ScrollThumb =  this.attachMovie("ScrollThumb","ScrollThumb",this.getNextHighestDepth());
00056                 this.ScrollThumb.init("vertical");
00057                 this.ScrollThumb.onPress = scrollThumbDrag;
00058                 this.ScrollThumb.onRelease = scrollThumbStopDrag;
00059                 this.ScrollThumb.onReleaseOutside = scrollThumbStopDrag;
00060                 //this.ScrollThumbMarks =  this.attachMovie("ScrollThumbMarksVert","ScrollThumbMarks",this.getNextHighestDepth());
00061                 
00062         }
00063         
00064         public function setFieldName(p_fieldName:String):Void {
00065                 this.fieldName = p_fieldName;
00066                 this.ScrollBtnUp.fieldName = this.fieldName;
00067                 this.ScrollBtnDown.fieldName = this.fieldName;
00068         }
00069         
00070         public function setStyle(textStyleNode:XMLNode){
00071                 
00072                 var txtFont:String = textStyleNode.attributes.fontFamily;
00073                 var txtColor:String = "#"+textStyleNode.attributes.color;
00074                 var txtLinkColor:String = "#"+textStyleNode.attributes.linkColor;
00075                 var txtSize:String = textStyleNode.attributes.size;
00076                 var txtAlign:String = textStyleNode.attributes.align;
00077                 
00078                 if(txtFont == "Myriad Web Pro")
00079                         this.txtField.embedFonts = true;
00080                 else
00081                         this.txtField.embedFonts = false;
00082                 
00083                 this.txtFieldStyle = new TextField.StyleSheet();
00084                 this.txtFieldStyle.setStyle("description", {
00085                         fontFamily:txtFont,
00086                         color:txtColor,
00087                         fontSize:txtSize, 
00088                         textAlign:"left"
00089                 });
00090                 this.txtFieldStyle.setStyle("groupDescription", {
00091                         fontFamily:txtFont,
00092                         color:txtColor,
00093                         fontSize:txtSize, 
00094                         textAlign:"left"
00095                 });
00096                 this.txtFieldStyle.setStyle("a:link", {
00097                         color:txtLinkColor
00098                 });
00099                 this.txtFieldStyle.setStyle("a:hover", {
00100                         textDecoration:'underline'
00101                 });
00102                 
00103                 this.txtField.styleSheet = txtFieldStyle;
00104                 
00105         }
00106         
00107         public function scrollTextUp(){
00108                 this.txtField.scroll--;
00109                 var scrollPercentage:Number = (this.txtField.scroll-1)/this.txtField.maxscroll;
00110                 this.ScrollThumb._y =(scrollPercentage*this._iScrollDistance)+this.ScrollLine._y;
00111                 //this.ScrollThumbMarks._y = this.ScrollThumb._y + (this.ScrollThumb._height/2);
00112         }
00113         
00114         public function scrollTextDown(){
00115                 this.txtField.scroll++;
00116                 var scrollPercentage:Number = (this.txtField.scroll)/this.txtField.maxscroll;
00117                 this.ScrollThumb._y =(scrollPercentage*this._iScrollDistance)+this.ScrollLine._y;
00118                 //this.ScrollThumbMarks._y = this.ScrollThumb._y + (this.ScrollThumb._height/2);
00119                 
00120         }
00121 
00122         
00123         public function scrollTextOffset(offset:Number){
00124                 this.txtField.scroll = offset;
00125         }
00126         
00127         public function scrollThumbDrag(){
00128                 this.onEnterFrame = this._parent.checkScrollPos;
00129                 this._parent._bScrollUsed = true;
00130                 startDrag(this,false,this._x,this._parent.ScrollLine._y,this._x,this._parent._iScrollDistance+this._parent.ScrollLine._y);
00131         }
00132         
00133         public function scrollThumbStopDrag(){
00134                 this.onEnterFrame = null;
00135                 stopDrag();
00136                 //this.ScrollThumbMarks._y = this.ScrollThumb._y + (this.ScrollThumb._height/2);
00137         }
00138         
00139         private function checkScrollPos(){
00140                 var scrollPercentage:Number = (this._y - this._parent.ScrollLine._y)/this._parent._iScrollDistance;
00141                 var scrollOffset:Number = Math.floor(scrollPercentage*this._parent.txtField.maxscroll);
00142                 this._parent.scrollTextOffset(scrollOffset+1);
00143                 //this._parent.ScrollThumbMarks._y = this._parent.ScrollThumb._y + (this._parent.ScrollThumb._height/2);
00144         }
00145         
00146         public function setHeightWidth(h:Number, w:Number):Void {
00147                 this._iControlWidth = w;
00148                 this._iControlHeight = h;
00149                 
00150                 //this.ScrollingFieldBg.drawRectangle(w,h,7);
00151                 //this.ScrollingFieldBg._x = 0;
00152                 //this.ScrollingFieldBg._y = 0;
00153                 
00154                 //position text field within area
00155                 this.txtField._x = this._iScrollFieldMargin;
00156                 this.txtField._y = this._iScrollFieldMargin;
00157                 
00158                 //fit text to area
00159 
00160                 this.txtField._width = w-this.ScrollBtnUp._width-(3*this._iScrollFieldMargin);
00161                 this.txtField._height = h-(2*this._iScrollFieldMargin);
00162                 
00163                 //see if scroll bar is needed
00164                 if(this.txtField.textHeight > (this.txtField._height-5)){
00165                         
00166                         //position scroll buttons
00167                         this.ScrollBtnUp._x = this.ScrollBtnDown._x = w - this._iScrollFieldMargin - this.ScrollBtnUp._width;
00168                         this.ScrollBtnUp._y = this._iScrollFieldMargin;
00169                         this.ScrollBtnDown._y = this.txtField._y + this.txtField._height - this.ScrollBtnUp._height;
00170                         
00171                         //position, size scroll line
00172                         this.ScrollLine._height = this.txtField._height - (this.ScrollBtnUp._height*2) - 7;
00173                         this.ScrollLine._x = this.ScrollBtnUp._x + (this.ScrollBtnUp._width/2);
00174                         this.ScrollLine._y = this.ScrollBtnUp._y + this.ScrollBtnUp._height + 3;
00175                         
00176                         //set thumb height and position
00177                         if(this.ScrollLine._height/this.txtField.maxscroll > 25)
00178                                 this.ScrollThumb.setHeight(this.ScrollLine._height/this.txtField.maxscroll);
00179                         else
00180                                 this.ScrollThumb.setHeight(25);
00181                         
00182                         this._iScrollDistance = this.ScrollLine._height - this.ScrollThumb._height;
00183                         
00184                         //draw square behind scrollbar
00185                         this.ScrollBarBg.clear();
00186                         //thickness:Number, rgb:Number, alpha:Number, pixelHinting:Boolean, noScale:String, capsStyle:String, jointStyle:String, miterLimit:Number
00187                         this.ScrollBarBg.lineStyle(1, this._iScrollBarBorder, this._iScrollBarBorderAlpha, true, "none", "none", "miter", 1);
00188                         this.ScrollBarBg.beginFill(this._iScrollBarFill,this._iScrollBarFillAlpha);
00189                         this.ScrollBarBg.moveTo(this.ScrollLine._x - 6.8, this.ScrollLine._y - 2);
00190                         this.ScrollBarBg.lineTo(this.ScrollLine._x + 6.5, this.ScrollLine._y - 2);
00191                         this.ScrollBarBg.lineTo(this.ScrollLine._x + 6.5, this.ScrollLine._y + this.ScrollLine._height + 2);
00192                         this.ScrollBarBg.lineTo(this.ScrollLine._x - 6.8, this.ScrollLine._y + this.ScrollLine._height + 2);
00193                         this.ScrollBarBg.moveTo(this.ScrollLine._x - 6.8, this.ScrollLine._y - 2);
00194                         this.ScrollBarBg.endFill();
00195                         
00196                         if(!_bScrollUsed){
00197                                 this.ScrollThumb._y = this.ScrollLine._y;
00198                                 //this.ScrollThumbMarks._y = this.ScrollThumb._y + (this.ScrollThumb._height/2);
00199                         }
00200                         else {
00201                                 var scrollPercentage:Number = (this.txtField.scroll)/this.txtField.maxscroll;
00202                                 this.ScrollThumb._y =(scrollPercentage*this._iScrollDistance)+this.ScrollLine._y; 
00203                                 //this.ScrollThumbMarks._y = this.ScrollThumb._y + (this.ScrollThumb._height/2);
00204                         }
00205                         this.ScrollThumb._x = this.ScrollLine._x;
00206                         //this.ScrollThumbMarks._x = this.ScrollThumb._x + 1;
00207                         
00208                         
00209                         //make all scroll elements visible
00210                         this.ScrollBtnUp._visible = this.ScrollBtnDown._visible = this.ScrollThumb._visible = this.ScrollLine._visible = true;
00211                         
00212                 }
00213                 else{
00214                         this.ScrollBtnUp._visible = this.ScrollBtnDown._visible = this.ScrollThumb._visible  = this.ScrollLine._visible = false;
00215                         this.ScrollBarBg.clear();
00216                 }
00217                         
00218                 
00219 
00220                 
00221                 
00222                 //if(this.txtField.textHeight > this.txtField._height)
00223                         //trace("scroll bar");
00224                 
00225         }
00226 
00227 }

Copyright © 2006 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.