I'm trying to learn OOP on my own using AS3, and I've given myself a challenge for that purpose. Because it's quite a complex one, I'm trying to understand useful tools in AS3.
At any rate, the function.call
(AS3 API's doc. here) method looks quite interesting, and I think I would be able to put that into use, however I apparently don't understand fully what it does and how it works. JavaScript seems to have an equivalent that looks pretty straightforward to use. (I saw this other thread with the same question as mine, but in JS)
Here's an example of what I thought the function.call
would do.
package
{
import flash.display.Sprite
public class Main extends Sprite
{
public var foo:Foo;
public var bar:Bar;
public function Main()
{
foo = new Foo();
bar = new Bar();
trace(bar.barProperty); //Hello World!
//I expect the 'foo.BarProp' to be called with this==bar.
foo.value = foo.BarProp.call(bar); //ReferenceError: Error #1069: Property barProperty not found on Main.as$0.Foo and there is no default value.
trace(foo.value); //Expected output: Hello World!
}
}
}
class Foo {
public var value:String;
public function Foo() {}
public function BarProp():String {
return this.barProperty;
}
}
class Bar {
public var barProperty:String = "Hello World!";
public function Bar() {}
}
All right, so what is it that I'm just not getting?