Where you declare a variable will determine the scope of the variable,
that is, how long that variable stays in memory for use and from where
it can be accessed.

In your first class, the variables declared above the function can be
accessed in other parts of the class.

In your second class the myName variable is a parameter to the function,
and is only available and in memory while in the function.  Once
trace("myName") is executed and the function is complete, the myName
variable is gone and can not be accessed by any other part of the class.

In your third class, you have declared the variable within the function.
Similar to your second class, the myName variable will be gone when the
function is finished executing and can not be accessed from elsewhere in
the class.

If you think other functions or parts of the class will need to know
about a variable then its best to declare it outside of the function (as
a coding standard this is usually done above the other functions and
constructor) like you have done in your first example.

Hope that helps!

~D.C. Holth


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Omar
Fouad
Sent: Thursday, February 15, 2007 4:50 AM
To: Flashcoders mailing list
Subject: [Flashcoders] AS2 Question

Hi list i am new to AS2 and in writing classes and there is a question
that
i would like to do:

assume i have the following class

Class myClass {

var myName:String;
var myAge:Number:
var myJob:String;

       function setName(name) {
             name = myName;
       }
}
here i declared the myName variable at the beginning

in this class than:

Class myClass {

       function setName(myName:String) {

             trace("myName");
       }
}
and in this other class:

 Class myClass {

       function setName(name) {
             var myName:String;
             name = myName;
       }
}
now the question is (even if it maight seen silly but i don't get the
concept yet), what is the difference between declaring the variables
before
methods (after the class declaration) and declaring them inside the
method
itself, or even in the method parameters???

Thanks in advance

--
Omar Fouad - Digital Emotions...
-
Love is always patient and kind. It is never jealous. Love is never
boastful
nor conceited It is never rude or selfish. It does not take offense and
is
not resentful. Love takes no pleasure in other people's sins...but
delights
in the truth. It is always ready to excuse, to trust, to hope... and to
endure... whatever comes.
----------------------------------------
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

This e-mail and its attachments are intended only for the use of the 
addressee(s) and may contain privileged, confidential or proprietary 
information. If you are not the intended recipient, or the employee or agent 
responsible for delivering the message to the intended recipient, you are 
hereby notified that any dissemination, distribution, displaying, copying, or 
use of this information is strictly prohibited. If you have received this 
communication in error, please inform the sender immediately and delete and 
destroy any record of this message. Thank you.
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to