Reputation: 1313
Say i have a variable in a general Global.as
file like this:
public static const test:String = "testString";
And in another file i want to override that variable. like following perhaps:
In File1.as
:
override var test:String = "testStringUpdated";
Ofcourse this isnt working. Does anyone know how to do this?
Is it actually possible with override
and is override
suposed to be used like this? Or is it only for overriding functions?
Thanks in advance.
Upvotes: 2
Views: 1914
Reputation: 39456
Generally you don't 'override' variables; simply change their value in the subclass (a constructor is a good place for this).
public function File1()
{
test = "testStringUpdated";
}
As for literally overriding, you can override setters and getters.
Simply set up your variable as a setter/getter combination in the base class, eg:
class Base
{
private var _test:String = "testString";
public function get test():String
{
return _test;
}
public function set test(value:String):void
{
_test = value;
}
}
Then in your subclass (File1), you can alter how the value of test
will be obtained, eg:
class File1 extends Base
{
override public function get test():String
{
return super.test + "Updated"; // testStringUpdated
}
}
Upvotes: 2