模板AS3(如C ++) [英] Templates for AS3 (like c++)
问题描述
如何定义C ++ - 在AS3像模板?;我有我想要的地图类(二维数组)再利用跨项目,但是单元的数据是不同的类取决于项目或实施;
How do I define C++-like templates in AS3?; I have a map class (2d array) that I want to re-use across projects but the cell data is a different class depending on the project or implementation;
有一堆关于共享code翻过不同的实现等原因,但我希望财产以后这样的:
There are a bunch of other reasons regarding sharing code accross different implementations, but I'd hope for somthing like:
map = new MyMap<MyCell>();
如果它是闪存10只:磷
Doesn't matter if it's Flash 10 only :-p
无所谓
干杯, 克里斯
Cheers, Chris
推荐答案
有没有模板,但动态类型和使用类的值可能是你已经足够了。
There aren't templates, but dynamic typing and using classes as values might be good enough for your purposes.
您可以做一个类,它的类,并将其存储为一个实例变量。
You can make a class that takes a class and stores it as an instance variable.
class MyMap {
var myClass:Class;
function MyMap(c:Class){
myClass = c;
}
}
然后你喂类吧...
And then you feed the class to it...
map = new MyMap(MyCell);
然后在方法,你可以参考这个类。
And then in methods, you can refer to that class.
// Inside MyMap somewhere
var someWhatever:Object = new myClass();
// or
var someWhatever:Object = Object(myClass).someCachingSchemeStaticMethod();
// or whatever.
这篇关于模板AS3(如C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!