Errors when creating scrollpane dynamically

I’ve been trying to create a scrollpane dynamically but I keep getting a bunch of errors when I publish the swf. At first I thought maybe there was a problem with my code so then I looked in the help file and copied and pasted one of there examples into a blank fla and I still get the same errors when I publish. Anyone know what I’m doing wrong? If I look at what is the source of the errors it looks like the error originates at this section of the ScrollPane.as file:


override protected function drawBackground():void {
            var bg:DisplayObject = background;
            
            background = getDisplayObjectInstance(getStyleValue(enabled ? "upSkin" : "disabledSkin"));
            background.width = width;
            background.height = height;
            addChildAt(background,0);
            
            if (bg != null && bg != background) { removeChild(bg); }
        }

specifically the line that says “background.width = width”.

Here is the code I copied and pasted from the help sample:


import fl.containers.ScrollPane;

var url:String = "http://www.helpexamples.com/flash/images/image1.jpg";

var myScrollPane:ScrollPane = new ScrollPane();
myScrollPane.setSize(320, 240);
myScrollPane.move(10, 10);
myScrollPane.addEventListener(ProgressEvent.PROGRESS, progressHandler);
myScrollPane.addEventListener(Event.COMPLETE, completeHandler);
myScrollPane.load(new URLRequest(url));
addChild(myScrollPane);

function progressHandler(event:ProgressEvent):void {
    var bLoaded:int = event.bytesLoaded;
    var bTotal:int = event.bytesTotal;
    var pctLoaded:int = int(event.currentTarget.percentLoaded);
    trace("progress: " + bLoaded + " of " + bTotal + " bytes loaded (" + pctLoaded + "%)");
}

function completeHandler(event:Event):void {
    trace("complete:");
}

and here are the errors I’m getting:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.containers::ScrollPane/fl.containers:ScrollPane::drawBackground()
at fl.containers::ScrollPane/fl.containers:ScrollPane::draw()
at fl.core::UIComponent/::callLaterDispatcher()
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChildAt()
at fl.controls::BaseButton/fl.controls:BaseButton::drawBackground()
at fl.controls::BaseButton/fl.controls:BaseButton::draw()
at fl.core::UIComponent/drawNow()
at fl.controls::ScrollBar/fl.controls:ScrollBar::draw()
at fl.core::UIComponent/::callLaterDispatcher()

Normally I would just think I did something wrong but I’m literally copying it straight out of the help file. I’ve created scrollpanes with actionscript all the time in AS2 but this was my first try with AS3 so I’m not really sure what the issue is.