Return an Object with a Function? (VerifyError)

Hey all, long time fan, first time poster :smiley:
I’m trying to create a function that determines which of 4 similar classes to create, and returns the new object itself.

Basically, I have a base class (Panel) that has 3 additional variations in layout, each of which has a subclass: TextPanel, FeaturePanel, and LinkPanel. The two parameters for my function are the “kind” of window to create and its name (“linkString”), both of which are provided by external XML. I’m wondering if it’s even possible to return the new Panel as an object…?

My code will probably explain this better than I can:

// create the new Panel variable ("addPanel") with a call to newPanel:
var addPanel = newPanel(linkList*.attribute("kind"), linkString);
// newPanel function:
public function newPanel( g:String, h:String ) {
            switch ( g ) {
                case "Text":
                    return new TextPanel(h);
                    break;    //also, are these 'break's redundant?
                case "Feature":
                    return new FeaturePanel(h);
                    break;
                case "Link":
                    return new LinkPanel(h);
                    break;
                default:
                    return new Panel(h);
            }
        }

within the Panel constructor, the provided string (linkString / ‘h’) is set as the Panel’s .name. I did not copy that function into the subclasses, since they inherit it - unless I’m mistaken.

I’m new to AS3 and self-taught, so I realize this may be crazy talk, or just plain ugly coding. Hopefully this makes some sense though. Thanks in advance for any help!