|  | Class scope |  | |
| | | tegnegi |  |
| Posted: Fri Aug 22, 2008 2:18 pm Post subject: Class scope |  |
I just cant understand how can we retrieve the private variables of a class through other class. To explain in detail i ve 2 class files Person and Person2. Here is the code inside them.
Person.as class file
class Person { private var fn:String; private var ln:String; function Person() { fn = "myFirstName"; ln = "myLastName"; } }
Person2.as class file
class Person2 { private var root:MovieClip; function Person2(mov) { root = mov; trace(root.pObj.fn); } }
The fla file that calls the class has this code on its first frame:
var pObj:Person=new Person() trace(pObj.fn) var p2:Person2=new Person2(this) //myFirstName
My question is how Person2 class can access Person class private variable. |
| |
| | | kglad |  |
| Posted: Fri Aug 22, 2008 5:02 pm Post subject: Re: Class scope |  |
it can't. you haven't set it up for that.
person2 instances have no access to person instances and fn and ln are properties of person instances. |
| |
| | | tegnegi |  |
| Posted: Wed Aug 27, 2008 5:23 am Post subject: Re: Class scope |  |
But if you take the code and try it does happen as i ve mentioned. Moreover pObj is Person2 instance and not Person1 instance, but even then Person2 instance cant have access to its class private variables. Why is it happening here? I ll suggest you to try it. |
| |
|
|