Switching between scripts/class

What is the best way to swap/toggle between scripts when clicking on a button.
i have two as files - one is for a drawing tool and the other is for a writing tool. I am trying to ‘switch’ between the two codes when clicking on a button labeled ‘Write’ and another button labeled ‘Draw’.

Is it possible to change the ‘Document class’? I don’t know if this makes sense :blush:

Any input appreciated. Thanks

Have the functions for “write” and “draw” as separate as files (as you already do). Instantiate them in the document class. Then when tou click on the buttons, in the document class change the mouse down event listener to use the appropriate class.

Hey thanks for the reply. Does anyone have any examples?

 [LEFT] 	ActionScript Code:
[LEFT][COLOR=#0000FF]private[/COLOR] [COLOR=#000000]**function**[/COLOR] createDrawButton[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] : [COLOR=#0000FF]void[/COLOR] [COLOR=#000000]{[/COLOR]
       [COLOR=#000000]**var**[/COLOR] btn_draw:SimpleButton = [COLOR=#000000]**new**[/COLOR] drawButton[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
        btn_draw.[COLOR=#000080]x[/COLOR] = [COLOR=#000080]25[/COLOR];
        btn_draw.[COLOR=#000080]y[/COLOR] = [COLOR=#000080]7[/COLOR];
        btn_draw.[COLOR=#000080]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000080]CLICK[/COLOR], clickHandler_draw[COLOR=#000000])[/COLOR];
        addChild[COLOR=#000000]([/COLOR]btn_draw[COLOR=#000000])[/COLOR];
        
        [COLOR=#000000]**function**[/COLOR] clickHandler_draw[COLOR=#000000]([/COLOR]event:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#0000FF]void[/COLOR] [COLOR=#000000]{[/COLOR]
           [COLOR=#808080]*//what goes here;*[/COLOR]
        [COLOR=#000000]}[/COLOR]
    [COLOR=#000000]}[/COLOR]

[/LEFT]

[/LEFT]

it kinds of depends on your implementation of the tools and how they work.

The basic idea, though, is that you would have a single “active tool.” When your button is pushed, the active tool is set and then only that tool, drawing or writing, will function and do its thing.

One way you could set this up is through one simple variable. In your click handler, you’d set that variable to the instance of your desired active tool. Then that variable would be used by a persistent user interaction manager instance (another class you would define to always exist and serve only to send messages to the active tool) to receive mouse/input events from the user.