fl.containers
public class ScrollPane
继承ScrollPane Inheritance BaseScrollPane Inheritance UIComponent Inheritance Sprite Inheritance DisplayObjectContainer Inheritance InteractiveObject Inheritance DisplayObject Inheritance EventDispatcher Inheritance Object
实现 IFocusManagerComponent

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

ScrollPane 组件在一个可滚动区域中呈现显示对象和 JPEG、GIF 与 PNG 文件,以及 SWF 文件。 可以使用滚动窗格来限制这些媒体类型所占用的屏幕区域。 滚动窗格可以显示从本地磁盘或 Internet 加载的内容。 在创作过程中和运行时,您都可以使用 ActionScript 设置此内容。 如果滚动窗格的内容具有有效的 Tab 停靠位,则窗格获得焦点以后,那些标记将获得焦点。 离开内容中的最后一个 Tab 停靠位之后,焦点将移到下一个组件。 滚动窗格中的垂直和水平滚动条不会获得焦点。

注意:正在从不同的域或沙箱加载内容时,内容的属性可能会由于安全原因而无法访问。 有关域安全如何影响加载过程的详细信息,请参阅“Loader 类”。

查看示例

另请参见

Loader



公共 属性
 属性定义方
 InheritedaccessibilityProperties : AccessibilityProperties
此显示对象的当前辅助功能选项。
DisplayObject
 Inheritedalpha : Number
指示指定对象的 Alpha 透明度值。
DisplayObject
 InheritedblendMode : String
BlendMode 类中的一个值,用于指定要使用的混合模式。
DisplayObject
 InheritedbuttonMode : Boolean
指定此 sprite 的按钮模式。
Sprite
  bytesLoaded : Number
[read-only] 获取已加载的内容的字节数。
ScrollPane
  bytesTotal : Number
[read-only] 获取要加载的内容的字节数。
ScrollPane
 InheritedcacheAsBitmap : Boolean
如果设置为 true,则 Flash Player 将缓存显示对象的内部位图表示形式。
DisplayObject
 Inheritedconstructor : Object
对类对象或给定对象实例的构造函数的引用。
Object
  content : DisplayObject
[read-only] 获取对加载到滚动窗格中的内容的引用。
ScrollPane
 InheritedcontextMenu : ContextMenu
指定与此对象相关联的上下文菜单。
InteractiveObject
 InheriteddoubleClickEnabled : Boolean
指定此对象是否接收 doubleClick 事件。
InteractiveObject
 InheriteddropTarget : DisplayObject
[read-only] 指定拖动 sprite 时经过的显示对象,或放置 sprite 的显示对象。
Sprite
 Inheritedenabled : Boolean
获取或设置一个值,该值指示组件是否可以接受用户交互。
UIComponent
 Inheritedfilters : Array
包含当前与显示对象关联的每个滤镜对象的索引数组。
DisplayObject
 InheritedfocusEnabled : Boolean
获取或设置一个布尔值,该值指示组件是否可以在用户单击它后获得焦点。
UIComponent
 InheritedfocusManager : IFocusManager
获取或设置为此组件及其同级组件控制焦点的 FocusManager。
UIComponent
 InheritedfocusRect : Object
指定此对象是否显示焦点矩形。
InteractiveObject
 Inheritedgraphics : Graphics
[read-only] 指定属于此 sprite 的 Graphics 对象,在此 sprite 中可执行矢量绘画命令。
Sprite
 Inheritedheight : Number
获取或设置组件的高度,以像素为单位。
UIComponent
 InheritedhitArea : Sprite
指定一个 sprite 用作另一个 sprite 的点击区域。
Sprite
 InheritedhorizontalLineScrollSize : Number
获取或设置一个值,该值描述当单击滚动箭头时要在水平方向上滚动的内容量。
BaseScrollPane
 InheritedhorizontalPageScrollSize : Number
获取或设置按滚动条轨道时水平滚动条上滚动滑块要移动的像素数。
BaseScrollPane
 InheritedhorizontalScrollBar : ScrollBar
[read-only] 获取对水平滚动条的引用。
BaseScrollPane
 InheritedhorizontalScrollPolicy : String
获取或设置一个值,该值指示水平滚动条的状态。
BaseScrollPane
 InheritedhorizontalScrollPosition : Number
获取或设置一个值,该值描述滚动窗格中水平滚动条的水平位置(以像素为单位)。
BaseScrollPane
 InheritedloaderInfo : LoaderInfo
[read-only] 返回一个 LoaderInfo 对象,其中包含加载此显示对象所属的文件的相关信息。
DisplayObject
 Inheritedmask : DisplayObject
调用显示对象被指定的 mask 对象遮罩。
DisplayObject
 InheritedmaxHorizontalScrollPosition : Number
[read-only] 获取当前内容的最大水平滚动位置(以像素为单位)。
BaseScrollPane
 InheritedmaxVerticalScrollPosition : Number
[read-only] 获取当前内容的最大垂直滚动位置(以像素为单位)。
BaseScrollPane
 InheritedmouseChildren : Boolean
确定对象的子项是否支持鼠标。
DisplayObjectContainer
 InheritedmouseEnabled : Boolean
指定此对象是否接收鼠标消息。
InteractiveObject
 InheritedmouseFocusEnabled : Boolean
获取或设置一个值,该值指示组件是否可以在用户单击它后获得焦点。
UIComponent
 InheritedmouseX : Number
[read-only] 指示鼠标位置的 x 坐标,以像素为单位。
DisplayObject
 InheritedmouseY : Number
[read-only] 指示鼠标位置的 y 坐标,以像素为单位。
DisplayObject
 Inheritedname : String
指示 DisplayObject 的实例名称。
DisplayObject
 InheritednumChildren : int
[read-only] 返回此对象的子项数目。
DisplayObjectContainer
 InheritedopaqueBackground : Object
指定显示对象是否由于具有某种背景颜色而不透明。
DisplayObject
 Inheritedparent : DisplayObjectContainer
[read-only] 指示包含此显示对象的 DisplayObjectContainer 对象。
DisplayObject
  percentLoaded : Number
[read-only] 获取一个范围在 0 到 100 之间的数字,指示已加载内容的百分比。
ScrollPane
 Inheritedprototype : Object
[static] 对类或函数对象的原型对象的引用。
Object
 Inheritedroot : DisplayObject
[read-only] 对于加载的 SWF 文件中的显示对象,root 属性是此 SWF 文件所表示的显示列表树结构部分中的顶级显示对象。
DisplayObject
 Inheritedrotation : Number
指示 DisplayObject 实例距其原始方向的旋转程度,以度为单位。
DisplayObject
 Inheritedscale9Grid : Rectangle
