PDA

View Full Version : Superclass getter/setter access problems


Stimpson
02-09-2004, 08:20 AM
For some little thingy I'm working on I noticed something odd concerning getter/setters and inheritance, well was odd to me anyways ;).

I declared some getter/setters in a base class linked to an movieclip acting as a component. And they work fine inside that base class. Inside the base class another clip is attached, also an component, which is linked to an class which in turn extends the base class.

Now there is no issue with the internal component as such, exept that it just can't seem to access to getter/setters of it's superclass. Calling them on _parent works, and all other 'normal' superclass methods also, as do static properties.

I tried the same out with classes not linked to movieclips, and there the superclass getter/setters work fine in the subclass. So I guess there must be something going on there. Anyone knows more about this?

ericlin
02-09-2004, 09:21 AM
Where and when did you access the getter/setter of the child clip ?

In the constructor of base class ?

Can you post a zip file ?

Stimpson
02-09-2004, 10:12 AM
No, never mind but thx ericlin. I was trying to access instance variables of the superclass with the getter/setters :rolleyes:. I'll just stick with static :).

ferdymania
02-09-2004, 06:17 PM
hi stimpy
i hope i understand you..
but i am not sure that you want to access the base class members...
imho , i f you extend a base class, then the extended class
has those variables in it..
so if i extend movieclip with a mymc class
then i have access to all movieclip members, methods, e.g
mymc._x
mymc.gotoAndStop(6)
etc etc..
just access the member variables thru the extended class...
i hope i got that right...
steve

Stimpson
02-10-2004, 06:07 AM
Yeah, problem was that the getter/setters worked as such, as in they existed in the subclass, exept that those variables they handled are only initialized when an instance of the base class is created. So accessing those getter/setters in the subclass returns undefined, since they bypass that instance of the superclass :).

ferdymania
02-10-2004, 06:30 AM
have you tried "super"
that will inititalise base class vars..
if you have

class base{
var x,y;
// constructor
function base(x,y){
//blah
}
}
// and a subby...
class Subby extends base{
var blah, blah2;
// constructor
function Subby(pblah, pblah2){
// call super
super(x,y);
this.blah = pblah;
this.blah2 = pblah2;
}
}


that is how it works as far as i know.. sorry if i am stating the obvioous.....
see ya mate
steve

oh p.s. are u using the flash get and set or conventional getters and setters.. ?
i dont trust flash's get and set methods...
to be honest i have been just accessing the member variables directly in my stuff and not worrying about private...
naughty me.. but i only do games.. so macht nix...
ROFL