有没有办法子类化并重写自定义命名空间中的方法?
假设我有一个类,其方法在公共、受保护或内部以外的命名空间中定义...
package com.foo.bar
{
import com.foo.my_name_space
public class bar
{
private var _vabc:String
private var _v123:String
protected function set123(val:String):void{
_v123 = val;
}
my_name_space function setABC(val:String):void{
_vabc = val;
}
}
}
现在我想在子类中扩展和覆盖它...
package com.foo
{
import com.foo.bar.bar
import com.foo.my_name_space
public class foo extends bar
{
override protected function set123(val:String):void{
super.set123(val);
}
.... ????? ...
}
}
很容易覆盖受保护、公共等方法,但是有吗重写名称空间 *my_name_space* 中定义的 setABC 方法的方法?
我尝试了以下语法,它似乎通过了 FlashBuilder 预编译器检查,但不起作用。
use namespace my_name_space override function my_name_space::setABC(val:String):void
我尝试了许多其他语法组合,但大多数甚至都无法通过预编译检查。 (许多有某种类型的命名空间错误)我有一种感觉这是不可能的,但想知道是否有人有任何想法?
Say I have a class with a method defined in a namespace other than public, protected or internal...
package com.foo.bar
{
import com.foo.my_name_space
public class bar
{
private var _vabc:String
private var _v123:String
protected function set123(val:String):void{
_v123 = val;
}
my_name_space function setABC(val:String):void{
_vabc = val;
}
}
}
Now I want to extend and override this in a subclass...
package com.foo
{
import com.foo.bar.bar
import com.foo.my_name_space
public class foo extends bar
{
override protected function set123(val:String):void{
super.set123(val);
}
.... ????? ...
}
}
Easy enough to override protected, public etc. methods, but is there a way to override the setABC method defined in the name space *my_name_space* ?
I've tried the following syntax, which seems to pass the FlashBuilder pre-compiler check but doesn't work.
use namespace my_name_space override function my_name_space::setABC(val:String):void
I've tried a number of other syntax combinations but most wouldn't even pass the pre-compile check. (many with some type of namespace error) I have a feeling this isn't possible but wonder if anyone might have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
詹姆斯的回答是对的。您只是未能正确添加
use namespace
指令。此示例按预期工作:James' answer is right. You just failed to add the
use namespace
directive appropriately. This example works as expected:这应该有效
This should work