当前有效的缩放网格。
DisplayObject
 InheritedscaleX : Number
将组件的当前宽度与缩放系数相乘。
UIComponent
 InheritedscaleY : Number
将组件的当前高度与缩放系数相乘。
UIComponent
  scrollDrag : Boolean
获取或设置一个值,该值指示当用户在滚动窗格中拖动内容时是否发生滚动。
ScrollPane
 InheritedscrollRect : Rectangle
显示对象的滚动矩形范围。
DisplayObject
 InheritedsoundTransform : SoundTransform
控制此 sprite 中的声音。
Sprite
  source : Object
获取或设置以下内容:绝对或相对 URL(该 URL 标识要加载的 SWF 或图像文件的位置)、库中影片剪辑的类名称、对显示对象的引用或者与组件位于同一层上的影片剪辑的实例名称。
ScrollPane
 Inheritedstage : Stage
[read-only] 显示对象的舞台。
DisplayObject
 InheritedtabChildren : Boolean
确定对象的子项是否支持 Tab 键。
DisplayObjectContainer
 InheritedtabEnabled : Boolean
指定此对象是否遵循 Tab 键顺序。
InteractiveObject
 InheritedtabIndex : int
指定 SWF 文件中的对象按 Tab 键顺序排列。
InteractiveObject
 InheritedtextSnapshot : TextSnapshot
[read-only] 返回此 DisplayObjectContainer 实例的 TextSnapshot 对象。
DisplayObjectContainer
 Inheritedtransform : Transform
一个对象,具有与显示对象的矩阵、颜色转换和像素范围有关的属性。
DisplayObject
 InheriteduseBitmapScrolling : Boolean
设置为 true 时,滚动内容的 cacheAsBitmap 属性设置为 true;设置为 false 时,该值会关闭。
BaseScrollPane
 InheriteduseHandCursor : Boolean
布尔值,指示当鼠标滑过其 buttonMode 属性设置为 true 的 sprite 时是否显示手指形(手形光标)。
Sprite
 Inheritedversion : String = "3.0.0.13"
组件的版本号。
UIComponent
 InheritedverticalLineScrollSize : Number
获取或设置一个值,该值描述当单击滚动箭头时要在垂直方向上滚动多少像素。
BaseScrollPane
 InheritedverticalPageScrollSize : Number
获取或设置按滚动条轨道时垂直滚动条上滚动滑块要移动的像素数。
BaseScrollPane
 InheritedverticalScrollBar : ScrollBar
[read-only] 获取对垂直滚动条的引用。
BaseScrollPane
 InheritedverticalScrollPolicy : String
获取或设置一个值,该值指示垂直滚动条的状态。
BaseScrollPane
 InheritedverticalScrollPosition : Number
获取或设置一个值,该值描述滚动窗格中垂直滚动条的垂直位置(以像素为单位)。
BaseScrollPane
 Inheritedvisible : Boolean
获取或设置一个值,该值指示当前组件实例是否可见。
UIComponent
 Inheritedwidth : Number
获取或设置组件的宽度(以像素为单位)。
UIComponent
 Inheritedx : Number
获取或设置 x 坐标,该坐标表示组件在其父容器内沿 x 轴的位置。
UIComponent
 Inheritedy : Number
获取或设置 y 坐标,该坐标表示组件在其父容器内沿 y 轴的位置。
UIComponent
公共 方法
 方法定义方
  
创建新的 ScrollPane 组件实例。
ScrollPane
 Inherited
将一个 DisplayObject 子实例添加到该 DisplayObjectContainer 实例中。
DisplayObjectContainer
 Inherited
将一个 DisplayObject 子实例添加到该 DisplayObjectContainer 实例中。
DisplayObjectContainer
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。
EventDispatcher
 Inherited
指示安全限制是否会导致出现以下情况:在列表中忽略了使用指定 point 点调用 DisplayObjectContainer.getObjectsUnderPoint() 方法时返回的所有显示对象。
DisplayObjectContainer
 Inherited
删除此组件实例中的样式属性。
UIComponent
 Inherited
确定指定显示对象是 DisplayObjectContainer 实例的子项还是该实例本身。
DisplayObjectContainer
 Inherited
将事件调度到事件流中。
EventDispatcher
 Inherited
在此组件上显示或隐藏焦点指示符。
UIComponent
 Inherited
启动立即绘制操作,但不像 invalidateNow 那样使全部设置失效。
UIComponent
 Inherited
getBounds(targetCoordinateSpace:DisplayObject):Rectangle
返回一个矩形,该矩形定义相对于 targetCoordinateSpace 对象坐标系的显示对象区域。
DisplayObject
 Inherited
返回位于指定索引处的子显示对象实例。
DisplayObjectContainer
 Inherited
返回具有指定名称的子显示对象。
DisplayObjectContainer
 Inherited
返回 DisplayObject 的 child 实例的索引位置。
DisplayObjectContainer
 Inherited
检索当前具有焦点的对象。
UIComponent
 Inherited
返回对象的数组,这些对象位于指定点下,并且是该 DisplayObjectContainer 实例的子项(或孙子项,依此类推)。
DisplayObjectContainer
 Inherited
getRect(targetCoordinateSpace:DisplayObject):Rectangle
返回一个矩形,该矩形根据 targetCoordinateSpace 参数定义的坐标系定义显示对象的边界,但不包括形状上的任何笔触。
DisplayObject
 Inherited
检索组件的样式查找链中设置的样式属性。
UIComponent
  
[static] 检索当前组件的默认样式映射。
ScrollPane
 Inherited
将 point 对象从舞台(全局)坐标转换为显示对象的(本地)坐标。
DisplayObject
 Inherited
检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
EventDispatcher
 Inherited
指示对象是否已经定义了指定的属性。
Object
 Inherited
计算显示对象,以确定它是否与 obj 显示对象重叠或相交。
DisplayObject
 Inherited
hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false):Boolean
计算显示对象,以确定它是否与 x 和 y 参数指定的点重叠或相交。
DisplayObject
 Inherited
invalidate(property:String, callLater:Boolean = true):void
在未另外指定的情况下,将属性标记为无效,并在下一帧上重绘组件。
UIComponent
 Inherited
指示 Object 类的实例是否在指定为参数的对象的原型链中。
Object
  
load(request:URLRequest, context:LoaderContext = null):void
该方法的 request 参数只接受其 source 属性包含字符串、类或 URLRequest 对象的 URLRequest 对象。
ScrollPane
 Inherited
将 point 对象从显示对象的(本地)坐标转换为舞台(全局)坐标。
DisplayObject
 Inherited
