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:
:sen: well itâs already past advanced for me, but I figure it canât hurt. I am waiting on my Macromedia Flash MX Designerâs AS Reference guide (slow mailâŚ) so why not try to get as much out of your OOP Basics as I can? Iâm not driving you crazy with my questionsâŚ(which may or may not even be too relevant to the lessons) am I?
not really, I just think it would be easier for you if you had some simpler background to work off of. If youâre just starting off, you may just be confusing yourself with all this junk here.
Yes you are probably right. I have been working with Flash for about 2 years now, BUT I really only get to use it once a year for anything worth while so I donât get much practice. I figure I will follow through with it anyway and see what I can get out of it.