# Creating functions with the Tween class

**URL:** <https://forum.kirupa.com/t/creating-functions-with-the-tween-class/190751>\
**Category:** Uncategorized\
**Created:** [June 14, 2006, 1:41pm UTC](https://forum.kirupa.com/t/creating-functions-with-the-tween-class/190751 "2006-06-14T13:41:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![graylensman](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@graylensman](https://forum.kirupa.com/u/graylensman)\
**Post date:** [June 14, 2006, 1:41pm UTC](https://forum.kirupa.com/t/creating-functions-with-the-tween-class/190751/1 "2006-06-14T13:41:18Z")

</div>

I’m working with the Tween class in Flash 8. It’s great stuff, except I find my ActionScript is getting excessively lengthy. For example, I have ten instances of buttons on stage. They all utilize this particular bit of code, which makes the buttons pop upward:

```
ActionScript Code:
[FONT=Courier New][LEFT]button1.[COLOR=#0000FF]onRollOver[/COLOR]=[COLOR=#000000] **function** [/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]

```

[COLOR=#808080]_//initailizing the Tween_[/COLOR]  
[COLOR=#000000] **var** [/COLOR] popBtn:Tween=[COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]button1, [COLOR=#FF0000]"\_y"[/COLOR], mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR].[COLOR=#000080]Elastic[/COLOR].[COLOR=#000080]easeOut[/COLOR], [COLOR=#000080]0[/COLOR], -[COLOR=#000080]20[/COLOR], [COLOR=#000080]2[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#808080]_//calling the tween object_[/COLOR]  
popBtn.[COLOR=#0000FF]start[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]  
[/LEFT]  
[/FONT]

The only difference for any of the buttons in the script is the name of the instance. When i set this up as a global function, using “this” instead of a specific instance name, the script fails to execute. So I have to hammer out all those lines of code for each button instance.

Thanks in advance for any help!