[static] 将多个类的样式合并到一个对象中。
UIComponent
 Inherited
将组件移动到其父项内的指定位置。
UIComponent
 Inherited
指示指定的属性是否存在、是否可枚举。
Object
  
重新加载滚动窗格的内容。
ScrollPane
 Inherited
从 DisplayObjectContainer 实例的子列表中删除指定的 child DisplayObject 实例。
DisplayObjectContainer
 Inherited
从 DisplayObjectContainer 的子列表中指定的 index 位置删除子 DisplayObject。
DisplayObjectContainer
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
从 EventDispatcher 对象中删除侦听器。
EventDispatcher
 Inherited
更改现有子项在显示对象容器中的位置。
DisplayObjectContainer
 Inherited
设置此组件的焦点。
UIComponent
 Inherited
设置循环操作动态属性的可用性。
Object
 Inherited
setSize(width:Number, height:Number):void
将组件设置为指定宽度和高度。
UIComponent
 Inherited
setStyle(style:String, value:Object):void
对此组件实例设置样式属性。
UIComponent
 Inherited
startDrag(lockCenter:Boolean = false, bounds:Rectangle = null):void
允许用户拖动指定的 Sprite。
Sprite
 Inherited
结束 startDrag() 方法。
Sprite
 Inherited
交换两个指定子对象的 Z 轴顺序(从前到后顺序)。
DisplayObjectContainer
 Inherited
swapChildrenAt(index1:int, index2:int):void
在子级列表中两个指定的索引位置,交换子对象的 Z 轴顺序(前后顺序)。
DisplayObjectContainer
 Inherited
返回指定对象的字符串表示形式。
Object
  
根据内容的宽度和高度刷新滚动条属性。
ScrollPane
 Inherited
验证并更新此对象的属性和布局,如果需要的话重绘对象。
UIComponent
 Inherited
返回指定对象的原始值。
Object
 Inherited
检查是否用此 EventDispatcher 对象或其任何始祖为指定事件类型注册了事件侦听器。
EventDispatcher
事件
 事件摘要定义方
 Inherited Flash Player 获得操作系统焦点并变为活动状态时调度。EventDispatcher
 Inherited 将显示对象添加到显示列表中时调度。DisplayObject
 Inherited 在将显示对象直接添加到舞台显示列表或将包含显示对象的子树添加至舞台显示列表中时调度。DisplayObject
 Inherited 用户在同一 InteractiveObject 上按下并释放用户指针设备的主按钮时调度。InteractiveObject
   完成内容加载时调度。ScrollPane
 Inherited Flash Player 失去操作系统焦点并变为非活动状态时调度。EventDispatcher
 Inherited 如果 InteractiveObject 的 doubleClickEnabled 标志设置为 true,当用户在该对象上快速连续按下两次并释放指针设备的主按钮时调度。InteractiveObject
 Inherited 播放头进入新帧时调度。DisplayObject
 Inherited 显示对象获得焦点后调度。InteractiveObject
 Inherited 显示对象失去焦点后调度。InteractiveObject
 Inherited 在组件可见性从可见改为不可见以后调度。UIComponent
 Inherited 用户按下某个键时调度。InteractiveObject
 Inherited 用户尝试使用键盘导航更改焦点时调度。InteractiveObject
 Inherited 用户释放某个键时调度。InteractiveObject
 Inherited 在 Flash Player 窗口中,用户在 InteractiveObject 实例上按下指针设备按钮时调度。InteractiveObject
 Inherited 用户尝试使用指针设备更改焦点时调度。InteractiveObject
 Inherited 用户移动 InteractiveObject 上的指针设备时调度。InteractiveObject
 Inherited 用户将指针设备从 InteractiveObject 实例上移开时调度。InteractiveObject
 Inherited 在 Flash Player 窗口中,用户将指针设备移动到 InteractiveObject 实例上时调度。InteractiveObject
 Inherited 在 Flash Player 窗口中,用户在 InteractiveObject 实例上释放指针设备按钮时调度。InteractiveObject
 Inherited 在 Flash Player 窗口中,鼠标滚轮滚动到 InteractiveObject 实例上时调度。InteractiveObject
 Inherited 在移动组件以后调度。UIComponent
   当加载内容时调度。ScrollPane
 Inherited 将要从显示列表中删除显示对象时调度。DisplayObject
 Inherited 在从显示列表中直接删除显示对象或删除包含显示对象的子树时调度。DisplayObject
 Inherited 将要更新和呈现显示列表时调度。DisplayObject
 Inherited 在调整组件大小以后调度。UIComponent
 Inherited 用户将指针设备从 InteractiveObject 实例上移开时调度。InteractiveObject
 Inherited 用户将指针设备移动到 InteractiveObject 实例上时调度。InteractiveObject
   当用户通过使用组件上的滚动条或鼠标设备上的滚轮滚动内容时调度。ScrollPane
 Inherited 在组件可见性从不可见改为可见以后调度。UIComponent
 Inherited 对象的 tabChildren 标志值发生更改时调度。InteractiveObject
 Inherited 对象的 tabEnabled 标志发生更改时调度。InteractiveObject
 Inherited 对象的 tabIndex 属性值发生更改时调度。InteractiveObject
样式
 样式说明定义方
  
contentPadding
类型: Number   格式: Length
要放置在滚动窗格中内容周围的填充量(以像素为单位)。 默认值为 0.
ScrollPane
 Inherited 类型: Number   格式: Length
当 enabled 属性设置为 false 时,禁止与组件进行交互,且组件上面显示一个白色叠加层,使组件内容变暗。 disabledAlpha 样式指定应用于该叠加层的透明度级别。 有效值的范围为 0(表示叠加层完全透明)到 1(表示叠加层不透明)。 默认值为 0.5.
BaseScrollPane
  
disabledSkin
类型: Class
禁用滚动窗格时显示的外观。 默认值为 ScrollPane_disabledSkin.
ScrollPane
 Inherited 类型: flash.text.TextFormat
用于在禁用了按钮的情况下呈现组件标签的 TextFormat 对象。 默认值为 TextFormat("_sans", 11, 0x999999, false, false, false, '', '', TextFormatAlign.LEFT, 0, 0, 0, 0).
UIComponent
 Inherited 类型: Class
类的名称,该类用作当禁用了滚动条时滚动条的向下箭头按钮的外观。 如果以图形化方式或编程方式更改该外观,您应当确保新外观与轨道具有相同的高度(对于水平滚动条)或高度(对于垂直滚动条)。. 默认值为 ScrollArrowDown_disabledSkin.
BaseScrollPane
 Inherited 类型: Class
