我有以下开关案例:
switch (appModel.currentPage){
case "Programma":
case "Winkelwagen":
case "Films":
case "Contact":
if (page){
removeChild(page);
}
//here i would like to create a new object page that has the type of the switch.
i mean this: var page: getDefinitionByName(appModel.currentPage+"Page");
this doesnt work thou but it should be something like: "FilmsPage or ContactPage or ...".
addChild(page);
break;
有谁知道怎么做?
答案 0 :(得分:0)
var pageClass:Object = getDefinitionByName(appModel.currentPage+"Page");
var page:DisplayObject = new pageClass();
addChild( page );
答案 1 :(得分:0)
PatrickS的答案应该有效,但是你需要确保你将使用的所有类都被引用,或者编译器会跳过它们,而不是将它们添加到你的SWF中。