Referencing movieclip created in another function

Hi,

I’m a complete newb to AS 3.0, but wrote a couple of small games using AS 2.0. One of the things I found easiest about AS 2.0 is that a MovieClip created using _root.attachMovieClip() inside of one function was accessible to every other function. For instance:

AS 2.0

 
function AddClip() {
TheClip = _root.attachMovie("Object", "TheClip"+ClipCount, _root.getNextHighestDepth(), {_x:30, _y:30})
}
function ManipulateClip() {
TheClip._x = TheClip._x+10
}

Now in AS 3.0, when I declare a MovieClip inside of one function, I cannot figure out how to access that MovieClip from another function.

For instance:

AS 3.0

 
function AddClip() {
  var Terrain2_mc:Terrain=new Terrain();
  Terrain2_mc.x=0;
  Terrain2_mc.y=0;
  addChild(Terrain2_mc);
}
function ManipulateClip() {
  Terrain2.x = Terrain2.x+10
}

This causes an error, because the MovieClip variable was declared inside of a function and when the function ended, the MovieClip variable was erased.

Is there any way of doing this without declaring the MovieClip variable outside of the function? I want to be able to create an unknown amount of these movieclips on the fly, so I can’t just declare them outside of the function.

Any help would be appreciated.

Thanks,

-JayMasterJay