类的名称,该类用作当单击滚动条的向下箭头按钮时该按钮的外观。 如果以图形化方式或编程方式更改该外观,您应当确保新外观与轨道具有相同的高度(对于水平滚动条)或高度(对于垂直滚动条)。. 默认值为 ScrollArrowDown_downSkin.
BaseScrollPane
 Inherited 类型: Class
类的名称,该类用作当鼠标指针在滚动条的向下箭头按钮上方时该按钮的外观。 如果以图形化方式或编程方式更改该外观,您应当确保新外观与轨道具有相同的高度(对于水平滚动条)或高度(对于垂直滚动条)。. 默认值为 ScrollArrowDown_overSkin.
BaseScrollPane
 Inherited 类型: Class
类的名称,该类用作滚动条的向下箭头按钮的外观。 如果以图形化方式或编程方式更改该外观,您应当确保新外观与轨道具有相同的高度(对于水平滚动条)或高度(对于垂直滚动条)。. 默认值为 ScrollArrowDown_upSkin.
BaseScrollPane
 Inherited 类型: Number   格式: Length
用于分隔组件的外边框和焦点指示符的外边框的填充(以像素为单位)。 默认值为 2.
UIComponent
 Inherited 类型: Class
用于显示焦点指示符的外观。 默认值为 focusRectSkin.
UIComponent
 Inherited 类型: Number   格式: Time
在第一次调度 buttonDown 事件之后、发送第二个 buttonDown 事件之前等待的毫秒数。. 默认值为 500.
BaseScrollPane
 Inherited 类型: Number   格式: Time
在由 repeatDelay 样式指定的延迟之后调度的 buttonDown 事件之间的间隔(以毫秒为单位)。. 默认值为 35.
BaseScrollPane
 Inherited 类型: Class
用作滚动窗格背景的外观。 默认值为 ScrollPane_upSkin.
BaseScrollPane
 Inherited 类型: flash.text.TextFormat
用于呈现组件标签的 TextFormat 对象。 默认值为 TextFormat("_sans", 11, 0x000000, false, false, false, '', '', TextFormatAlign.LEFT, 0, 0, 0, 0).
UIComponent
 Inherited 类型: Class
用于指示缩略图的禁用状态的外观。. 默认值为 ScrollThumb_upSkin.
BaseScrollPane
 Inherited 类型: Class
类的名称,该类用作当单击滚动条的缩略图时该缩略图的外观。. 默认值为 ScrollThumb_downSkin.
BaseScrollPane
 Inherited 类型: Class
类的名称,该类用作滚动条的缩略图的图标。. 默认值为 ScrollBar_thumbIcon.
BaseScrollPane
 Inherited 类型: Class
类的名称,该类用作当鼠标指针在滚动条的缩略图上方时该缩略图的外观。. 默认值为 ScrollThumb_overSkin.
BaseScrollPane
 Inherited 类型: Class
类的名称,该类用作滚动条的缩略图的外观。. 默认值为 ScrollThumb_upSkin.
BaseScrollPane
 Inherited 类型: Class
用于指示被禁用轨道的外观。. 默认值为 ScrollTrack_Skin.
BaseScrollPane
 Inherited 类型: Class
用于指示被禁用外观的按下状态的外观。. 默认值为 ScrollTrack_Skin.
BaseScrollPane
 Inherited 类型: Class
用于指示滚动轨道的鼠标悬停状态的外观。. 默认值为 ScrollTrack_Skin.
BaseScrollPane
 Inherited 类型: Class
用于指示滚动轨道的鼠标松开状态的外观。. 默认值为 ScrollTrack_Skin.
BaseScrollPane
 Inherited 类型: Class
类的名称,该类用作当禁用了滚动条时滚动条的向上箭头按钮的外观。 如果以图形化方式或编程方式更改该外观,您应当确保新外观与轨道具有相同的高度(对于水平滚动条)或高度(对于垂直滚动条)。. 默认值为 ScrollArrowUp_disabledSkin.
BaseScrollPane
 Inherited 类型: Class
类的名称,该类用作当单击滚动条的向上箭头按钮时该按钮的外观。 如果以图形化方式或编程方式更改该外观,您应当确保新外观与轨道具有相同的高度(对于水平滚动条)或高度(对于垂直滚动条)。. 默认值为 ScrollArrowUp_downSkin.
BaseScrollPane
 Inherited 类型: Class
类的名称,该类用作当鼠标指针在滚动条的向上箭头按钮上方时该按钮的外观。 如果以图形化方式或编程方式更改该外观,您应当确保新外观与轨道具有相同的高度(对于水平滚动条)或高度(对于垂直滚动条)。. 默认值为 ScrollArrowUp_overSkin.
BaseScrollPane
 Inherited 类型: Class
类的名称,该类用作滚动条的向上箭头按钮的外观。 如果以图形化方式或编程方式更改该外观,您应当确保新外观与轨道具有相同的高度(对于水平滚动条)或高度(对于垂直滚动条)。. 默认值为 ScrollArrowUp_upSkin.
BaseScrollPane
  
upSkin
类型: Class
滚动窗格上显示的默认外观。 默认值为 ScrollPane_upSkin.
ScrollPane
属性详细信息
bytesLoaded属性
bytesLoaded:Number  [read-only]

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

获取已加载的内容的字节数。 如果此属性与 bytesTotal 的值相等,说明已加载所有字节。

默认值为 0.


实现
    public function get bytesLoaded():Number

另请参见


示例
如何使用示例

下面的示例创建一个滚动窗格并将“test.jpg”加载到其中。 在进行加载时,“输出”面板显示已加载的字节数和总字节数,而进度栏则提供可视表示形式。 将“test.jpg”替换为一个图像,并将 ScrollPane 和 ProgressBar 都放在 FLA 文件的库中:

import fl.containers.ScrollPane;
import fl.controls.ProgressBar;

var path:String = "test.jpg";

var sp:ScrollPane = new ScrollPane();
sp.move(10,10);
sp.setSize(530,300);
sp.addEventListener(ProgressEvent.PROGRESS,reportProgress);
sp.load(new URLRequest(path));
addChild(sp);

var progressBar:ProgressBar = new ProgressBar();
progressBar.move(10,320);
progressBar.setSize(530,50);
progressBar.source = sp;
addChild(progressBar);

function reportProgress(e:ProgressEvent):void {
    trace(e.bytesLoaded + " loaded out of " + e.bytesTotal);
}
bytesTotal属性 
bytesTotal:Number  [read-only]

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

获取要加载的内容的字节数。

默认值为 0.


实现
    public function get bytesTotal():Number

另请参见


示例
如何使用示例

下面的示例将一个外部图像加载到 ScrollPane 实例中,并通过侦听 progresscomplete 事件显示 bytesLoadedbytesTotalpercentLoaded 属性:

