나는 당신이 상속이 작동하는 방법에 대해 혼란 스러울 수 있다고 생각합니다. 특히 부모 클래스와 하위 클래스 간의 관계.
public class Parent {
// Constructor for the Parent Class.
public function Parent() {
}
protected function sayHello() : void {
trace("Hello!");
}
}
우리는 지금을 만들 수 있습니다
부모 클래스는 아이 서브 클래스가 행동하는의, here'a 매우 간단한 예제의 사용을 할 수 메서드와 속성의 형태로 행동에 노출 될 수 있습니다 부모의 눈에 보이는 행동 (함수와 속성)를 얻을 것이 부모 클래스의 자식 클래스 : 이제
public class Child extends Parent {
// Constructor for the Child Class.
public function Child() {
// Call the 'parent' classes constructor.
super();
// This child class does not define a function called "sayHello" but
// the Parent class which this Child class extends does, and as a result
// we can make a call to it here. This is an example of how the child Class
// gains the behaviours of the Parent class.
this.sayHello();
}
public function sayGoodbye() : void {
trace("Goodbye!");
}
}
, 자식 클래스는 부모의 기능과 속성에 액세스 할 수 있습니다 관계, 확장 한 클래스는 한 가지 방법으로 만 작동합니다. 의 우리 방법을 살펴 보자,
public class Parent {
public function Parent() {
// Trying to call the sayGoodbye() method will cause a compilation Error.
// Although the "sayGoodbye" method was declared in the Child class, the
// Parent Class has no knowledge of it.
this.sayGoodbye();
}
}
을 이제 : 그 결과로, 그래서 다음과 같은 코드가 작동하지 않습니다, 부모 클래스는 아이들이 선언 선택할 수있는 기능과 특성에 대한 지식이없는, 말을하는 것입니다 아마도 부모 클래스에서 FLA에 인스턴스에 속하는 텍스트 필드에 액세스하려고의 문제를 해결할 수 :
// it is important to note that by extending the MovieClip class, this Parent Class now
// has access to all the behaviours defined by MovieClip, such as getChildByName().
public class Parent extends MovieClip {
// This is a TextField that we are going to use.
private var txtName : TextField;
public function Parent() {
// Here we are retrieving a TextField that has an instance name of txtName
// from the DisplayList. Although this Parent Class does not have a TextField
// with such an instance name, we expect the children that extend it to declare
// one.
txtName = this.getChildByName("txtName") as TextField;
// Check to see if the Child class did have an TextField instance called
//txtName. If it did not, we will throw an Error as we can not continue.
if (txtName == null) {
throw new Error("You must have a TextField with an instance name of 'txtName' for this Parent Class to use.");
}
// Now we can make use of this TextField in the Parent Class.
txtName.text = "Hi my name is Jonny!";
}
}
이제 연동이이 부모 클래스를 확장하여 FLA의 많은 인스턴스를 가질 수 있습니다 . 부모 클래스가 그 일을 할 수 있도록 인스턴스 이름이 'txtName'인 TextField가 있는지 확인하면됩니다.
희망이 있습니다.
그러나'C' 클래스는'MovieClip' 클래스의 서브 클래스이므로'A' 클래스와 아무런 관련이 없습니다. 'A'는'MovieClip'을 확장하지 않고'B'는'A'를 확장하고'C'는'B'를 확장합니까? – Taurayi
welp 나는이 예제가 정확히 무엇을 달성하려했는지 설명하기에 충분하지 않다고 생각한다. 정확한 시나리오로 메인 포스트를 업데이트했습니다. – ufk
용어가 약간 모호합니다. 즉, 연결로 인해 항목이 확장되지 않고 의미가 명확하지 않은 경우 FLA를 보는 데 도움이됩니다. 그건 제쳐두고, 당신은 여전히 슈퍼에 대해 혼란스러워합니다. 예제에서 super.element_name은 MovieClip 클래스의 "element_name"속성을 찾으려고합니다. 그러나 user_bg_generic 클래스가 저작 도구에서 만든 MovieClip 내부의 요소에 대한 참조를 가져오고 user_bg_generic의 하위 클래스로 내보내도록 설정하면 this.element_name 또는 this [ "element_name "] 형식 표기법이 아니라 '수퍼'표기법. –