At 10/12/16 10:11 PM, drp22 wrote:
Hello folks,
I'm creating blocks but I want them to be numbered.
this.graphics.beginFill(1, 1);
this.graphics.drawRect(50, 50, 50, 50);
this.graphics.endFill();
I've tried searching on Youtube and Google for tutorials but there wasn't anything specifically for what I'm looking for.
How do I display and have it shown as a block with a number 1 inside of it?
Seems simple but im no expert.. Possibly create a function that draws these graphics and create a textfield variable..
give the texts properties what you want them to be besides the text.. Set the X and Y Position to the boxes width and height divided by 2 so its in the box may want to subtract your textfields width... make sure the function uses parameters for the boxes X and Y position.. then possibly use a for loop ? to number and create your squares and make your text equal the value of i if you use that in your for loop? im sort of nooby but from my head this is what i thought of
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;
/**
* ...
* @author Muerte
*/
public class Main extends Sprite
{
public var SquareCount:int = 0;
public var SquareCountMax:int = 11;
public var curX:int = 0;
public function Main()
{
for (var i:int = 1; i < SquareCountMax; i++)
{
if (SquareCount <= SquareCountMax)
{
curX = curX + 55;
this.drawSquare(curX, 100, 50, 50, i.toString() );
SquareCount++
}
}
}
public function drawSquare(BoxX:int, BoxY:int, BoxWidth:int, BoxHeight:int, text:String) : void {
var textf:TextField = new TextField();
var format:TextFormat = new TextFormat();
this.graphics.beginFill(0xFF3322, 1);
this.graphics.drawRect(BoxX, BoxY, BoxWidth, BoxHeight);
this.graphics.endFill();
format.size = 20;
format.font = "Arial";
textf.defaultTextFormat = format;
textf.x = BoxX + BoxWidth / 2;
textf.y = BoxY + BoxHeight / 2;
textf.textColor = 0x000000;
textf.text = text;
addChild(textf);
}
}
}
Sorry if i'm a bit confusing..
The image below should be your outcome