PDA

View Full Version : AS2 "Interface" inheritance example?



jewelsmith
July 1st, 2004, 03:22 AM
Hi,
I am intrigued by the new Interface Class. But I can not get my head around how to use it. I have an idea about creating and running rules/functions dynamically at runtime.
What do you think?
Flash Newbie

kaneda
July 1st, 2004, 03:34 AM
http://www.simonwacker.com/blog/archives/000044.php#more

jewelsmith
July 1st, 2004, 04:01 AM
Hey Thanks!!:be:

I think I understand this except 2 things.

In the code "public function stop(Void):Void {}"
Does the "stop(Void):Void " show the inheritance?
If so how do you indicate the parameters that should/could be passed?:puzzle:

code example from Wacker
interface Engine {
public function start(Void):Void;
public function stop(Void):Void;
}
interface Car {
public function setEngine(newEngine:Engine):Void;
}
class CarMini implements Car {
private var engine:Engine;
public function CarMini(newEngine:Engine) {
setEngine(newEngine);
}
public function setEngine(newEngine:Engine):Void {
engine = newEngine;
}
}

class FourStrokeEngine implements Engine {
public function FourStrokeEngine(Void) {
}
public function start(Void):Void {
// start the lame four stroke engine
}
public function stop(Void):Void {
// stop the lame four stroke engine
}
}

kaneda
July 1st, 2004, 04:27 AM
Interfaces are as2 compiler directives. This means you define that a class that implements your interface has the same methods like you defined (nothing more). Otherwise said: You make sure that a different classes have the same methods and use the same Attributes.

If you have a method like "stop(Void):Void" within your interface your class (that implements it) is not allowed to take parameters.

If you want that all your implementations use parameters with a method you can do:



interface Animal {
public function eat(f:Food):Void;
}


so all implementations have to take food.

jewelsmith
July 1st, 2004, 11:11 AM
BTW since you are in Linz my mother is from Lumbach(sp?) very beautiful area!

Thank you!