The constructor will be called before LoadContent. At that time, the lines in your switch statement will all be assigning null to spriteTexture.
The simplest fix would be to save the value of requestedMenuButtonType and put the switch statement (or a call to a method containing the switch statement) into LoadContent (at a point after the icons have been loaded). Ex:
private static MenuButtonType savedMenuButtonType;
public MenuButton(int requestedX, int requestedY, int requestedWidth, int requestedHeight, MenuButtonType requestedMenuButtonType)
: base(requestedX, requestedY, requestedWidth, requestedHeight)
{
...
savedMenuButtonType = requestedMenuButtonType;
...
}
public static void LoadContent(ContentManager Content)
{
...
//Main Menu Icons
...
//About Menu Icons
...
spriteTexture = GetRequestedSpriteTexture();
}
private static Texture2D GetRequestedSpriteTexture()
{
switch (savedMenuButtonType)
{
case MenuButtonType.play:
return playButtonIcon;
break;
...
}
A better solution might be to wrap the Texture2Ds in some Icon class, which has its own LoadContent method (which calls LoadContent for its particular Texture2D). Then when LoadContent is called, it would load the Texture2Ds without throwing away the Icon references.
public class Icon
{
private string mTextureName;
private Texture2D mTexture;
public Icon(string pTextureName)
{
mTextureName = pTextureName;
}
...
public void LoadContent(ContentManager Content)
{
mTexture = Content.Load<Texture2D>(mTextureName);
}
...
}
public class MenuButton : SpriteObject
{
private Icon spriteIcon;
//Different Icons, static for loading
private static Icon playButtonIcon = new Icon("Menu Items/Menu Buttons/PlayButtonIcon");
...
public MenuButton(int requestedX, int requestedY, int requestedWidth, int requestedHeight, MenuButtonType requestedMenuButtonType)
: base(requestedX, requestedY, requestedWidth, requestedHeight)
{
...
spriteIcon = playButtonIcon;
...
}
public void LoadContent(ContentManager Content)
{
...
playButtonIcon.LoadContent(Content);
...
}
}