import fl.containers.ScrollPane;

var url:String = "http://www.helpexamples.com/flash/images/image1.jpg";

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.setSize(320, 240);
myScrollPane.move(10, 10);
myScrollPane.addEventListener(ProgressEvent.PROGRESS, progressHandler);
myScrollPane.addEventListener(Event.COMPLETE, completeHandler);
myScrollPane.load(new URLRequest(url));
addChild(myScrollPane);

function progressHandler(event:ProgressEvent):void {
    var bLoaded:int = event.bytesLoaded;
    var bTotal:int = event.bytesTotal;
    var pctLoaded:int = int(event.currentTarget.percentLoaded);
    trace("progress: " + bLoaded + " of " + bTotal + " bytes loaded (" + pctLoaded + "%)");
}

function completeHandler(event:Event):void {
    trace("complete:");
}
content属性 
content:DisplayObject  [read-only]

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

获取对加载到滚动窗格中的内容的引用。

默认值为 null.


实现
    public function get content():DisplayObject

示例
如何使用示例

下面的示例演示如何修改滚动窗格的内容的透明度:

import fl.containers.ScrollPane;
import fl.controls.NumericStepper;

var ns:NumericStepper = new NumericStepper();
ns.minimum = 10;
ns.maximum = 100;
ns.stepSize = 10;
ns.value = ns.maximum;
ns.addEventListener(Event.CHANGE, updateScrollPaneContentAlpha);
addChild(ns);

var sp:ScrollPane = new ScrollPane();
sp.move(0,30);
sp.setSize(180, 160);
sp.source = "http://www.helpexamples.com/flash/images/image2.jpg";
addChild(sp);

function updateScrollPaneContentAlpha(e:Event):void {
    sp.content.alpha = e.target.value / 100;
}

下面的示例使用两个 Button 组件实例控制图像在 ScrollPane 组件中显示的缩放程度:

import fl.containers.ScrollPane;
import fl.controls.Button;
import fl.events.ComponentEvent;

var MAX_SCROLLPANE_WIDTH:uint = 400;
var MAX_SCROLLPANE_HEIGHT:uint = 267;

var url:String = "http://www.helpexamples.com/flash/images/image1.jpg";

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.scrollDrag = true;
myScrollPane.cacheAsBitmap = true;
myScrollPane.setSize(MAX_SCROLLPANE_WIDTH, MAX_SCROLLPANE_HEIGHT);
myScrollPane.move(10, 10);
myScrollPane.addEventListener(Event.COMPLETE, completeHandler);
myScrollPane.load(new URLRequest(url));
addChild(myScrollPane);

var zoomInButton:Button = new Button();
zoomInButton.autoRepeat = true;
zoomInButton.enabled = false;
zoomInButton.label = "Zoom in (+)";
zoomInButton.move(420, 10);
zoomInButton.addEventListener(ComponentEvent.BUTTON_DOWN, zoomInHandler);
addChild(zoomInButton);

var zoomOutButton:Button = new Button();
zoomOutButton.autoRepeat = true;
zoomOutButton.enabled = false;
zoomOutButton.label = "Zoom out (-)";
zoomOutButton.move(420, 40);
zoomOutButton.addEventListener(ComponentEvent.BUTTON_DOWN, zoomOutHandler);
addChild(zoomOutButton);

var cacheButton:Button = new Button();
cacheButton.enabled = false;
cacheButton.emphasized = myScrollPane.cacheAsBitmap;
cacheButton.label = "cacheAsBitmap";
cacheButton.toggle = true;
cacheButton.selected = myScrollPane.cacheAsBitmap;
cacheButton.move(420, 70);
cacheButton.addEventListener(Event.CHANGE, changeHandler);
addChild(cacheButton);

function completeHandler(event:Event):void {
    zoomInButton.enabled = true;
    zoomOutButton.enabled = true;
    cacheButton.enabled = true;
    myScrollPane.removeEventListener(Event.COMPLETE, completeHandler);
}

function changeHandler(event:Event):void {
    myScrollPane.cacheAsBitmap = !myScrollPane.cacheAsBitmap;
    cacheButton.emphasized = myScrollPane.cacheAsBitmap;
}

function zoomInHandler(event:ComponentEvent):void {
    var zoomLvl:Number = myScrollPane.content.scaleX * 1.1;
    updateSP(zoomLvl);
}

function zoomOutHandler(event:ComponentEvent):void {
    var zoomLvl:Number = myScrollPane.content.scaleX / 1.1;
    updateSP(zoomLvl);
}

function updateSP(newScale:Number):void {
    var img:DisplayObject = myScrollPane.content as DisplayObject;
    img.scaleY = newScale;
    img.scaleX = newScale;
    myScrollPane.width = Math.min(img.width, MAX_SCROLLPANE_WIDTH);
    myScrollPane.height = Math.min(img.height, MAX_SCROLLPANE_HEIGHT);
    myScrollPane.update();
}
percentLoaded属性 
percentLoaded:Number  [read-only]

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

获取一个范围在 0 到 100 之间的数字,指示已加载内容的百分比。 如果从库(而不是外部加载的内容)加载资源,则 percentLoaded 属性设置为 0。

默认值为 0.


实现
    public function get percentLoaded():Number

另请参见


示例
如何使用示例

下面的示例将一个外部图像加载到 ScrollPane 实例中,并通过侦听 progresscomplete 事件显示 bytesLoadedbytesTotalpercentLoaded 属性:

import fl.containers.ScrollPane;

var url:String = "http://www.helpexamples.com/flash/images/image1.jpg";

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.setSize(320, 240);
myScrollPane.move(10, 10);
myScrollPane.addEventListener(ProgressEvent.PROGRESS, progressHandler);
myScrollPane.addEventListener(Event.COMPLETE, completeHandler);
myScrollPane.load(new URLRequest(url));
addChild(myScrollPane);

function progressHandler(event:ProgressEvent):void {
    var bLoaded:int = event.bytesLoaded;
    var bTotal:int = event.bytesTotal;
    var pctLoaded:int = int(event.currentTarget.percentLoaded);
    trace("progress: " + bLoaded + " of " + bTotal + " bytes loaded (" + pctLoaded + "%)");
}

function completeHandler(event:Event):void {
    trace("complete:");
}
scrollDrag属性 
scrollDrag:Boolean  [read-write]

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

获取或设置一个值,该值指示当用户在滚动窗格中拖动内容时是否发生滚动。 true 值指示当用户拖动内容时发生滚动;false 值指示不发生滚动。

默认值为 false.


实现
    public function get scrollDrag():Boolean
    public function set scrollDrag(value:Boolean):void

