PDA

View Full Version : OOP inheritance



Rezmason
September 25th, 2007, 11:47 AM
Greetings. It's been a while, but I've been caught up in all sorts of things. How've you been? How're the kids?

I'm subclassing DisplayObject (not directly), but I'm doing it in an interesting way, and I want to override some of the properties of DisplayObject, or remove them altogether. For instance, the rotation property of DisplayObject is relatively worthless in my new class, but there is another public property of my class very similar to rotation that I'd really, really like to call rotation. Is this at all possible?

senocular
September 25th, 2007, 12:05 PM
yes, because rotation is a getter/setter, you can override it (using the override keyword) with your own custom getter and setters for the rotation property. Your definition will then be used instead of the default. If at any time you want to access the default in your class, you can use super.rotation. :)

public override function get rotation():Number {
return 0;
}
public override function set rotation(value:Number):void {
height = rotation; // wheeee!
}

hakukaji
September 25th, 2007, 12:07 PM
what happens when you just try it? by putting a public rotation property in your class?

Rezmason
September 25th, 2007, 01:19 PM
yes, because rotation is a getter/setter, you can override it (using the override keyword) with your own custom getter and setters for the rotation property. Your definition will then be used instead of the default. If at any time you want to access the default in your class, you can use super.rotation. :)

That is awesome. Are most properties of built-in objects in the Flash library getters and setters?


what happens when you just try it? by putting a public rotation property in your class?

I get a compile error. There's some sort of overlap. But overriding a getter/setter is a cakewalk. Problem solved.

hakukaji
September 25th, 2007, 01:21 PM
awesome

senocular > me :puzzle:

senocular
September 25th, 2007, 01:27 PM
That is awesome. Are most properties of built-in objects in the Flash library getters and setters?

Most, but not all. x and y in the Point class, for example, are not getter/setters so they cannot be overridden. The reason for this is performance (a lot of the geom classes are like this to be speedy). I think most if not all in DisplayObject, though, are getter/setters so you can go wild with those. If you don't know and want to check, look at the documentation; it shows the implementation (whether a variable or a getter/setter property).

Rezmason
September 25th, 2007, 07:12 PM
Thanks, senocular!™


awesome

senocular > me :puzzle:

Don't let sen's omniscience get you down. After all, he kind of does it for a living.

hakukaji
September 26th, 2007, 11:46 AM
Thanks, senocular!™



Don't let sen's omniscience get you down. After all, he kind of does it for a living.

That's good, I just started with AS a month ago. PHP however, that's my area! :D

tpspoons
September 27th, 2007, 01:38 PM
Most, but not all. x and y in the Point class, for example, are not getter/setters so they cannot be overridden. The reason for this is performance (a lot of the geom classes are like this to be speedy). I think most if not all in DisplayObject, though, are getter/setters so you can go wild with those. If you don't know and want to check, look at the documentation; it shows the implementation (whether a variable or a getter/setter property).

Couldn't find a good explanation anywhere, what are getters and setters?



What is all this? V
.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #f5f5ff; background-image: none; color: #000000; font-family: Verdana, Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }

hakukaji
September 27th, 2007, 02:18 PM
getters and setters are public methods that are used to access and set a private property.


as far as the "off-topic" stuff, looks like some css.

tpspoons
September 27th, 2007, 02:25 PM
Thanks, but I got that it was css, I guess I was asking why it kept appearing when I edit a post (?

.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #f5f5ff; background-image: none; color: #000000; font-family: Verdana, Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #f5f5ff; background-image: none; color: #000000; font-family: Verdana, Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }.wysiwyg { background-attachment: scroll; background-repeat: repeat; background-position: 0% 0%; background-color: #f5f5ff; background-image: none; color: #000000; font-family: Verdana, Arial, Arial; font-style: normal; font-variant: normal; font-weight: 400; font-size: 10pt; line-height: normal } p { margin: 0px; }

hakukaji
September 27th, 2007, 02:58 PM
haha not sure, what browser are you using?

tpspoons
September 27th, 2007, 03:02 PM
Opera

hakukaji
September 27th, 2007, 03:51 PM
odd, Im using opera, does this happen everytime?

graylensman
September 27th, 2007, 04:13 PM
awesome

senocular > me :puzzle:

senocular > everyone :)