Copy link to clipboard
Copied
Hi guys,
thanks to Hakan KIRIK, i've learnt hw to display random game characters as an individual using the code below:
var bearOne = new bearMC();
var bearTwo = new bearMC_2();
var bearThree = new bearMC_3();
var characters:Array = new Array(bearOne,bearTwo,bearThree);
var mcChar:MovieClip=characters[int(Math.random()*3)];
addChild(mcChar);
Currently, I'm looking deeper.. Let's say if I'm displaying the characters in different parts say Head, Body and Arms, etc.. How do I make sure when I randomize the characters, the correct part of each character is displayed correctly? Instead of characterOne's head appear with characterTwo's Body and characterThree's Arms for example.
Copy link to clipboard
Copied
If I understood you correctly, you can do something like
var bearOne:Array = [new BearHead1(), new BearBody1(), new BearArms1()];
or better still
var bearOne:Object = {head: new BearHead1(), body: new BearBody1(), arms: new BearArms1()};
or even better still
var bearOne:Bear = new Bear(1);
// "Bear" is a class defines bear's body parts depending on the argument
Copy link to clipboard
Copied
It isn't clear in what context you would be using body parts. If you are using arrays for the body parts the same way you do for the bears then you would want to store the random variable such that you could use it multiple times before you are done with a given bear. Otherwise, the 2nd suggestion to use an object to define the parts that belong to each bear would be a better storage vehicle.