attachMovieClip in functions?

Hey all!

Im sorry to start on this forum with… well a terrible question I suppose.

Ive been messing around with actionscript for a while now and ive been able to find out most of my problems on my own. This one make no sense… at all. Ive searched on this forum, and on the internet for answers to this stupid problem.

Here it goes!

i = 1;
onEnterFrame = function ()
    {
    function randBalPlacement ()
        {
        i++;
        this.attachMovie("bal", "newName_" + i, 20);
        var bal:MovieClip = _root["newName_" + i];
        var xCo:Number = Math.floor(Math.random() * (400 - 200)) + 200;
        var yCo:Number = Math.floor(Math.random() * (400 - 200)) + 200;
        bal._x = xCo;
        bal._y = yCo;
        }
    randBalPlacement ();
    }

The attachMovie part is placed inside a function in this script. It does nothing though, and thats the problem. However when I delete the function part as seen below it acts like it should.

i = 1;
onEnterFrame = function ()
    {
        i++;
        this.attachMovie("bal", "newName_" + i, 20);
        var bal:MovieClip = _root["newName_" + i];
        var xCo:Number = Math.floor(Math.random() * (400 - 200)) + 200;
        var yCo:Number = Math.floor(Math.random() * (400 - 200)) + 200;
        bal._x = xCo;
        bal._y = yCo;
    }

Is there any specific reason that attachMovie doesnt work in a function? And what are possible solutions for this problem?

Thx,

ArmoredSandwich AKA ImWithNoob