그래서이 슈퍼 클래스 그리드 클래스와 GrassTile1, GrassTile2 등의 그리드 클래스 서브 클래스가 있습니다. 서브 클래스의 모든 인스턴스는 배열에 저장됩니다. 하위 클래스의 인스턴스를 배열을 참조하는 수퍼 클래스로 변환하는 방법은 무엇입니까?하위 클래스의 인스턴스를 수퍼 클래스로 캐스팅하는 방법은 무엇입니까?
private var backgroundGrid = []; //the array which the grids are stored in, in the main class.
public class Grid extends MovieClip
{
protected var node :PathfindNode; //the variable I wish to access, from an instance of subclass.
public function Grid(){
node = new PathfindNode();
}
}
public class GrassTile1 extends Grid { //every subclass of Grid will extends Grid
public function GrassTile1() {
// constructor code
}
}
function getBackgroundGrid(i:int,j:int):Grid{ //in the main class
return Grid(backgroundGrid[i][j]); // this line gives me an error
}
형식 오류 : 오류 # 1034 : 유형 강제 변환 실패 : 그리드에 2905d5f1 @ GrassTile1을 변환 할 수 없습니다.
backgroundGrid [i] [j] .node에 접근 해 보았습니다. 다른 생각으로는 생각하고 실패했습니다. 어떤 아이디어?
는
간단한 .fla를 설정하고 내가 말한 내용에 기반하여 파일을 설정 했으므로 오류가 없습니다. – prototypical
업데이트 된 답변보기 일어나는 일이 실제로 일어나기를 기대하기 위해 생성자에 흔적을 던지면 좋을 것입니다. 나는 슈퍼를 부를 필요가 없었고, 그것은 나를 위해 잘 작동합니다. – prototypical