Code:
// Assign onRelease Events
for(i=0; i<cursors.length; i++) {
cursors[i][0].id = i;
cursors[i][0].onRelease = function() {
currentCursor = cursors[this.id][1];
I understand this.id corresponds with the strings in the array right?
what does cursors.length represent?
I have a (bad?) habit of using this naming convention. To me, it makes sense but it trips some people up who are trying to learn from my code. I should probably learn a better convention.
Anyway, there is a movieclip with an instance name of cursor (singular) on the stage. This contains the various cursors that will change when you click on it's cooresponding buttom.
In the Actionscript, there is also the cursors (plural) array. "length" is a property of the Array object. It tell us how many items are in the array. You could count how many items are in the array and hard code that value, but if you ever need to update it...it's more things to keep track of.
So, using cursors.length as the upper limit to the loop means that it will loop just enough times to assign the actions within the loop to the movieclips in the array. That way, you're not wasting any unnecessary resources.
In my example, cursors.length would equal 16. You can read more about the array.length property here.
Code:
cursors[i][0].id = i;
Yes, the above code assigns an arbitrary "id" property to each button in the menu. With ActionScript, you can add whatever made-up property you want -- cursors.favoriteColor = red, for example. What this does, is assigns the property to the movieclip object, and therefore making it available globally. Within a for loop, we have access to i, the variable. This also serves as an index to the array. For example, in the first loop, the function does this (subtituting i for 0...the first value within the loop):
Code:
cursors[0][0].id = 0;
Remember, arrays begin counting at 0. Also , remember we're using a associative array (i.e. an array within an array).
cursors[0] says...give me the first element within the cursor's array. The result is [tools.selection, "selection"].
cursors[0][0] says give me the first element with the first element of the cursors erray. In other words, the first element of [tools.selection, "selection"]; which is tools.selection.
Moving on, we're assigning an id property. So, we're setting the id property of the tools.selection movieclip to 0.
What's the point? Well, like I said, assigning a property makes that value global. The i within that loop is only available with in the loop. It is not available within that onRelease function. We need the index within the on release function to know which cursor to display after you click the button. So instead of using the i, we use the movieclip's id property which equals the same thing. Again, for illustration, purposes: the code broken down for the first loop
Code:
for(i=0; i<cursors.length; i++) {
cursors[i][0].id = i;
cursors[i][0].onRelease = function() {
currentCursor = cursors[this.id][1];
}
}
We've already figured out that the cursors[i][0].id = i line equals out to tools.selection.id = 0. Next, we're taking that same movieclip (tools.selection or cursors[i][0]) and assignin an onRelease event to it. That part should be familiar to you. Now, within the onRelease, we're setting a variable called currentCursor. We're setting currentCursor eq1al to cursors[this.id][1] -- or cursors[0][1] after the 1st loop. We also know that cursors[0] is equal to [tools.selection, "selection"]. cursors[0][1], then, refers to the second value in the array -- "selection". So, after you click on the button, the currentCursor variable is set equal to selection. The currentCursor variable then is used to set the label paramter of the changeCursor function.
Code:
tools.back.onRollOver
Actually, again there are multiple usages of the terms. I should have paid closer attention to what I was naming things. There is a bit of a disconnect between what things are called in the library and their instance names.
Menu in the library has an instance name of "tools"
Tools in the library has various instance names (selection, subselection, lasso, etc...)
If you open up the Menu (library name) movieclip, you should see a bunch of rectangles around each of the buttons. Each of those rectangles is actually an instance of the Tools(library name) movieclip. The Tools(library name) movieclip is just a rectangle with 0% transparency. It just serves as a hit state...there are no visuals in it.
So to go over it again (with instance names).
tools (contains everything) -> back (the image of the buttons)
tools -> selection (instance of the "tools" movieclip from the library)
tools -> subselect (another instance)
etc...
Hope that makes sense. Please let me know if it doesn't. Sorry for the confusing naming.
Code:
[tools.line, "crosshair"]
The array is set up in an associated array with the following syntax.
Code:
var cursors = [
[movieclip, "label"]
];
movieclip refers to the actual button. this is located within the tools (instance name) movieclip, hence the tools.xxx. label, as before, refers to the frame label within the cursor (singluar) movieclip that is associated with that button.
Is there a similarity with calling up classes?
I'm not sure I know what you mean here.
Bookmarks