Okay I am only at the very beginning and I want to make certain that I go through this understanding everything that can so maybe I won’t have to ask as many questions in the forums and can start answering more. In this part:
[SIZE=1][COLOR=Navy]The code for making a standard generic object in Flash is as follows:
myObject = new Object();
The variable myObject then becomes a object variable which can then have more variables added to it using dot syntax like so.[/COLOR][/SIZE]
Is myObject the actual name of the variable and the = new Object simply stating that there is a new object called myObject?
correct. “myObject” is the variable name. The variable “myObject” is of the type Object. It is defined as such because it was set to equal (=) “new Object()”
So “new Object()” is the command that creates the actual object in Flash. It is basically always the same for a generic object type (there is a shorthand version which I think I mention in there as well). “myObject” is your own personal variable name which can be anything. Its the container for keeping the object created so that you may use that object any way you see fit through that “myObject” variable.
new and Object are two separate keywords in Flash. If you omit the space, you turn it into one keyword newObject <- and that isnt understood by Flash. In using
new Object(5);
you create a generic object with a base value of 5 - or really, a number object whose value is 5. Flash sees both the new keyword and the Object keyword seperately, understands them as such and creates the object as instructed. Then you get 5 + 1 is 6. If you use
newObject(5);
Flash sees that as one word, “newObject” and doesn’t know what newObject is in Flash terms. Because of that, the return value is actually undefined or “nothing.” When you add 1 to nothing (Flash MX) you get 1.
I don’t understand how the trace is returning level zero when the instance of the MovieClip is created in level one. (or at least I think that is what is happening)
that is correct. Flash, when tracing movieclips, returns a path to that movieclip as its set within the Flash movie. Because you can load other Movies into Flash with their own _root timelines, Flash defaults each trace path to their respective levels. _level0 represents _root of the main timeline. _level1 would be _root of a swf loaded into level 1.
Senocular you must have been submitting a reply at the same time I was. So as far as my question concerning the level thing, it is just saying that the temp movieclip can be accessed through the main timeline even though it was loaded into level1 (of the main timeline) right?
The current traces are correct (though for the second part you probably mean new Object(5)). Because the first compares basic variable types, or non-object variables, their values are compared and true is traced because 5 equals 5. When you’re dealing with objects, however, their comparative value is the object reference and not the value of that object itself. This means that when two objects are compared, their references are compared, or the “value” of the actual variable itself… and if that variable is an object, then its a reference to the object in Flash’s memory since its represented as a complex data type.
when you make your own custom objects, those which dont have a base value like Number objects do, you can create your own valueOf methods to give you whatever value you want. valueOf just gives you a function to manually get an object’s “value.” When you’re dealing with number variables, its usually pretty pointless because the variables are their values, but it can be helpful when making custom objects to give that object a value of its own based on whatever you want it to have (supplied through the valueOf function). I think its covered more as you read throughout the tutorial.
As you can see, this function uses this to directly access the current object’s (myArray’s) array elements as this refers to the array itself. Then, using a local temporary variable temp, it is able to internally switch the two values of those array elements. The trace after the function call confirms its success on the myArray variable.[/SIZE][/COLOR]
In this example, why is the variable temp needed to switch values :h:
do you know a way to do it without using a temp variable? Its just a necessity of the action. You need the temporary variable because if you assign 1 to 0 the original value of 0 is lost thereby not giving you a method for putting that original 0 value into 1. the temp variable saves the value so when its needed it can be put respectively into the other variable.
No I don’t know how to do it without a temp varible…actually I don’t know how to do it all at :crazy:
That’s why I am asking all the questions cause I am trying to understand everything :drool: