I have a base class called Room
and a subclass called Attic
, and another called Basement
.
I have a controller class that has an attribute called CurrentLocation
which is type Room
. The idea is I want to be able to put Attic
or Basement
in that property and get it back, then cast that to whatever type it is.
So if on the controller the content is of type Attic
, I'm trying to figure out how to explicitly cast it. I thought I knew but its not working... Here's what I thought it would be, borrowing from Java:
var myAttic:Attic = (Attic) Controller.CurrentLocation;
This gives me a syntax error:
1086: Syntax error: expecting semicolon before instance.
So how do you cast implicitly? Or can you? I could swear I've done this before as as3.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…