另请参见


示例
如何使用示例

下面的示例创建一个 ScrollPane 实例,并在滚动内容时跟踪组件的水平和垂直滚动位置:

import fl.containers.ScrollPane;
import fl.events.ScrollEvent;

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.scrollDrag = true;
myScrollPane.source = "http://www.helpexamples.com/flash/images/image2.jpg";
myScrollPane.addEventListener(ScrollEvent.SCROLL, scrollHandler);
myScrollPane.move(10, 10);
addChild(myScrollPane);

function scrollHandler(event:ScrollEvent):void {
    var mySP:ScrollPane = event.currentTarget as ScrollPane;
    trace("scrolling");
    trace("\t" + "direction:", event.direction);
    trace("\t" + "position:", event.position);
    trace("\t" + "horizontalScrollPosition:", mySP.horizontalScrollPosition, "of", mySP.maxHorizontalScrollPosition);
    trace("\t" + "verticalScrollPosition:", mySP.verticalScrollPosition, "of", mySP.maxVerticalScrollPosition);
}
source属性 
source:Object  [read-write]

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

获取或设置以下内容:绝对或相对 URL(该 URL 标识要加载的 SWF 或图像文件的位置)、库中影片剪辑的类名称、对显示对象的引用或者与组件位于同一层上的影片剪辑的实例名称。

有效的图像文件格式包括 GIF、PNG 和 JPEG。 若要通过使用 URLRequest 对象加载资源,请使用 load() 方法。

默认值为 null.


实现
    public function get source():Object
    public function set source(value:Object):void

另请参见


示例
如何使用示例

下面的示例使用 source 属性将一个外部图像加载到 ScrollPane 组件中:

import fl.containers.ScrollPane;

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.source = "http://www.helpexamples.com/flash/images/image1.jpg";
myScrollPane.setSize(320, 240);
myScrollPane.move(10, 10);
addChild(myScrollPane);

下面的示例使用 source 属性将库中的一个影片剪辑元件加载到 ScrollPane 组件中:

import fl.containers.ScrollPane;

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.source = Box;
myScrollPane.setSize(320, 240);
myScrollPane.move(10, 10);
addChild(myScrollPane);
构造函数详细信息
ScrollPane()构造函数
public function ScrollPane()

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

创建新的 ScrollPane 组件实例。

方法详细信息
getStyleDefinition()方法
public static function getStyleDefinition():Object

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

检索当前组件的默认样式映射。 样式映射包含适合组件的类型,具体取决于组件使用的样式。 例如,disabledTextFormat 样式包含 null 值或 TextFormat 对象。 可以使用这些样式并对当前组件调用 setStyle()。 下面的代码覆盖指定组件上默认的 disabledTextFormat 样式:
componentInstance.setStyle("disabledTextFormat", new TextFormat());

返回
Object — 默认样式对象。

另请参见


示例
如何使用示例

下例为多个组件类创建一个样式浏览器:
import fl.controls.*;
import fl.containers.*;
import fl.controls.listClasses.*;
import fl.controls.dataGridClasses.*;
import fl.controls.progressBarClasses.*;
import fl.core.UIComponent;
import fl.data.DataProvider;

var dp:DataProvider = new DataProvider();
dp.addItem( { label: "BaseScrollPane",    data:BaseScrollPane } );
dp.addItem( { label: "Button",             data:Button } );
dp.addItem( { label: "CellRenderer",    data:CellRenderer } );
dp.addItem( { label: "CheckBox",         data:CheckBox } );
dp.addItem( { label: "ColorPicker",     data:ColorPicker } );
dp.addItem( { label: "ComboBox",         data:ComboBox } );
dp.addItem( { label: "DataGrid",         data:DataGrid } );
dp.addItem( { label: "HeaderRenderer",    data:HeaderRenderer } );
dp.addItem( { label: "ImageCell",        data:ImageCell } );
dp.addItem( { label: "IndeterminateBar",data:IndeterminateBar } );
dp.addItem( { label: "Label",             data:Label } );
dp.addItem( { label: "List",             data:List } );
dp.addItem( { label: "NumericStepper",     data:NumericStepper } );
dp.addItem( { label: "ProgressBar",     data:ProgressBar } );
dp.addItem( { label: "RadioButton",     data:RadioButton } );
dp.addItem( { label: "ScrollPane",         data:ScrollPane } );
dp.addItem( { label: "Slider",             data:Slider } );
dp.addItem( { label: "TextArea",         data:TextArea } );
dp.addItem( { label: "TextInput",         data:TextInput } );
dp.addItem( { label: "TileList",         data:TileList } );
dp.addItem( { label: "UILoader",         data:UILoader } );
dp.addItem( { label: "UIComponent",     data:UIComponent } );

var cb:ComboBox = new ComboBox();
cb.move(10,10);
cb.setSize(300,25);
cb.prompt = "Select a component to view its styles";
cb.rowCount = 12;
cb.dataProvider = dp;
cb.addEventListener(Event.CHANGE, showStyleDefinition);
addChild(cb);

var dg:DataGrid = new DataGrid();
dg.setSize(425,300);
dg.move(10,50);
dg.columns = [ new DataGridColumn("StyleName"), new DataGridColumn("DefaultValue") ];
addChild(dg);

function showStyleDefinition(e:Event):void {
    var componentClass:Class = e.target.selectedItem.data as Class;
    var styles:Object = componentClass["getStyleDefinition"].call(this);
    trace(styles.toString());
    var styleData:DataProvider = new DataProvider();
    for(var i:* in styles) {
        trace(i + " : " + styles[i]);
        styleData.addItem( { StyleName:i, DefaultValue:styles[i] } );
    }
    styleData.sortOn("StyleName");
    dg.dataProvider = styleData;
}
load()方法 
public function load(request:URLRequest, context:LoaderContext = null):void

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

该方法的 request 参数只接受其 source 属性包含字符串、类或 URLRequest 对象的 URLRequest 对象。 默认情况下,LoaderContext 对象使用当前域作为应用程序域。 若要指定不同的应用程序域值、检查策略文件或更改安全域,请初始化新的 LoaderContext 对象并将其传递给该方法。

参数

request:URLRequest — 要用来将图像加载到滚动窗格中的 URLRequest 对象。
 
context:LoaderContext (default = null) — 设置加载操作上下文的 LoaderContext 对象。

另请参见


示例
如何使用示例

下面的示例将一个图像加载到滚动窗格中:
import fl.containers.ScrollPane;

var request:URLRequest = new URLRequest("http://www.helpexamples.com/flash/images/image1.jpg");
var sp:ScrollPane = new ScrollPane();
sp.setSize(180, 160);
sp.load(request);
addChild(sp);
refreshPane()方法 
public function refreshPane():void

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

