# Question about AS1 OOP: Object Basics by Senocular

**URL:** https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974
**Category:** flash
**Created:** [July 27, 2004, 2:10pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974 "2004-07-27T14:10:11Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![jillymo](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jillymo](https://forum.kirupa.com/u/jillymo)
#### Post date: [July 27, 2004, 2:10pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/1 "2004-07-27T14:10:11Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 2:21pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/2 "2004-07-27T14:21:03Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 2:26pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/3 "2004-07-27T14:26:36Z")

</div>

:hugegrin: Thanks Senocular! Back to your tutorial…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 2:30pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/4 "2004-07-27T14:30:55Z")

</div>

np 😉 Feel free to ask any more questions as they arise.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 3:37pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/5 "2004-07-27T15:37:32Z")

</div>

Okay well I’m feeling free…

:jail: (okay maybe not quite so free)

Anyway, how come if I **do not** put a space between new and object in the AS below, it traces one instead of six?

[COLOR=Navy][SIZE=1]myObject = new Object(5);  
trace(myObject + 1); // traces 6 [/SIZE] [/COLOR]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 3:47pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/6 "2004-07-27T15:47:04Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 4:06pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/7 "2004-07-27T16:06:28Z")

</div>

I see. Once again thank you for the explanation. :pleased:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 4:37pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/8 "2004-07-27T16:37:24Z")

</div>

Okay in this example:

[COLOR=Navy][SIZE=1]// create a temporary movieclip  
this.createEmptyMovieClip(“temp”,1);

// assign a reference variable  
tempRef = temp;  
trace(temp); // traces \_level0.temp  
trace(tempRef); // traces \_level0.temp [/SIZE] [/COLOR]

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)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 4:49pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/9 "2004-07-27T16:49:50Z")

</div>

i believe that \_level0 is \_root, and so it’s just saying you can acces temp from \_level0 (\_root).temp

but, i dunno oop, so… 🙂

:p:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 5:12pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/10 "2004-07-27T17:12:56Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 5:13pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/11 "2004-07-27T17:13:21Z")

</div>

okay well what about this one- would this be right?

[COLOR=Navy][SIZE=1]num1 = 5;  
num2 = 5;  
trace(num1 == num2); // traces true

num1 = {5};  
num2 = {5};  
trace(num1 == num2); // traces false[/SIZE][/COLOR]

Or would they both trace true because the object is a number? And if they would not both trace true could someone please explain why?

:thumb:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 5:15pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/12 "2004-07-27T17:15:49Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 5:34pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/13 "2004-07-27T17:34:28Z")

</div>

> [@jillymo](#):
>
> 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?

yes, any movieclip/movie can access movieclips in other levels of that same movie.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 5:39pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/14 "2004-07-27T17:39:19Z")

</div>

> [@jillymo](#):
>
> okay well what about this one- would this be right?
> 
> [COLOR=Navy][SIZE=1]num1 = 5;  
> num2 = 5;  
> trace(num1 == num2); // traces true
> 
> num1 = {5};  
> num2 = {5};  
> trace(num1 == num2); // traces false[/SIZE][/COLOR]
> 
> Or would they both trace true because the object is a number? And if they would not both trace true could someone please explain why?
> 
> :thumb:

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 6:46pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/15 "2004-07-27T18:46:46Z")

</div>

What is the difference between the two expressions below (where they both trace 50)?

[COLOR=Navy][SIZE=1]// basic number  
num = 5;  
trace(num.valueOf()); // traces 5 [/COLOR]

[SIZE=1][COLOR=DarkRed]// math expressions use valueOf  
trace(num \* 10); // traces 50;  
trace(num.valueOf() \* 10); // traces 50; [/SIZE] [/COLOR] [/SIZE]

Why would you use one over the other or are they different?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 27, 2004, 7:06pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/16 "2004-07-27T19:06:49Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 28, 2004, 3:19pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/17 "2004-07-28T15:19:27Z")

</div>

[COLOR=Navy][SIZE=1]myArray = [1,2];  
myArray.switchValues = function(){  
var temp = this[0];  
this[0] = this[1];  
this[1] = temp;  
};  
trace(myArray); // traces 1,2  
myArray.switchValues();  
trace(myArray); // traces 2,1

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:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 28, 2004, 5:22pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/18 "2004-07-28T17:22:24Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 28, 2004, 5:33pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/19 "2004-07-28T17:33:48Z")

</div>

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:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 28, 2004, 5:52pm UTC](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974/20 "2004-07-28T17:52:01Z")

</div>

are you sure you want to be reading that tutorial? 😉 I think it will begin to get a little advanced for you fairly quickly.

[Next page](https://forum.kirupa.com/t/question-about-as1-oop-object-basics-by-senocular/58974.md?page=2)
