
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Abstract and Final Classes Not Supported
|
213
coordsLoader = new XML( );
}
public function loadCoords (URL:String):Void {
var clip:MovieClip = this.mc;
coordsLoader.onLoad = function (success:Boolean):Void {
if (success) {
clip._x = parseInt(this.firstChild...); // XML node access not shown
clip._y = parseInt(this.firstChild...); // XML node access not shown
} else {
// Handle a load error
trace("Could not load coords from file: " + URL);
}
};
coordsLoader.load(URL);
}
}
With access to both instances, the Circle class can happily transfer loaded coordi-
nates from the XML file to the movie clip. Not only is this composition relationship
more natural, but it lets us easily change the implementation details later without
breaking any code that uses the Circle class. For example, we could change the XML
instance to a LoadVars instance without affecting any external code that invokes
Circle.loadCoords( ).
Note that a Circle instance doesn’t really have to store the XML instance in the
coordsLoader property. Instead, the Circle.loadCoords( ) method could store the
XML instance in a local variable (in other words, we could define a “Uses-A” rela-
tionship rather than a “Has-A” relationship). The latter technique works but has a
higher performance cost because the XML instance has to be ...