youwh
May 11th, 2008, 07:27 PM
I have some scripts that loads in external jpeg for a flip and match game. Currently, for every 2 cards I have a for loop to call in the image, and after 10 card is load and duplicate, it will go to the 2nd line. If I have 60 cards on the board, that means I need to have duplicate almost 30 sets of coding with the arrangement of card in grid. I know this is not a smart way to do it, can anyone help me on this?
And the bigger problem I think is, the jpeg loaded into the card. I want to load in the last/latest 30 pictures as the card image. Because I will be constantly putting new images into the picture folder.
This is currently how I am doing.
ActionScript Code:
for (var i:Number=0; i < 2; i++) {
var imageRequest:URLRequest=new URLRequest("cards/pic9.jpg");
var imageLoader:Loader=new Loader;
imageLoader.load(imageRequest);
card=new Card ;
addChild(card);
card.setType(imageLoader);
card.x=cardX;
card.y=cardY;
cardX+= card.width + 10;
card.addEventListener(MouseEvent.CLICK,checkCards) ;
cardArray.push(card);
}
for (var j:Number=0; j < 2; j++) {
var imageRequest2:URLRequest=new URLRequest("cards/pic10.jpg");
var imageLoader2:Loader=new Loader;
imageLoader2.load(imageRequest2);
card=new Card ;
addChild(card);
card.setType(imageLoader2);
card.x=cardX;
card.y=cardY;
cardX+= card.width + 10;
card.addEventListener(MouseEvent.CLICK,checkCards) ;
cardArray.push(card);
}
_cardX = 45
_cardY+= _card.height + 50 //next line of cards
// and after some 20 or 30 cards loaded in...
for (var i:Number=0; i < 2; i++) {
var imageRequest:URLRequest=new URLRequest("cards/pic31.jpg");
var imageLoader31:Loader=new Loader;
imageLoader31.load(imageRequest31);
card=new Card ;
addChild(card);
card.setType(imageLoader31);
card.x=cardX;
card.y=cardY;
cardX+= card.width + 10;
card.addEventListener(MouseEvent.CLICK,checkCards) ;
cardArray.push(card);
}
for (var j:Number=0; j < 2; j++) {
var imageRequest32:URLRequest=new URLRequest("cards/pic32.jpg");
var imageLoader32:Loader=new Loader;
imageLoader32.load(imageRequest32);
card=new Card ;
addChild(card);
card.setType(imageLoader2);
card.x=cardX;
card.y=cardY;
cardX+= card.width + 10;
card.addEventListener(MouseEvent.CLICK,checkCards) ;
cardArray.push(card);
}
//end with the latest/last card
And the bigger problem I think is, the jpeg loaded into the card. I want to load in the last/latest 30 pictures as the card image. Because I will be constantly putting new images into the picture folder.
This is currently how I am doing.
ActionScript Code:
for (var i:Number=0; i < 2; i++) {
var imageRequest:URLRequest=new URLRequest("cards/pic9.jpg");
var imageLoader:Loader=new Loader;
imageLoader.load(imageRequest);
card=new Card ;
addChild(card);
card.setType(imageLoader);
card.x=cardX;
card.y=cardY;
cardX+= card.width + 10;
card.addEventListener(MouseEvent.CLICK,checkCards) ;
cardArray.push(card);
}
for (var j:Number=0; j < 2; j++) {
var imageRequest2:URLRequest=new URLRequest("cards/pic10.jpg");
var imageLoader2:Loader=new Loader;
imageLoader2.load(imageRequest2);
card=new Card ;
addChild(card);
card.setType(imageLoader2);
card.x=cardX;
card.y=cardY;
cardX+= card.width + 10;
card.addEventListener(MouseEvent.CLICK,checkCards) ;
cardArray.push(card);
}
_cardX = 45
_cardY+= _card.height + 50 //next line of cards
// and after some 20 or 30 cards loaded in...
for (var i:Number=0; i < 2; i++) {
var imageRequest:URLRequest=new URLRequest("cards/pic31.jpg");
var imageLoader31:Loader=new Loader;
imageLoader31.load(imageRequest31);
card=new Card ;
addChild(card);
card.setType(imageLoader31);
card.x=cardX;
card.y=cardY;
cardX+= card.width + 10;
card.addEventListener(MouseEvent.CLICK,checkCards) ;
cardArray.push(card);
}
for (var j:Number=0; j < 2; j++) {
var imageRequest32:URLRequest=new URLRequest("cards/pic32.jpg");
var imageLoader32:Loader=new Loader;
imageLoader32.load(imageRequest32);
card=new Card ;
addChild(card);
card.setType(imageLoader2);
card.x=cardX;
card.y=cardY;
cardX+= card.width + 10;
card.addEventListener(MouseEvent.CLICK,checkCards) ;
cardArray.push(card);
}
//end with the latest/last card