
November 26th, 2012, 12:47 AM
|
|
Registered User
|
|
Join Date: May 2010
Posts: 2
Time spent in forums: 32 m 18 sec
Reputation Power: 0
|
|
|
Need Help Making Duplicate Cards (Movie Clips) with a function
I'm in the process of creating a Yu-Gi-Oh! based multiplayer game using Flash, Php and Mysql Database, I have been able to successfully create a Dynamic card using data pulled from the database and into php and using variables to send data into flash. I can create a single card but I cannot seem to make multiple cards. I have a for loop running in PHP to pull all the cards data, and I just cannot seem to figure out how to use that data to duplicate the function to create a single card. This is urgent! I need to figure this out. Please help.
(Code is below)
PHP:
Code:
<?php
//Connection to the database
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die($dberror1);
//Select the db you wish to connect to
$select_db = mysql_select_db($db_select) or die($dberror2);
//Mysql query to run the while loop
$card_query = mysql_query("SELECT * FROM cards") or die("There are no cards in this database!");
//Count how many rows are in the database
$num_cards = mysql_num_rows($card_query) or die("No cards in the database!");
//Run a while loop to grab data from the database
while($cardData = mysql_fetch_assoc($card_query)){
$id = $cardData['id'];
$cid = $cardData['card_id'];
$c_name = $cardData['card_name'];
$c_attrib = $cardData['attribute'];
$c_level = $cardData['level'];
$c_attack = $cardData['attack'];
$c_defense = $cardData['defense'];
$c_effect = $cardData['effect'];
$c_class = $cardData['card_class'];
$c_type = $cardData['type'];
$c_desc = $cardData['description'];
$c_image = $cardData['card_image'];
}
echo "&num_cards=".$num_cards;
for($i = 0; $i < $num_cards; $i++){
echo "&id=".$id;
echo "&card_id=".$cid;
echo "&card_name=".$c_name;
echo "&card_attribute=".$c_attrib;
echo "&card_level=".$c_level;
echo "&card_attack=".$c_attack;
echo "&card_defense=".$c_defense;
echo "&card_effect=".$c_effect;
echo "&card_class="."[".$c_class."]";
echo "&card_type=".$c_type;
echo "&description=".$c_desc;
echo "&card_image=".$c_image;
}
?>
How it outputs:
Code:
&num_cards=2&id=2&card_id=38033121&card_name=Dark Magician Girl&card_attribute=Dark&card_level=6&card_attack=2300&card_defense=2000&card_effect=none&card_class=[Spellcaster]&card_type=Effect&description=This card gains 300 ATK for each "Dark Magician" or "Magician of Black Chaos" in either player's Graveyard.&card_image=38033121.jpg&id=2&card_id=38033121&card_name=Dark Magician Girl&card_attribute=Dark&card_level=6&card_attack=2300&card_defense=2000&card_effect=none&card_class=[Spellcaster]&card_type=Effect&description=This card gains 300 ATK for each "Dark Magician" or "Magician of Black Chaos" in either player's Graveyard.&card_image=38033121.jpg
Actionscript 2.0 Code:
Code:
function Dynamic_cards(){
//Sets up the LoadVars for loading the content
CardLoader = new LoadVars();
CardLoader.load("http://www.duelist-central.com/Cards/index.php");
CardLoader.onLoad = function(){
//trace(CardLoader.card_name);
//trace(CardLoader.card_level);
//trace(CardLoader.num_cards);
//Creates an empty movie clip, and loads the movie
_root.createEmptyMovieClip("Singlecard",_root.getNextHighestDepth());
_root.Singlecard.attachMovie(CardLoader.card_type,"CARD",0);
_root.Singlecard._x = 300;
_root.Singlecard._y = 200;
_root.Singlecard._height = 187;
_root.Singlecard._width = 130;
//Sets the text format for the card name
var format1:TextFormat = new TextFormat();
format1 = new TextFormat();
format1.font = "Arial";
format1.bold = true;
format1.size = 7;
format1.color= 0x000000;
//Sets the text format for the card type
var format2:TextFormat = new TextFormat();
format2 = new TextFormat();
format2.font = "Arial";
format2.bold = true;
format2.size = 10;
format2.align = center;
format2.color= 0xFFFFFF;
//Creates and displays the cardname inside of the dynamic textfield
_root.Singlecard.createTextField("cardname",1,-54,-82,100,500);
_root.Singlecard.cardname.setNewTextFormat(format1);
_root.Singlecard.cardname.text = CardLoader.card_name;
_root.Singlecard.cardname.autoSize = true;
_root.Singlecard.cardname.selectable = false;
//Creates a textfield for cardtype and defines if it has an ability or not
_root.Singlecard.createTextField("CLASS",2,-53,47,200,100);
_root.Singlecard.CLASS.setNewTextFormat(format1);
_root.Singlecard.CLASS.text = CardLoader.card_class;
_root.Singlecard.CLASS.autoSize = true;
_root.Singlecard.CLASS.selectable = false;
_root.Singlecard.createTextField("ATK",3,-16,73,200,100);
_root.Singlecard.ATK.setNewTextFormat(format1);
_root.Singlecard.ATK.text = "ATK/"+CardLoader.card_attack;
_root.Singlecard.ATK.autoSize = true;
_root.Singlecard.ATK.selectable = false;
_root.Singlecard.createTextField("DEF",4,18,73,200,100);
_root.Singlecard.DEF.setNewTextFormat(format1);
_root.Singlecard.DEF.text = "DEF/"+CardLoader.card_defense;
_root.Singlecard.DEF.autoSize = true;
_root.Singlecard.DEF.selectable = false;
_root.Singlecard.createEmptyMovieClip("Attribute",5);
_root.Singlecard.Attribute.attachMovie(CardLoader.card_attribute,"Attr",6);
_root.Singlecard.Attribute.Attr._x = 45.5;
_root.Singlecard.Attribute.Attr._y = -76.5;
_root.Singlecard.Attribute.Attr._height = 12;
_root.Singlecard.Attribute.Attr._width = 12;
_root.Singlecard.createEmptyMovieClip("CardImage",7);
_root.Singlecard.CardImage.attachMovie(CardLoader.card_image,"Image",8);
_root.Singlecard.CardImage.Image._x = 0;
_root.Singlecard.CardImage.Image._y = -6;
_root.Singlecard.CardImage.Image._height = 94;
_root.Singlecard.CardImage.Image._width = 94;
var starsArr = new Array();
for (h = 0; h < CardLoader.card_level; h++)
{
starsArr[h] = new Object();
starsArr[h] = _root.Singlecard.createEmptyMovieClip("stars" + h, 9 + h);
starsArr[h].attachMovie("istars", "star", 1);
starsArr[h]._width = 8;
starsArr[h]._height = 8;
starsArr[h]._x = 46 - (starsArr[h]._width + 1) * h;
starsArr[h]._y = -63;
} // end of for
_root.Singlecard.onPress = function(){
startDrag(this);
}
_root.Singlecard.onRelease = function(){
stopDrag();
}
}//end LoadVars
}//end function
Dynamic_cards();
How this code outputs:
http://i133.photobucket.com/albums/q45/bmsk81992/output.png
|