mattgyver
January 29th, 2009, 03:36 AM
I’m having a heck of a time drawing sprites based on a loop inside of a class.
My goal is to create anywhere from 1 to 1000 clickable tiles. They will be line/fill and not an existing library movieClip. When I make a package with “public class HexagonTile extends Sprite”, draw and addChild to the tiles, then from a separate .as class loop call “var testHex:HexagonTile = new HexagonTile();”, the tiles don’t get drawn, but there are no errors and the traces come back with correct info.
So the jist of it is: In one class file I run a loop and want to create x number of tiles:
for (var j:Number = 0; j < gameMap[0].length; j++) {
var testHex:HexagonTile = new HexagonTile();
}
So the HexagonTile class needs to draw some graphics and place it all on the stage:
public class HexagonTile extends Sprite {
public var checker:Sprite;
public function HexagonTile():void {
checker = new Sprite();
checker.y = Math.random() * 400 >> 0;
checker.x = Math.random() * 400 >> 0;
checker.graphics.lineStyle(2, 0xFF0000);
checker.graphics.beginFill(0x0000FF);
checker.graphics.drawCircle(10, 10, 100);
checker.graphics.endFill();
addChild(checker);
trace(checker.name);
}
}
The above code has no errors and traces the checker names fine, so everything is connected right I think, just no drawings.
Here is a link to my 2 class .as files, and the main fla (which is only used to trigger the class). AS3 is a pain. http://mattgyver.com/HexagonBoard.zip I've also attached it.
Thanks!
My goal is to create anywhere from 1 to 1000 clickable tiles. They will be line/fill and not an existing library movieClip. When I make a package with “public class HexagonTile extends Sprite”, draw and addChild to the tiles, then from a separate .as class loop call “var testHex:HexagonTile = new HexagonTile();”, the tiles don’t get drawn, but there are no errors and the traces come back with correct info.
So the jist of it is: In one class file I run a loop and want to create x number of tiles:
for (var j:Number = 0; j < gameMap[0].length; j++) {
var testHex:HexagonTile = new HexagonTile();
}
So the HexagonTile class needs to draw some graphics and place it all on the stage:
public class HexagonTile extends Sprite {
public var checker:Sprite;
public function HexagonTile():void {
checker = new Sprite();
checker.y = Math.random() * 400 >> 0;
checker.x = Math.random() * 400 >> 0;
checker.graphics.lineStyle(2, 0xFF0000);
checker.graphics.beginFill(0x0000FF);
checker.graphics.drawCircle(10, 10, 100);
checker.graphics.endFill();
addChild(checker);
trace(checker.name);
}
}
The above code has no errors and traces the checker names fine, so everything is connected right I think, just no drawings.
Here is a link to my 2 class .as files, and the main fla (which is only used to trigger the class). AS3 is a pain. http://mattgyver.com/HexagonBoard.zip I've also attached it.
Thanks!