重新加载滚动窗格的内容。

该方法不重绘滚动条。 若要重置滚动条,请使用 update() 方法。

另请参见


示例
如何使用示例

下面的示例将一个图像加载到 ScrollPane 组件实例中,并使用 refreshPane() 方法刷新窗格:

import fl.containers.ScrollPane;
import fl.controls.Button;
import fl.controls.TextArea;

var url:String = "http://www.helpexamples.com/flash/images/image2.jpg";

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.setSize(320, 240);
myScrollPane.move(10, 10);
myScrollPane.load(new URLRequest(url));
myScrollPane.addEventListener(ProgressEvent.PROGRESS, progressHandler);
myScrollPane.addEventListener(Event.COMPLETE, completeHandler);
addChild(myScrollPane);

var refreshButton:Button = new Button();
refreshButton.emphasized = true;
refreshButton.label = "refreshPane()";
refreshButton.move(myScrollPane.x + myScrollPane.width + 10, myScrollPane.y);
refreshButton.addEventListener(MouseEvent.CLICK, clickHandler);
addChild(refreshButton);

var myTextArea:TextArea = new TextArea();
myTextArea.editable = false;
myTextArea.setSize(320, 120);
myTextArea.move(myScrollPane.x, myScrollPane.y + myScrollPane.height + 10);
addChild(myTextArea);

function progressHandler(event:ProgressEvent):void {
    var bLoaded:int = event.bytesLoaded;
    var bTotal:int = event.bytesTotal;
    var pctLoaded:int = int(event.currentTarget.percentLoaded);
    addText("progress (" + bLoaded + " of " + bTotal + " bytes loaded -- " + pctLoaded + "%)");
}

function completeHandler(event:Event):void {
    addText("complete");
    addText("----------");
}

function clickHandler(event:MouseEvent):void {
    myScrollPane.refreshPane();
}

function addText(str:String):void {
    myTextArea.appendText(str + "\n");
    myTextArea.verticalScrollPosition = myTextArea.maxVerticalScrollPosition;
}
update()方法 
public function update():void

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

根据内容的宽度和高度刷新滚动条属性。 如果 ScrollPane 的内容在运行时会更改,这就会很有用。

另请参见


示例
如何使用示例

下面的示例创建一个 ScrollPane 组件实例,并根据用户单击的按钮加载不同的图像:

import fl.containers.ScrollPane;
import fl.controls.Button;

var baseURL:String = "http://www.helpexamples.com/flash/images/";

var img1Button:Button = new Button();
img1Button.label = "Image 1";
img1Button.move(10, 10);
img1Button.addEventListener(MouseEvent.CLICK, clickHandler);
addChild(img1Button);

var img2Button:Button = new Button();
img2Button.label = "Image 2";
img2Button.move(10, 40);
img2Button.addEventListener(MouseEvent.CLICK, clickHandler);
addChild(img2Button);

var img3Button:Button = new Button();
img3Button.label = "Image 3";
img3Button.move(10, 70);
img3Button.addEventListener(MouseEvent.CLICK, clickHandler);
addChild(img3Button);

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.setSize(320, 240);
myScrollPane.move(120, 10);
myScrollPane.addEventListener(Event.COMPLETE, completeHandler);
addChild(myScrollPane);

function clickHandler(event:MouseEvent):void {
    switch (event.currentTarget) {
        case img1Button:
            myScrollPane.source = baseURL + "image1.jpg";
            break;
        case img2Button:
            myScrollPane.source = baseURL + "image2.jpg";
            break;
        case img3Button:
            myScrollPane.source = baseURL + "image3.jpg";
            break;
    }
}

function completeHandler(event:Event):void {
    myScrollPane.update();
}
事件详细信息
complete 事件
事件对象类型: flash.events.Event
Event.type property = flash.events.Event.COMPLETE

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

完成内容加载时调度。

定义 complete 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target已完成加载的网络对象。

示例
如何使用示例

下面的示例创建一个 ScrollPane 组件实例,加载外部图像并侦听 progresscomplete 事件:

import fl.containers.ScrollPane;
import fl.controls.Label;

var url:String = "http://www.helpexamples.com/flash/images/image1.jpg";

var conversion:Number = 1024;

var myLabel:Label = new Label();
myLabel.autoSize = TextFieldAutoSize.LEFT;
myLabel.text = "";
myLabel.move(10, 10);
addChild(myLabel);

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.addEventListener(ProgressEvent.PROGRESS, progressHandler);
myScrollPane.addEventListener(Event.COMPLETE, completeHandler);
myScrollPane.load(new URLRequest(url));

function progressHandler(event:ProgressEvent):void {
    var bLoaded:int = int(event.bytesLoaded / conversion);
    var bTotal:int = int(event.bytesTotal / conversion);
    var pctLoaded:int = event.target.percentLoaded as int;
    myLabel.text = bLoaded + " of " + bTotal + " (" + pctLoaded + "%)";
}

function completeHandler(event:Event):void {
    var img:DisplayObject = myScrollPane.content;
    
    myScrollPane.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
    myScrollPane.removeEventListener(Event.COMPLETE, completeHandler);
    removeChild(myLabel);

    myScrollPane.setSize(img.width, img.height);
    var newX:uint = (stage.stageWidth - myScrollPane.width) / 2;
    var newY:uint = (stage.stageHeight - myScrollPane.height) / 2;
    myScrollPane.move(newX, newY);
    addChild(myScrollPane);
}

另请参见

progress 事件  
事件对象类型: flash.events.ProgressEvent
ProgressEvent.type property = flash.events.ProgressEvent.PROGRESS

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

当加载内容时调度。

定义 progress 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
bytesLoaded在侦听器处理事件时加载的项数或字节数。
bytesTotal如果加载进程成功,最终将加载的项目或字节总数。
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target报告进度的网络对象。

示例
如何使用示例

下面的示例将一个外部图像加载到 ScrollPane 实例中,并通过侦听 progresscomplete 事件显示 bytesLoadedbytesTotalpercentLoaded 属性:

import fl.containers.ScrollPane;

var url:String = "http://www.helpexamples.com/flash/images/image1.jpg";

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.setSize(320, 240);
myScrollPane.move(10, 10);
myScrollPane.addEventListener(ProgressEvent.PROGRESS, progressHandler);
myScrollPane.addEventListener(Event.COMPLETE, completeHandler);
myScrollPane.load(new URLRequest(url));
addChild(myScrollPane);

