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!