Recursive tree regenerate question

Hey

I’m trying to get the recursive tree (can be found under fractals in kirupa tutorials) to regenerate every time a button is pressed.
My code is in a movieclip (tree) and it works fine, but I want to regenerate a new tree each time a different menubutton is pressed. How would I go about doing this?

I tried naming my tree movieclip as an instance (tree)
and putting

on (release) {
tree.makeBranch ( 200, 300, branch_length, -Math.PI/2, max_size ) ;
} 

on my buttons. I persume I’m not communicating with the function properly…!

/*** Constants ***/
max_sub_branch = 4 ;
max_sub_angle = 3*Math.PI/4 ;
max_size = 8 ;
branch_length = 50 ;

/*** Function ***/
function makeBranch ( start_x, start_y, length, angle, size ) {
if ( size > 0 ) {
this.lineStyle ( size, 0x333333, 100 ) ;
this.moveTo ( start_x, start_y ) ;
var end_x = start_x + length * Math.cos ( angle ) ;
var end_y = start_y + length * Math.sin ( angle ) ;
this.lineTo ( end_x, end_y ) ;

var sub_branch = random (max_sub_branch - 1) + 2 ;
var branch_length_dimin = .5 + Math.random()/2 ;
for ( var i=0; i < sub_branch; i ++ ) {
var newLength = length * branch_length_dimin ;
var newAngle = angle + Math.random() * max_sub_angle - max_sub_angle / 2 ;
var newSize = size - 1 ;
makeBranch ( end_x, end_y, newLength, newAngle, newSize ) ;
}
}
}

/*** Function call ***/
makeBranch ( 200, 300, branch_length, -Math.PI/2, max_size ) ;

Any help welcome :geek: