29 November, 2007

My First Package and the DisplayList

so, following along the lynda.com tutorials, i happened upon the one about the new feature in ActionScript3, and that is the "displayList". New to ActionScript, the displayList is basically the manager for all things that APPEAR on the stage. In order to show something on the stage you must add it to the stage, and conversely in order to NOT display some object on the stage, you can use removeChild().

its nothing too crazy, and really not that hard, but it was cool to see my first little creation come to life! now, this may appear as nothing but a circle with a line through it, but for my company, Navtrak, Inc. the icon you see bears a striking resemblance to our vehicle icon in our software.

anyway, the code for this exercise is below:

package {
import flash.display.Shape;
import flash.display.Sprite;

public class DisplayList extends Sprite {

public function DisplayList() {
var circle:Shape = new Shape();
circle.graphics.lineStyle(5,0x000000,1);
circle.graphics.beginFill(0xcc0000,.75);
circle.graphics.drawCircle(20,20,15);
addChild(circle);
circle.x = 30;
circle.y = 10
var line:Shape = new Shape();
line.graphics.lineStyle(2, 0, 100);
line.graphics.lineTo(25, 25);
addChild(line);
line.x = 30;
line.y = 10;
}
}
}

The example is here.

Labels: , ,

4 Comments:

At 30 November, 2007 , Blogger creole said...

Seems like a LOT of code just to add ONE item to the stage. Is there more to the demo? Does the icon do anything?

 
At 30 November, 2007 , Blogger Tony said...

well, i dont know since A LOT of code is relative... wouldnt ya say? i mean, in coldfusion we can do a lot of things with just a little bit of code, but that kinda warps our perception sometimes.

but, to answer you, no it doesnt do a single thing, other than draw a circle and a line and display it on the stage. quite simply its truly nothing, other than my first foray into an actionscript class, the display list, and doing anything flex.

actionscript seems to LOOK like a lot of code, but once you get into it, its really not that much.

and each line is very justifiable and needed.

 
At 30 November, 2007 , Blogger Tony said...

oh, and one more thing, its actually TWO different things on the stage, the circle is one, and the line is another.

 
At 14 May, 2009 , Blogger fizzgig said...

how do you show this in a mxml file?

 

Post a Comment

<< Home