开发者

creating object according to the switch case value

开发者 https://www.devze.com 2023-02-02 16:13 出处:网络
i have the following switch case: switch (appModel.currentPage){ case \"Programma\": case \"Winkelwagen\":

i have the following switch case:

    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;

Does anyone know how to do this?


var pageClass:Object = getDefinitionByName(appModel.currentPage+"Page");
var page:DisplayObject = new pageClass();
addChild( page );


PatrickS's answer should work, but you will need to make sure all the classes that you will use are referenced somewhere, or the compiler will skip over them, and not add them to your SWF.

0

精彩评论

暂无评论...
验证码 换一张
取 消