I keep getting, this error"Error package cannot be nested", when I compile my code: 

package  {

    import flash.display.Sprite;
    import flash.text.TextField;
    public class MessageBox extends Sprite {
        function MessageBox():void {

         var msgbox:Sprite = new Sprite();

          // drawing a white rectangle
          msgbox.graphics.beginFill(0xFFFFFF); // white
          msgbox.graphics.drawRect(0,0,300,20); // x, y, width, height
          // drawing a black border
          msgbox.graphics.lineStyle(2, 0x000000, 100);  // line thickness, line color (black), line alpha or opacity
          msgbox.graphics.drawRect(0,0,300,20); // x, y, width, height
          var textfield:TextField = new TextField()
          textfield.text = "Hi there!"

What is a nested package, and how do I fix it?

Its working! Just create a (MessageBox.as) file with the name of your class and paste your code there. Open your flash file and give your class name within the Document. Ctrl+Enter to run the file. Thats it! I checked it.