||moock-updates|| asdg, actionscript 2.0, and a link to buy flash
colin@moock.org
colin@moock.org
Tue Aug 26 16:14:01 2003
first of all, i promised to post a link to buy Flash MX 2004...here it is:
http://affiliates.macromedia.com/b.asp?id=2331&p=go/dr_home_aff1
if you use that link to buy your copy of Flash (or any other 2004 product) i
get a commission that will help support moock.org.
now on to the good stuff...
/**
* asdg & actionscript 2
*/
now that Flash MX 2004 has been announced, i've been asked whether i intend
to update ActionScript for Flash MX: The Definitive Guide. here's the
official response:
i am currently working on a project that will cover ActionScript 2.0.
however the details and shipping date are still confidential. i will make an
announcement on my blog (www.moock.org/blog) and on this mailing list when
the project is near completion.
until then, if you're working with actionscript 1.0, asdg2 is still
completely applicable to your work.
even if you're working in actionscript 2.0:
1) the language reference of asdg2 is still 99% accurate, and still provides
complete coverage of the core language as it exists in Flash Player 6. of
course, if you want to use a specific Flash Player 7-only class, you'll have
to consult Macromedia's help for the documentation.
2) all non-object-oriented aspects of the language have not changed, so
asdg2's coverage of non-object-oriented topics (such as variables, loops,
conditionals, operators, movie clips, etc) is still accurate and will
continue to be useful.
/**
* a taste of actionscript 2.0
*/
i thought i'd whip up a quick'n'dirty code sample to show you all what as2
feels like. things to note:
-strict typing. datatypes are specified after a colon (e.g.,
propName:datatype = value)..unlike java, which specifies types first (e.g.,
datatype propname = value)
-automatic 'this' resolution. you don't have to explicitly use 'this' to
refer to instance and class properties
-a REAL class statement!!!
-access control modifiers (public, private, but no protected)
-use "var" in a class to create properties
-it all compiles down to AS1 (yes, prototype) so you can run it in flash
player 6
-class code must appear in an external .as file, not on a frame, button or
clip
enjoy! lots more to come!
/**
* A sample ActionScript 2.0 class.
*/
class Box {
// Box dimensions.
private var width:Number;
private var height:Number;
// Movie clip that will contain visual
// representation of the box.
private var container_mc:MovieClip;
/**
* Constructor.
*/
public function Box (w:Number, h:Number,
x:Number, y:Number,
target:MovieClip, depth:Number) {
// Create the container clip that will hold Box visuals.
container_mc = target.createEmptyMovieClip("boxcontainer" + depth,
depth);
// Initialize size.
setWidth(w);
setHeight(h);
// Initialize position.
setX(x);
setY(y);
}
/**
* Accessor to retrieve width.
*/
public function getWidth ():Number {
return width;
}
/**
* Accessor to assign width. This version both assigns the new width
property
* value and redraws the box based on the new width.
*/
public function setWidth (w:Number):Void {
width = w;
draw();
}
/**
* Accessor to retrieve height.
*/
public function getHeight ():Number {
return height;
}
/**
* Accessor to assign height. This version both assigns the new height
property
* value and redraws the box based on the new height.
*/
public function setHeight (h:Number):Void {
height = h;
draw();
}
/**
* Accessor to retrieve x. For convenience, the x and y coordinates
* are stored directly on the container movie clip. If numeric accuracy
* were a concern, we'd store x as a Box property separately so
* that it wouldn't be rounded by the MovieClip class.
*/
public function getX ():Number {
return container_mc._x;
}
/**
* Accessor to assign x.
*/
public function setX (x:Number):Void {
container_mc._x = x;
}
/**
* Accessor to retrieve y.
*/
public function getY ():Number {
return container_mc._y;
}
/**
* Accessor to assign y.
*/
public function setY (y:Number):Void {
container_mc._y = y;
}
/**
* Displays the Box instance on screen. Uses the MovieClip drawing methods
to
* draw lines in container_mc. For more information, see
* ActionScript for Flash MX: The Definitive Guide.
*/
public function draw ():Void {
// Clear the previous box rendering.
container_mc.clear();
// Use a 1 point black line.
container_mc.lineStyle(1, 0x000000);
// Position the drawing pen.
container_mc.moveTo(0, 0);
// Start a white fill.
container_mc.beginFill(0xFFFFFF, 100);
// Draw the border of the box.
container_mc.lineTo(width, 0);
container_mc.lineTo(width, height);
container_mc.lineTo(0, height);
container_mc.lineTo(0, 0);
// Formally stop filling the shape.
container_mc.endFill();
}
}