AS 3.0 Drawing Dynamic Shapes
So I have started my journey down the path of upgrading to AS 3.0 and I’m finding some very strange things. Here we go.
I’ve created a rounded rectangle from code and I wanted to place it vertically in the center of my stage. No big deal so this is what I did.
sp = new Sprite();
addChild(sp);
sp.graphics.beginFill(0xff0000);
sp.graphics.drawRoundRect(0,stage.stageHeight/2-sp.height/2,100,50,20);
sp.graphics.endFill();
What happened? It was not in the center. At first I thought my math was wrong but I ran a trace.
trace(”sprite height: “+ sp.y); // sprite height: 0
Are you kidding me? 0? Really? All that I can think is that the alleged y value is really the anchor point in the sprite. Interesting.
I was able to achieve my goal by doing this.
sp = new Sprite();
addChild(sp);
sp.graphics.beginFill(0xff0000);
sp.graphics.drawRoundRect(0,0,100,50,20);
sp.graphics.endFill();
sp.x=10
sp.y=stage.stageHeight/2-sp.height/2;
So all is wall in AS 3.0 land but some strange things in my journey.