function progressHandler(event:ProgressEvent):void {
    var bLoaded:int = event.bytesLoaded;
    var bTotal:int = event.bytesTotal;
    var pctLoaded:int = int(event.currentTarget.percentLoaded);
    trace("progress: " + bLoaded + " of " + bTotal + " bytes loaded (" + pctLoaded + "%)");
}

function completeHandler(event:Event):void {
    trace("complete:");
}

另请参见

scroll 事件  
事件对象类型: fl.events.ScrollEvent
ScrollEvent.type property = fl.events.ScrollEvent.SCROLL

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9.0.28.0

当用户通过使用组件上的滚动条或鼠标设备上的滚轮滚动内容时调度。 定义 scroll 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理事件对象的对象。
delta1;一个指示完成了多少滚动量的值。
directionvertical;ScrollBar 的方向。
position0;Scrollbar 滑块移动后的位置。
target调度了事件的对象。target 不一定是侦听该事件的对象。使用 currentTarget 属性可以访问侦听该事件的对象。

示例
如何使用示例

下面的示例侦听 scroll 事件,并使用 ScrollEvent 类的 direction 属性来确定内容是水平还是垂直滚动的:

import fl.containers.ScrollPane;
import fl.events.ScrollEvent;
import fl.controls.ScrollBarDirection;

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.scrollDrag = true;
myScrollPane.source = "http://www.helpexamples.com/flash/images/image1.jpg";
myScrollPane.addEventListener(ScrollEvent.SCROLL, scrollHandler);
addChild(myScrollPane);

function scrollHandler(event:ScrollEvent):void {
    switch (event.direction) {
        case ScrollBarDirection.HORIZONTAL:
            trace("horizontal scroll", event.position, "of", event.currentTarget.maxHorizontalScrollPosition);
            break;
        case ScrollBarDirection.VERTICAL:
            trace("vertical scroll", event.position, "of", event.currentTarget.maxVerticalScrollPosition);
            break;
    }
}
示例 如何使用示例

下面的示例演示如何启动 ScrollPane 组件实例来加载新内容、激活拖动以及在查看者拖动其视图时相对于整个图像更新该视图。

注意:图像必须大于 ScrollPane (425x380) 才能与图像进行交互。 另外,由于位图数据的最大尺寸原因,为了让图像显示在预览窗口中,图像宽度和高度必须小于 2880。

若要运行该示例,请按照下列步骤操作:

  1. 将图像 test.jpg 放在 FLA 文件所在的目录中(图像越大越好)。
  2. 将 ScrollPane 组件添加到库中。
  3. 将下面的代码作为 ScrollPaneExample.as 另存到 FLA 文件所在的同一目录中。
  4. 将 FLA 文件中的 Document 类设置为 ScrollPaneExample。
package
{
    import fl.containers.ScrollPane;
    import fl.events.ScrollEvent;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.MovieClip;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.*;    
    import flash.geom.Rectangle;

    public class ScrollPaneExample extends Sprite
    {
        private var sampleImagePath:String = "test.jpg";
        private var sp:ScrollPane;
        private var previewPositioner:Sprite;
        private var previewWindowSize:Number = 100;
        private var box:Sprite;
        
        public function ScrollPaneExample() {
            stage.frameRate = 31; // for smoother scrolling
            createScrollPane();
        }
        private function createScrollPane():void {
            sp = new ScrollPane();
            sp.move(10,10);
            sp.setSize(425,380);
            sp.source = sampleImagePath;
            sp.addEventListener(Event.COMPLETE,createPreviewWindow);
            sp.addEventListener(ScrollEvent.SCROLL,repositionPreview);
            sp.scrollDrag = true;
            addChild(sp);            
        }
        private function createPreviewWindow(e:Event):void {
            var previewWindow:Sprite = new Sprite();
            previewWindow.x = 445;
            previewWindow.y = 10;
            previewWindow.graphics.lineStyle(1,0,1);
            previewWindow.graphics.drawRect(0,0,previewWindowSize,previewWindowSize);
            addChild(previewWindow);

            if(sp.content.width > previewWindowSize && sp.content.height > previewWindowSize) {
                var bitmapData:BitmapData
                try {
                    bitmapData = new BitmapData(sp.content.width,sp.content.height);
                    bitmapData.draw(sp.content);
                    var bitmap:Bitmap = new Bitmap(bitmapData);
                    bitmap.width = previewWindowSize;
                    bitmap.height = previewWindowSize;
                    bitmap.alpha = 0.25
                    previewWindow.addChild(bitmap);            
                }
                catch (e:Error) {
                    trace(e.toString());
                }
                
                previewPositioner = new Sprite();
                previewPositioner.graphics.beginFill(0xFFFFFF,0.5);
                previewPositioner.graphics.lineStyle(1,0,0.5);
                previewPositioner.graphics.drawRect(0,0,getHorizontalAspect() * previewWindowSize, getVerticalAspect() * previewWindowSize);
                previewPositioner.addEventListener(MouseEvent.MOUSE_DOWN, dragPreviewPositioner);
                previewPositioner.addEventListener(MouseEvent.MOUSE_UP, dropPreviewPositioner);
                previewWindow.addChild(previewPositioner);
            }
        }
        private function dragPreviewPositioner(e:MouseEvent):void {
            var bounds:Rectangle = new Rectangle(0,0,previewWindowSize - Math.floor(previewPositioner.width) + 1,previewWindowSize - Math.floor(previewPositioner.height) + 1);
            previewPositioner.startDrag(false,bounds);
            previewPositioner.addEventListener(MouseEvent.MOUSE_MOVE, repositionScrollPane);
        }
        private function dropPreviewPositioner(e:MouseEvent):void {
            previewPositioner.stopDrag();
            previewPositioner.removeEventListener(MouseEvent.MOUSE_MOVE, repositionScrollPane);
        }
        private function repositionScrollPane(e:MouseEvent):void {
            sp.horizontalScrollPosition = (previewPositioner.x / previewWindowSize) * sp.content.width;
            sp.verticalScrollPosition = (previewPositioner.y / previewWindowSize) * sp.content.height;
        }
        private function repositionPreview(e:ScrollEvent):void {
            previewPositioner.x = (sp.horizontalScrollPosition * previewWindowSize) / sp.content.width;
            previewPositioner.y = (sp.verticalScrollPosition * previewWindowSize) / sp.content.height;
        }
        private function getHorizontalAspect():Number {
            return sp.width / sp.content.width;
        }
        private function getVerticalAspect():Number {
            return sp.height / sp.content.height;
        }
    }
}




 

评论添加到页面后给我发送电子邮件 | 评论报告

当前页: http://livedocs.adobe.com/flash/9.0_cn/ActionScriptLangRefV3/fl/containers/ScrollPane.html