I am just learning AS3 and am reading up on instantiating and object. The code from the Quickstart book makes about 75% sense to me, as it covers syntax in the previous section. However, like every damn intro to code on the planet, it throws in new, unexplained syntax:
var myMC:MovieClip= new MovieClip();
Line 1: I get var=myMC is defining a variable.. I don't however understand the colon... What does the colon do and what does MovieClip mean? I'd assume that new MovieClip() is a method...Right?
Line 2 and 3: makes sense. Adding property value to the x and y properties of myMC
Line 4: addChild(myMC); the book says this is to add the instance to the 'display'. It's the first time it mentioned 'display'. What is that? The stage? Im not fully clear on what addChild means literally too. Is MovieClip a 'parent class' and the addChild is making an offspring?
Also, if I put a line 5 and repeat addChild, do I get a second MovieClip with the same properties or do I have to make a new instance name?
Please don't tell me that this particular code is a poor way to do things and go down a long explanation of why and how you'd write the code. I am just trying to get the fundamentals here so I can learn to grow my knowledge...
You are creating an instance of a movie clip called myMC, MovieClip is the class and newMovieClip means you are adding a new one, then you are positioning that movie clip, then you are displaying it with addChild.
Yes if you used several addChild with same instance name then, you would display several of the same mc's, they would however basically overlay each other and not be visible unless you created different instances of the same mc with unique instance names and different positions basically repeating the whole code block but with a unique name and position.
Your are basically correct in your assumptions.
the "var" prefix means you're about to create a variable (and flash is going to allocate space for it). the keyword after the colon is the "type" or "class" of the variable.
the displaylist is what you see on-stage. in as3, until objects are added to the displaylist they are not displayed. when you create items in the authoring environment they are automatically added to the displaylist and will be displayed. nothing created with actionscript will be visible until it's explicitly added to the displaylist with addChild() or addChildAt().
the flash help files are very helpful. you should check them to fill in gaps that you're finding by studying other sources.