我怎样才能到达超类的文本元素?
我有以下场景:
我有一个 MovieClip,我为其创建了一个名为 A 的链接。
class A extends B{
}
class B extends C {
}
class C extends MovieClip {
public function C() {
// from the constructor of C i want to be able to reach the elements in Class a.
// for example I have some text elements that I want to change.
// super.super is not allowed.
}
}
允许什么?我该如何解决这个问题?
更新
好吧,这是一个确切的场景,但一个更简单的场景,我仍然无法解决。
最初的场景是,我有一个名为 user_bg_me
的 MovieClip,它有一个名为 user_bg_me
的链接,该链接扩展了 user_bg_generic
,该链接扩展了
内部的 “MovieClip” user_bg_generic
类我希望能够修改影片剪辑本身内的元素。使用 super.element_name 会出现找不到该属性的错误。
有什么想法吗?
I have the following scenario:
i have a MovieClip and I created a linkage for it named A.
class A extends B{
}
class B extends C {
}
class C extends MovieClip {
public function C() {
// from the constructor of C i want to be able to reach the elements in Class a.
// for example I have some text elements that I want to change.
// super.super is not allowed.
}
}
what is allowed? how can I resolve the issue ?
update
ok this is an exact scenario but a more simple one that I still wasn't able to resolve.
The original scenario is that I have a MovieClip called user_bg_me
that has a linkage named user_bg_me
that extends user_bg_generic
that extends 'MovieClip`
inside user_bg_generic
class i want to be able to modify elements inside the movie clip itself. using super.element_name provides an error that the property isn't found.
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您可能对继承的工作原理感到困惑;特别是父类和子类之间的关系。
父类可以以子类可以使用的方法和属性的形式公开行为,这是一个非常简单的实际示例:
我们现在可以创建此父类的子类这将获得父类的可见行为(函数和属性):
现在,这种关系(子类可以访问它们扩展的父类的函数和属性)仅以一种方式起作用。也就是说,父类不知道其子类可能选择声明的函数和属性,因此,以下代码将不起作用:
现在,让我们看看如何解决您尝试的问题从父类访问属于 FLA 中实例的 TextField:
现在,您的 FLA 中可以有任意多个实例,其中链接扩展了该父类。您只需确保它们有一个实例名称为“txtName”的 TextField,以便父类可以执行其操作。
希望这有帮助:)
I think you may be getting confused over how inheritance works; in particular the relationship between Parent and Child classes.
A Parent class can expose behaviours in the shape of methods and properties that child subclasses can make use of, here'a very simple example of that in action:
We can now create a child class of this Parent class which will gain the Parent's visible behaviours (functions and properties):
Now, this relationship, where Child classes can access the function and properties of the Parent classes they extend only works one way. That is to say, a Parent class has no knowledge of the functions and properties that its children may choose to declare, so as a result, the following code will not work:
Now, let's look at how we could possibly solve your problem of trying to access a TextField which belongs to an Instance in the FLA from the Parent Class:
You can now have as many Instances in your FLA which, which Linkage, extend this Parent Class. You just have to ensure that they have a TextField with the instance name 'txtName' so that the Parent Class can do its thing.
Hope this helps :)
你的层次结构倒退了。 C 类无法访问 A 的成员,因为 A 是 C 的子类,而不是相反。 C 类中的“super.super”即使有效也不会得到您想要的,因为它会引用 MovieClip 扩展的 Sprite 类。
雪碧 ->影片剪辑 -> C-> B-> A 是您的层次结构,
但更重要的是,您通常不需要 super 关键字来访问超类成员。仅当您使用同名的子类成员覆盖超类成员并且需要区分时,才需要关键字。如果不存在任何命名冲突,则无需使用 super 或类名限定符即可访问超类的公共和受保护成员。如果你真的认为你需要 super.super,你需要重新考虑你的继承设计。
You've got your hierarchy backwards. Class C can't access members of A because A is a subclass of C, not the other way around. "super.super" from within the C class wouldn't get you what you want even if it worked because it would refer to the Sprite class that MovieClip extends.
Sprite -> MovieClip -> C -> B -> A is your hierarchy
More importantly though, you don't normally need the super keyword to access superclass members. You only need the keyword when you've overridden superclass members with subclass members of the same name and you need to differentiate. If there aren't any naming conflicts, you can access public and protected members of the superclass without the super or class name qualifier. If you really think you need super.super, you need to reconsider your inheritance design.