Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 192

Programming actionscript 3.0
Table of Contents

Advertisement

The interface for the application includes two text fields,
. The text properties of these text fields are updated with information about the
outputTxt
GeometricSprite objects that have been added to the canvas or selected by the user. The
GeometricSprite class handles this information-reporting task by overriding the
method, as follows:
public override function toString():String
{
return this.shapeType + " of size " + this.size + " at " + this.x + ", "
+ this.y;
}
The
property is set to the appropriate value in the constructor method of each
shapeType
GeometricSprite subclass. For example, the
value for a CircleSprite instance recently added to the DrawingCanvas instance:
Circle of size 50 at 0, 0
The
describeChildren()
child list, using the
numChildren
to set the limit of the
var desc:String = "";
var child:DisplayObject;
for (var i:int = 0; i < this.numChildren; i++)
{
child = this.getChildAt(i);
desc += i + ": " + child + '\n';
}
The resulting string is used to set the
Clicking and dragging display objects
When the user clicks on a GeometricSprite instance, the application calls the
event handler. As the following shows, this event handler is set to listen for mouse down
events in the constructor function of the GeometricSprite class:
this.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
The
onMouseDown()
object. If it is the first time this method has been called for the object, the method creates a
new Shape object named
Shape object to draw a red highlight rectangle, as follows:
this.selectionIndicator = new Shape();
this.selectionIndicator.graphics.lineStyle(1.0, 0xFF0000, 1.0);
192
Display Programming
method of the DrawingCanvas class loops through the canvas's
property (inherited from the DisplayObjectContainer class)
loop. It generates a string listing each child, as follows:
for
text
method then calls the
selectionIndicator
selectedSpriteTxt
method might return the following
toString()
property of the
outputTxt
method of the GeometricSprite
showSelected()
and it uses the
graphics
and
toString()
text field.
onMouseDown()
property of the

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents