<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: Notes on Moock’s EAS3.0 by Ashwinee - Class</title>
	<atom:link href="http://flnotes.wordpress.com/2007/10/28/notes-on-from-moock%e2%80%99s-eas30-by-ashwinee-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://flnotes.wordpress.com/2007/10/28/notes-on-from-moock%e2%80%99s-eas30-by-ashwinee-class/</link>
	<description>byte size learning</description>
	<pubDate>Fri, 29 Aug 2008 05:21:38 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: flnotes</title>
		<link>http://flnotes.wordpress.com/2007/10/28/notes-on-from-moock%e2%80%99s-eas30-by-ashwinee-class/#comment-2081</link>
		<dc:creator>flnotes</dc:creator>
		<pubDate>Thu, 01 Nov 2007 07:53:03 +0000</pubDate>
		<guid isPermaLink="false">http://flnotes.wordpress.com/2007/10/28/notes-on-from-moock%e2%80%99s-eas30-by-ashwinee-class/#comment-2081</guid>
		<description>Here is how Moock explains it in his book.

"for assigning an instance variable a new value, we
need to start by referring to an object. In this case, we use the local variable pet to
refer to the desired VirtualPet instance:
pet
Next, we write a dot:
pet.
Then, we write the name of the instance variable whose value we wish to assign—in
this case, petName:
pet.petName
Finally, we write an equals sign, then the value we wish to assign to the instance variable.
Let’s use “Stan”:
pet.petName = "Stan""


"we need to start our variable assignment by
referring to an object. In this case, that object is the new VirtualPet instance being
created. To refer to it, we use the keyword this, which is an automatically created parameter whose value is the object being created: this Within the body of a constructor method, the object being created is known as the current object. To refer to the current object, we use the keyword this.
After the keyword this, we write a dot, followed by the name of the instance variable whose value we wish to assign—in this case petName.
this.petName"

"Finally, we write an equals sign, then the value we wish to assign to the instance
variable:
this.petName = value
The value we wish to assign is the value associated with the name parameter. Hence,for value, we write simply: name.
this.petName = name
At runtime, ActionScript replaces name, in the preceding code, with the value passed to the VirtualPet constructor. That value is then assigned to the instance variable petName."

"Even though the eat( ) method body does not yet contain any code, with the preceding definition in place, we can already invoke the eat( ) method on a VirtualPet object, as shown in the following updated version of the VirtualZoo class:
package zoo {
public class VirtualZoo {
private var pet;
public function VirtualZoo ( ) {
this.pet = new VirtualPet("Stan");
// Invoke eat( ) on the VirtualPet object referenced by the
// variable pet
this.pet.eat( );
}
}
}
Within the eat( ) method body, we want to add 100 to the currentCalories variable of the object through which the eat( ) method was called. To refer to that object, we use the keyword this.
Within the body of an instance method, the object through which the
method is called is known as the current object. To refer to the current
object, we use the keyword this. Notice that the term “current object”
can refer to either the object being created in a constructor method or
the object through which an instance method was called."

3.1. Omitting the Keyword this
"In Chapter 1, we learned that the keyword this is used to refer to the current object within constructor methods and instance methods. For example, in the following code, the expression this.petName = name tells ActionScript to set the value of the instance variable petName on the object currently being created:
public function VirtualPet (name) {
this.petName = name;
}
Similarly, in the following code, the expression this.currentCalories +=
numberOfCalories tells ActionScript to set the value of the instance variable
currentCalories on the object through which the eat() method was invoked:
public function eat (numberOfCalories) {
this.currentCalories += numberOfCalories;
}
In code that frequently accesses the variables and methods of the current object, including the keyword this can be laborious and can lead to clutter. To reduce labor and improve readability, ActionScript generally allows the current object's instance variables and instance methods to be accessed without the keyword this.
Here's how it works: within a constructor method or an instance method, when ActionScript encounters an identifier in an expression, it searches for a local variable, parameter, or nested function whose name matches that identifier. (Nested functions are discussed in Chapter5.) If no local variable, parameter, or nested function's name matches the identifier, then
ActionScript automatically searches for an instance variable or instance method whose name matches the identifier. If a match is found, then the matching instance variable or instance method is used in the expression.
For example, consider what happens if we remove the keyword this from the eat() method,
as follows:
public function eat (numberOfCalories) {
currentCalories += numberOfCalories;
}
When the preceding method runs, ActionScript encounters numberOfCalories, and tries
to find a local variable, parameter, or nested function by that name. There is a parameter by that name, so its value is used in the expression (in place of numberOfCalories).
Next, ActionScript encounters currentCalories, and tries to find a local variable,parameter, or nested function by that name. No variable, parameter, or nested functionnamed currentCalories is found, so ActionScript then tries to find an instance variable or instance method by that name. This time, ActionScript's search is successful—the VirtualPet class does have an instance variable named currentCalories, so ActionScript
uses it in the expression. As a result, the value of numberOfCalories is added to the instance variable currentCalories.
Therefore, within the eat() method, the expression this.currentCalories and
currentCalories are identical.
For the sake of easier reading, many developers (and this book) avoid redundant uses of this. From now on, we'll omit this when referring to instance variables and instance methods. However, some programmers prefer to always use this, simply to distinguish instance variables and instance methods from local variables.
Note that use of the this keyword is legal within instance methods, constructor methods, functions, and code in the global scope only. 
Elsewhere, use of the keyword this generates a compile-time error.
NOTE
The process ActionScript follows to look up identifiers is known as identifier
resolution. As discussed in Chapter 16, identifiers are resolved based on the region
(or scope) of the program in which they occur."

So from the above explanation it is clear that:

var pet = new VirtualPet()  means pet is a local variable which refers to the newly created virtual pet object or instance.Thereafter when  AS3.0 finds pet, it understands that we are talking about the virtualPet instance.

pet.petName = "Stan"

Here petName is an instance variable (not a local variable because it is defined in the VirualPet class).
As pet is an instance of VirtualPet, it can access all the instance variables defined in the class. So petName variable of pet is assigned the value "Stan".

this.pet.petname = "Stan" 
In this case "this" keyword means the current object. Here the current object is the virtulPet object referred to by variable pet. And it is same as pet.petname = "Stan" .

AS 3.0 is now intelligent enough to find the object we are reffering without the help of keyword "this". So you can avoid using it in such cases "when referring to instance variables and instance methods".</description>
		<content:encoded><![CDATA[<p>Here is how Moock explains it in his book.</p>
<p>&#8220;for assigning an instance variable a new value, we<br />
need to start by referring to an object. In this case, we use the local variable pet to<br />
refer to the desired VirtualPet instance:<br />
pet<br />
Next, we write a dot:<br />
pet.<br />
Then, we write the name of the instance variable whose value we wish to assign—in<br />
this case, petName:<br />
pet.petName<br />
Finally, we write an equals sign, then the value we wish to assign to the instance variable.<br />
Let’s use “Stan”:<br />
pet.petName = &#8220;Stan&#8221;"</p>
<p>&#8220;we need to start our variable assignment by<br />
referring to an object. In this case, that object is the new VirtualPet instance being<br />
created. To refer to it, we use the keyword this, which is an automatically created parameter whose value is the object being created: this Within the body of a constructor method, the object being created is known as the current object. To refer to the current object, we use the keyword this.<br />
After the keyword this, we write a dot, followed by the name of the instance variable whose value we wish to assign—in this case petName.<br />
this.petName&#8221;</p>
<p>&#8220;Finally, we write an equals sign, then the value we wish to assign to the instance<br />
variable:<br />
this.petName = value<br />
The value we wish to assign is the value associated with the name parameter. Hence,for value, we write simply: name.<br />
this.petName = name<br />
At runtime, ActionScript replaces name, in the preceding code, with the value passed to the VirtualPet constructor. That value is then assigned to the instance variable petName.&#8221;</p>
<p>&#8220;Even though the eat( ) method body does not yet contain any code, with the preceding definition in place, we can already invoke the eat( ) method on a VirtualPet object, as shown in the following updated version of the VirtualZoo class:<br />
package zoo {<br />
public class VirtualZoo {<br />
private var pet;<br />
public function VirtualZoo ( ) {<br />
this.pet = new VirtualPet(&#8221;Stan&#8221;);<br />
// Invoke eat( ) on the VirtualPet object referenced by the<br />
// variable pet<br />
this.pet.eat( );<br />
}<br />
}<br />
}<br />
Within the eat( ) method body, we want to add 100 to the currentCalories variable of the object through which the eat( ) method was called. To refer to that object, we use the keyword this.<br />
Within the body of an instance method, the object through which the<br />
method is called is known as the current object. To refer to the current<br />
object, we use the keyword this. Notice that the term “current object”<br />
can refer to either the object being created in a constructor method or<br />
the object through which an instance method was called.&#8221;</p>
<p>3.1. Omitting the Keyword this<br />
&#8220;In Chapter 1, we learned that the keyword this is used to refer to the current object within constructor methods and instance methods. For example, in the following code, the expression this.petName = name tells ActionScript to set the value of the instance variable petName on the object currently being created:<br />
public function VirtualPet (name) {<br />
this.petName = name;<br />
}<br />
Similarly, in the following code, the expression this.currentCalories +=<br />
numberOfCalories tells ActionScript to set the value of the instance variable<br />
currentCalories on the object through which the eat() method was invoked:<br />
public function eat (numberOfCalories) {<br />
this.currentCalories += numberOfCalories;<br />
}<br />
In code that frequently accesses the variables and methods of the current object, including the keyword this can be laborious and can lead to clutter. To reduce labor and improve readability, ActionScript generally allows the current object&#8217;s instance variables and instance methods to be accessed without the keyword this.<br />
Here&#8217;s how it works: within a constructor method or an instance method, when ActionScript encounters an identifier in an expression, it searches for a local variable, parameter, or nested function whose name matches that identifier. (Nested functions are discussed in Chapter5.) If no local variable, parameter, or nested function&#8217;s name matches the identifier, then<br />
ActionScript automatically searches for an instance variable or instance method whose name matches the identifier. If a match is found, then the matching instance variable or instance method is used in the expression.<br />
For example, consider what happens if we remove the keyword this from the eat() method,<br />
as follows:<br />
public function eat (numberOfCalories) {<br />
currentCalories += numberOfCalories;<br />
}<br />
When the preceding method runs, ActionScript encounters numberOfCalories, and tries<br />
to find a local variable, parameter, or nested function by that name. There is a parameter by that name, so its value is used in the expression (in place of numberOfCalories).<br />
Next, ActionScript encounters currentCalories, and tries to find a local variable,parameter, or nested function by that name. No variable, parameter, or nested functionnamed currentCalories is found, so ActionScript then tries to find an instance variable or instance method by that name. This time, ActionScript&#8217;s search is successful—the VirtualPet class does have an instance variable named currentCalories, so ActionScript<br />
uses it in the expression. As a result, the value of numberOfCalories is added to the instance variable currentCalories.<br />
Therefore, within the eat() method, the expression this.currentCalories and<br />
currentCalories are identical.<br />
For the sake of easier reading, many developers (and this book) avoid redundant uses of this. From now on, we&#8217;ll omit this when referring to instance variables and instance methods. However, some programmers prefer to always use this, simply to distinguish instance variables and instance methods from local variables.<br />
Note that use of the this keyword is legal within instance methods, constructor methods, functions, and code in the global scope only.<br />
Elsewhere, use of the keyword this generates a compile-time error.<br />
NOTE<br />
The process ActionScript follows to look up identifiers is known as identifier<br />
resolution. As discussed in Chapter 16, identifiers are resolved based on the region<br />
(or scope) of the program in which they occur.&#8221;</p>
<p>So from the above explanation it is clear that:</p>
<p>var pet = new VirtualPet()  means pet is a local variable which refers to the newly created virtual pet object or instance.Thereafter when  AS3.0 finds pet, it understands that we are talking about the virtualPet instance.</p>
<p>pet.petName = &#8220;Stan&#8221;</p>
<p>Here petName is an instance variable (not a local variable because it is defined in the VirualPet class).<br />
As pet is an instance of VirtualPet, it can access all the instance variables defined in the class. So petName variable of pet is assigned the value &#8220;Stan&#8221;.</p>
<p>this.pet.petname = &#8220;Stan&#8221;<br />
In this case &#8220;this&#8221; keyword means the current object. Here the current object is the virtulPet object referred to by variable pet. And it is same as pet.petname = &#8220;Stan&#8221; .</p>
<p>AS 3.0 is now intelligent enough to find the object we are reffering without the help of keyword &#8220;this&#8221;. So you can avoid using it in such cases &#8220;when referring to instance variables and instance methods&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Fact</title>
		<link>http://flnotes.wordpress.com/2007/10/28/notes-on-from-moock%e2%80%99s-eas30-by-ashwinee-class/#comment-2067</link>
		<dc:creator>The Fact</dc:creator>
		<pubDate>Mon, 29 Oct 2007 13:33:42 +0000</pubDate>
		<guid isPermaLink="false">http://flnotes.wordpress.com/2007/10/28/notes-on-from-moock%e2%80%99s-eas30-by-ashwinee-class/#comment-2067</guid>
		<description>What's not to understand? Well i won't try to explain it myself, just afraid to be wrong i guess. Looking forward for the explanation.</description>
		<content:encoded><![CDATA[<p>What&#8217;s not to understand? Well i won&#8217;t try to explain it myself, just afraid to be wrong i guess. Looking forward for the explanation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: libyano</title>
		<link>http://flnotes.wordpress.com/2007/10/28/notes-on-from-moock%e2%80%99s-eas30-by-ashwinee-class/#comment-2063</link>
		<dc:creator>libyano</dc:creator>
		<pubDate>Sun, 28 Oct 2007 18:34:50 +0000</pubDate>
		<guid isPermaLink="false">http://flnotes.wordpress.com/2007/10/28/notes-on-from-moock%e2%80%99s-eas30-by-ashwinee-class/#comment-2063</guid>
		<description>Hi ... 

i need to ask about this point exactly because i have the book and i did n't understand it  

(Within the body of the constructor method, this refers to the object created i.e. itself.) 

which object refer to instanse varible? and when we use this.pet.eat(); which object we refer to?

Thanks</description>
		<content:encoded><![CDATA[<p>Hi &#8230; </p>
<p>i need to ask about this point exactly because i have the book and i did n&#8217;t understand it  </p>
<p>(Within the body of the constructor method, this refers to the object created i.e. itself.) </p>
<p>which object refer to instanse varible? and when we use this.pet.eat(); which object we refer to?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>
