Attaching movie clips to another movie clip

I’m attaching (and then removing) relevant movie clips to an empty movie clip that is shown in a scrollpane. It all works fine when triggered from buttons, but when the flash file is first loaded no clip is attached and thus nothing is displayed in the scrollpane. What am I doing wrong?

This is the function I trigger through the buttons and when the file is first loaded:
function loadScroll(the_page)
{
//create delay for component to initialize
i = 1;
this.onEnterFrame = function()
{
i++;

    if (i>5) 
    {
        switch (the_page)
        {
            case "xmlGallery.html":
                empty_mc.testreal_mc.removeMovieClip();
                empty_mc.attachMovie("gallery", "galleryreal_mc", empty_mc.getNextHighestDepth());
                scrollpane.invalidate();
            break;
            default:
                empty_mc.galleryreal_mc.removeMovieClip();
                empty_mc.attachMovie("test_mc", "testreal_mc", empty_mc.getNextHighestDepth());
                empty_mc.testreal_mc.myTable.createTable(the_page);
                scrollpane.invalidate();
        }
        delete this.onEnterFrame;
    }
};
test_mc.myTable.onTableRendered = function() 
{
    scrollpane.hScrollPolicy = "false";
};

loadPicture();

}