...

View Full Version : Help with my basic activescript code



learningflash
09-30-2009, 12:00 PM
My code is suppose to create 2 random numbers (for 2 dice), then create the correct media clip from the library and put it into a 2 containers on the screen.
It only works 9/10 time, such as it mayl display dice 2 and 5 and the trace will be 3 and 2. Please can anybody see whats wrong. My codeing skills are very basic, thank.


var rollresult1:int = 1 + Math.random()*6
var rollresult2:int = 1 + Math.random()*6
var rollresulttotal:int = rollresult1 + rollresult2


if (rollresult1 == 1)
{var dice11_mc:DICE1 = new DICE1();
Dice1_container_mc.addChild(dice11_mc);
}
else if (rollresult1 == 2)
{var dice12_mc:DICE2 = new DICE2();
Dice1_container_mc.addChild(dice12_mc);
}
else if (rollresult1 == 3)
{var dice13_mc:DICE3 = new DICE3();
Dice1_container_mc.addChild(dice13_mc);
}
else if (rollresult1 == 4)
{var dice14_mc:DICE4 = new DICE4();
Dice1_container_mc.addChild(dice14_mc);
}
else if (rollresult1 == 5)
{var dice15_mc:DICE5 = new DICE5();
Dice1_container_mc.addChild(dice15_mc);
}
else if (rollresult1 == 6)
{var dice16_mc:DICE6 = new DICE6();
Dice1_container_mc.addChild(dice16_mc);
}


if (rollresult2 == 1)
{var dice21_mc:DICE1 = new DICE1();
Dice1_container_mc.addChild(dice21_mc);
}
else if (rollresult2 == 2)
{var dice22_mc:DICE2 = new DICE2();
Dice1_container_mc.addChild(dice22_mc);
}
else if (rollresult2 == 3)
{var dice23_mc:DICE3 = new DICE3();
Dice2_container_mc.addChild(dice23_mc);
}
else if (rollresult2 == 4)
{var dice24_mc:DICE4 = new DICE4();
Dice2_container_mc.addChild(dice24_mc);
}
else if (rollresult2 == 5)
{var dice25_mc:DICE5 = new DICE5();
Dice2_container_mc.addChild(dice25_mc);
}
else if (rollresult2 == 6)
{var dice26_mc:DICE6 = new DICE6();
Dice2_container_mc.addChild(dice26_mc);
}



trace(rollresult1, rollresult2, rollresulttotal)
stop()

learningflash
09-30-2009, 12:04 PM
container1 in the second bit of code.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum