Catching game video tutorial 1 question
My question is about the following function:
public function newObject(e:Event) {
var goodObjects:Array = ["Circle1","Circle2"];
var badObjects:Array = ["Square1","Square2"];
if(Math.random() < .5) {
var r:int = Math.floor(Math.random()*goodObjects.length);
var classRef:Class = getDefinitionByName(goodObjects[r]) as Class;
var newObject:MovieClip = new classRef();
newObject.typestr = "good";
} else {
r = Math.floor(Math.random()*badObjects.length);
classRef = getDefinitionByName(badObjects[r]) as Class;
newObject = new classRef();
newObject.typestr = "bad";
}
newObject.x = Math.random()*500;
addChild(newObject);
objects.push(newObject);
setNextObject();
}
You explained this line very fast, I could not understand what you said
if(Math.random() < .5) {
and maybe I just do not understand 'Variable Scope' in Action Script 3 but the following lines completely throw me off and have been driving me CRAZY please explain to me how these variables even exist? they are in an else statement.. the declaration is in the if... that does not look right to me.. I can not make any sense of it at all. I have a learning disability, this small detail is making me so angry! help!
r = Math.floor(Math.random()*badObjects.length);
classRef = getDefinitionByName(badObjects[r]) as Class;
newObject = new classRef();
newObject.typestr = "bad";
Copyright Gary Rosenzweig
