The ChildAccess abstract simplifies access to nested DisplayObjects. Although performance may be somewhat slower than using direct references, this is especially useful when setting up a UI or performing non-intensive tasks.
For example, consider the following hierarchy:
movieClip -> sprite -> sprite2 -> textField
You can use ChildAccess to more easily reference TextField:
var movieClip:ChildAccess<MovieClip> = movieClip;
movieClip.sprite.sprite2.textField.text = "Hello World";
Without ChildAccess, it can be more difficult to access nested objects:
var sprite:Sprite = cast movieClip.getChildByName("sprite");
var sprite2:Sprite = cast sprite.getChildByName("sprite2");
var textField:TextField = cast sprite2.getChildByName("textField");
textField.text = "Hello World";
ChildAccess provides most of the benefits of dynamic references, while still remaining strongly typed for properties.
You can use array access to reach child instances as well. This is useful if the child object has the name of a DisplayObject property, or if it uses special characters:
var movieClip:ChildAccess<MovieClip> = movieClip;
movieClip.sprite["sprite2"].x = 100;
Static variables
staticantiAliasType:AntiAliasType
Accesses the antiAliasType
property (for TextField instances only).
staticread onlycurrentFrameLabel:String
Accesses the currentFrameLabel
property (for MovieClip instances only).
staticread onlycurrentLabel:String
Accesses the currentLabel
property (for MovieClip instances only).
staticread onlycurrentLabels:Array<FrameLabel>
Accesses the currentLabels
property (for MovieClip instances only).
staticdefaultTextFormat:TextFormat
Accesses the defaultTextFormat
property (for TextField instances only).
staticdoubleClickEnabled:Bool
Accesses the doubleClickEnabled
property (for InteractiveObject instances only).
staticread onlydropTarget:DisplayObject
Accesses the dropTarget
property (for Sprite instances only).
staticread onlygraphics:Graphics
Accesses the graphics
property (for Shape or Sprite instances only).
staticmouseChildren:Bool
Accesses the mouseChildren
property (for DisplayObjectContainer instances only).
staticneedsSoftKeyboard:Bool
Accesses the needsSoftKeyboard
property (for InteractiveObject instances only).
staticread onlynumChildren:Int
Accesses the numChildren
property (for DisplayObjectContainer instances only).
staticread onlyselectionBeginIndex:Int
Accesses the selectionBeginIndex
property (for TextField instances only).
staticread onlyselectionEndIndex:Int
Accesses the selectionEndIndex
property (for TextField instances only).
staticsoftKeyboardInputAreaOfInterest:Rectangle
Accesses the softKeyboardInputAreaOfInterest
property (for InteractiveObject instances only).
statictabChildren:Bool
Accesses the tabChildren
property (for DisplayObjectContainer instances only).
statictileBlendModeEnabled:Bool
Accesses the tileBlendModeEnabled
property (for Tilemap instances only).
statictileColorTransformEnabled:Bool
Accesses the tileColorTransformEnabled
property (for Tilemap instances only).
Static methods
staticaddChild(this:T, child:DisplayObject):DisplayObject
Accesses the addChild
method (for DisplayObjectContainer instances only).
staticaddChildAt(this:T, child:DisplayObject, index:Int):DisplayObject
Accesses the addChildAt
method (for DisplayObjectContainer instances only).
staticaddEventListener<T2>(this:T, type:EventType<T2>, listener:T2 ‑> Void, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void
Accesses the addEventListener
method.
staticaddFrameScript(this:T, index:Int, method:() ‑> Void):Void
Accesses the addFrameScript
method (for MovieClip instances only).
staticaddTileAt(this:T, tile:Tile, index:Int):Tile
Accesses the addTileAt
method (for Tilemap instances only).
staticaddTiles(this:T, tiles:Array<Tile>):Array<Tile>
Accesses the addTiles
method (for Tilemap instances only).
staticappendText(this:T, text:String):Void
Accesses the appendText
method (for TextField instances only).
staticareInaccessibleObjectsUnderPoint(this:T, point:Point):Bool
Accesses the areInaccessibleObjectsUnderPoint
method (for DisplayObjectContainer instances only).
staticattachNetStream(this:T, netStream:NetStream):Void
Accesses the attachNetStream
method (for Video instances only).
staticattachTimeline(this:T, timeline:Timeline):Void
Accesses the attachTimeline
method (for MovieClip instances only).
staticcontains(this:T, child:Dynamic):Bool
Accesses the contains
method (for Tilemap or DisplayObjectContainer instances only).
staticgetBounds(this:T, targetCoordinateSpace:DisplayObject):Rectangle
Accesses the getBounds
method.
staticgetCharBoundaries(this:T, charIndex:Int):Rectangle
Accesses the getCharBoundaries
method (for TextField instances only).
staticgetCharIndexAtPoint(this:T, x:Float, y:Float):Int
Accesses the getCharIndexAtPoint
method (for TextField instances only).
staticgetChildAt(this:T, index:Int):DisplayObject
Accesses the getChildAt
method (for DisplayObjectContainer instances only).
staticgetChildByName(this:T, name:String):DisplayObject
Accesses the getChildByName
method (for DisplayObjectContainer instances only).
staticgetChildIndex(this:T, child:DisplayObject):Int
Accesses the getChildIndex
method (for DisplayObjectContainer instances only).
staticgetFirstCharInParagraph(this:T, charIndex:Int):Int
Accesses the getFirstCharInParagraph
method (for TextField instances only).
staticgetLineIndexAtPoint(this:T, x:Float, y:Float):Int
Accesses the getLineIndexAtPoint
method (for TextField instances only).
staticgetLineIndexOfChar(this:T, charIndex:Int):Int
Accesses the getLineIndexOfChar
method (for TextField instances only).
staticgetLineLength(this:T, lineIndex:Int):Int
Accesses the getLineLength
method (for TextField instances only).
staticgetLineMetrics(this:T, lineIndex:Int):TextLineMetrics
Accesses the getLineMetrics
method (for TextField instances only).
staticgetLineOffset(this:T, lineIndex:Int):Int
Accesses the getLineOffset
method (for TextField instances only).
staticgetLineText(this:T, lineIndex:Int):String
Accesses the getLineText
method (for TextField instances only).
staticgetObjectsUnderPoint(this:T, point:Point):Array<DisplayObject>
Accesses the getObjectsUnderPoint
method (for DisplayObjectContainer instances only).
staticgetParagraphLength(this:T, charIndex:Int):Int
Accesses the getParagraphLength
method (for TextField instances only).
staticgetTextFormat(this:T, beginIndex:Int = -1, endIndex:Int = -1):TextFormat
Accesses the getTextFormat
method (for TextField instances only).
staticgetTileIndex(this:T, tile:Tile):Int
Accesses the getTileIndex
method (for Tilemap instances only).
staticgotoAndPlay(this:T, frame:Any, ?scene:String):Void
Accesses the gotoAndPlay
method (for MovieClip instances only).
staticgotoAndStop(this:T, frame:Any, ?scene:String):Void
Accesses the gotoAndStop
method (for MovieClip instances only).
statichitTestPoint(this:T, x:Float, y:Float, shapeFlag:Bool = false):Bool
Accesses the hitTestPoint
method.
staticremoveChild(this:T, child:DisplayObject):DisplayObject
Accesses the removeChild
method (for DisplayObjectContainer instances only).
staticremoveChildAt(this:T, index:Int):DisplayObject
Accesses the removeChildAt
method (for DisplayObjectContainer instances only).
staticremoveChildren(this:T, beginIndex:Int = 0, endIndex:Int = 0x7FFFFFFF):Void
Accesses the removeChildren
method (for DisplayObjectContainer instances only).
staticremoveEventListener<T2>(this:T, type:EventType<T2>, listener:T2 ‑> Void, useCapture:Bool = false):Void
Accesses the removeEventListener
method.
staticremoveTile(this:T, tile:Tile):Tile
Accesses the removeTile
method (for Tilemap instances only).
staticremoveTileAt(this:T, index:Int):Tile
Accesses the removeTileAt
method (for Tilemap instances only).
staticremoveTiles(this:T, beginIndex:Int = 0, endIndex:Int = 0x7fffffff):Void
Accesses the removeTiles
method (for Tilemap instances only).
staticreplaceSelectedText(this:T, value:String):Void
Accesses the replaceSelectedText
method (for TextField instances only).
staticreplaceText(this:T, beginIndex:Int, endIndex:Int, newText:String):Void
Accesses the replaceText
method (for TextField instances only).
staticrequestSoftKeyboard(this:T):Bool
Accesses the requestSoftKeyboard
method (for InteractiveObject instances only).
staticsetChildIndex(this:T, child:DisplayObject, index:Int):Void
Accesses the setChildIndex
method (for DisplayObjectContainer instances only).
staticsetSelection(this:T, beginIndex:Int, endIndex:Int):Void
Accesses the setSelection
method (for TextField instances only).
staticsetTextFormat(this:T, format:TextFormat, beginIndex:Int = -1, endIndex:Int = -1):Void
Accesses the setTextFormat
method (for TextField instances only).
staticsetTileIndex(this:T, tile:Tile, index:Int):Void
Accesses the setTileIndex
method (for Tilemap instances only).
staticsetTiles(this:T, group:TileContainer):Void
Accesses the setTiles
method (for Tilemap instances only).
staticsortTiles(this:T, compareFunction:(Tile, Tile) ‑> Int):Void
Accesses the sortTiles
method (for Tilemap instances only).
staticstartDrag(this:T, lockCenter:Bool = false, ?bounds:Rectangle):Void
Accesses the startDrag
method (for Sprite instances only).
staticstopAllMovieClips(this:T):Void
Accesses the stopAllMovieClips
method (for DisplayObjectContainer instances only).
staticswapChildren(this:T, child1:DisplayObject, child2:DisplayObject):Void
Accesses the swapChildren
method (for DisplayObjectContainer instances only).
staticswapChildrenAt(this:T, index1:Int, index2:Int):Void
Accesses the swapChildrenAt
method (for DisplayObjectContainer instances only).
staticswapTiles(this:T, tile1:Tile, tile2:Tile):Void
Accesses the swapTiles
method (for Tilemap instances only).
staticswapTilesAt(this:T, index1:Int, index2:Int):Void
Accesses the swapTilesAt
method (for Tilemap instances only).