public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// the board
var sqr1, sqr2, sqr3, sqr4, sqr5, sqr6, sqr7, sqr8, sqr9;
graphics.beginFill(0xFF0000);
graphics.drawRect(10, 10, 100, 100) ;
graphics.drawRect(120, 10, 100, 100);
graphics.drawRect(230, 10, 100, 100);
graphics.drawRect(10, 120, 100, 100);
graphics.drawRect(10, 230, 100, 100);
graphics.drawRect(120, 120, 100, 100);
graphics.drawRect(230, 230, 100, 100);
graphics.drawRect(230, 120, 100, 100);
graphics.drawRect(120, 230, 100, 100);
}
}
}
buttonsassing varable
Page 1 of 1
2 Replies - 604 Views - Last Post: 12 August 2010 - 08:54 PM
#1
buttons
Posted 10 August 2010 - 03:39 AM
I want to make a tictactoe game. I have created the array of squares that I want to make into clickable buttons how do i assign the variables so i can make the clickable and to latter assign logic.
Replies To: buttons
#2
Re: buttons
Posted 10 August 2010 - 01:16 PM
You need to assign the variables before drawing them. Here is an example of such:
As you can see, you have to make the sprite first and then fill the individual sprite, that way you can control that individual sprite later on.
public class Main extends Sprite{
var square:Sprite; //Makes a Sprite object
public function makeShape():void{
square = new Sprite();
addChild(square);
square.graphics.beginFill(0x0000FF);
square.graphics.drawRect(0,0,100,100);
square.graphics.endFill();
}
}
As you can see, you have to make the sprite first and then fill the individual sprite, that way you can control that individual sprite later on.
This post has been edited by Ember: 10 August 2010 - 01:18 PM
#3
Re: buttons
Posted 12 August 2010 - 08:54 PM
this is my code now and it creates an awesome board
i was wondering if the was an easy way to draw letters(ex. "X","O") in ac3; or do i have to draw the lines them self.
//creats the sprites
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var sq1:Sprite, sq2:Sprite,sq3:Sprite,sq4:Sprite,sq5:Sprite
,sq6:Sprite, sq7:Sprite,sq8:Sprite,sq9:Sprite;
//draws the Sprites
sq1 = new Sprite();
addChild(sq1);
sq1.graphics.beginFill(0x0000FF);
sq1.graphics.drawRect(10,10,100,100);
sq1.graphics.endFill();
sq2 = new Sprite();
addChild(sq2);
sq2.graphics.beginFill(0x0000FF);
sq2.graphics.drawRect(120,10,100,100);
sq2.graphics.endFill();
sq3 = new Sprite();
addChild(sq3);
sq3.graphics.beginFill(0x0000FF);
sq3.graphics.drawRect(230,10,100,100);
sq3.graphics.endFill();
sq4 = new Sprite();
addChild(sq4);
sq4.graphics.beginFill(0x0000FF);
sq4.graphics.drawRect(10,120,100,100);
sq4.graphics.endFill();
sq5 = new Sprite();
addChild(sq5);
sq5.graphics.beginFill(0x0000FF);
sq5.graphics.drawRect(120,120,100,100);
sq5.graphics.endFill();
sq6 = new Sprite();
addChild(sq6);
sq6.graphics.beginFill(0x0000FF);
sq6.graphics.drawRect(230,120,100,100);
sq6.graphics.endFill();
sq7 = new Sprite();
addChild(sq7);
sq7.graphics.beginFill(0x0000FF);
sq7.graphics.drawRect(10,230,100,100);
sq7.graphics.endFill();
sq8 = new Sprite();
addChild(sq8);
sq8.graphics.beginFill(0x0000FF);
sq8.graphics.drawRect(120,230,100,100);
sq8.graphics.endFill();
sq9 = new Sprite();
addChild(sq9);
sq9.graphics.beginFill(0x0000FF);
sq9.graphics.drawRect(230,230,100,100);
sq9.graphics.endFill();
i was wondering if the was an easy way to draw letters(ex. "X","O") in ac3; or do i have to draw the lines them self.
This post has been edited by sunal135: 12 August 2010 - 08:55 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|