Hi,
I am making a grid based game with movie clips of 4 colors. Till now I have completed to populate the clips on the stage randomly. I can trace their names like this
public function clickCard(event:MouseEvent)
{
var thisCard:Card = (event.currentTarget as Card); // what card?
trace(thisCard.cardface);
trace (thisCard.currentLabel);
//MovieClip.currentLabel
}
What I want to do is check the surrounding movie clips and get their names when 1 clip is clicked on the stage.
How can I do that ? can someone guide me… pls
Here is my complete code till now…
package
{
import flash.display.MovieClip;
import flash.events.*;
public class Cards extends MovieClip
{
// game constants
private static const boardWidth:uint = 10;
private static const boardHeight:uint = 10;
private static const cardHorizontalSpacing:Number = 46;
private static const cardVerticalSpacing:Number = 46;
private static const boardOffsetX:Number = 120;
private static const boardOffsetY:Number = 45;
public function Cards():void
{
// make a list of card numbers
var cardlist:Array = new Array();
for(var i:uint=0;i<boardWidth*boardHeight/2;i++)
{
cardlist.push(i);
cardlist.push(i);
//trace (cardlist*);
//trace (cardlist.length);
}
// end for
for (var x:uint=0; x<boardWidth; x++) {
for (var y:uint=0; y<boardHeight; y++) {
var newCard:Card = new Card();
newCard.stop();
newCard.x = x*cardHorizontalSpacing;
newCard.y = y*cardVerticalSpacing;
// get a random color
var randomFace:uint = Math.floor(Math.random()*cardlist.length);
newCard.cardface = cardlist[randomFace]; // assign face to card
//cardlist.splice(randomFace,1); // remove face from list
newCard.gotoAndStop(newCard.cardface+2);
addChild(newCard);
newCard.addEventListener(MouseEvent.CLICK,clickCard);
}
}
}
// check which card is clicked
public function clickCard(event:MouseEvent)
{
var thisCard:Card = (event.currentTarget as Card); // what card?
trace(thisCard.cardface);
trace (thisCard.currentLabel);
//MovieClip.currentLabel
}
}
}