# Novice looking for help creating a function

**URL:** <https://forum.kirupa.com/t/novice-looking-for-help-creating-a-function/306355>\
**Category:** Uncategorized\
**Created:** [March 13, 2010, 9:55pm UTC](https://forum.kirupa.com/t/novice-looking-for-help-creating-a-function/306355 "2010-03-13T21:55:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![edmund](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@edmund](https://forum.kirupa.com/u/edmund)\
**Post date:** [March 13, 2010, 9:55pm UTC](https://forum.kirupa.com/t/novice-looking-for-help-creating-a-function/306355/1 "2010-03-13T21:55:57Z")

</div>

[SIZE=1]I have 5 instances of a movie clip that need to move to a frame labeled “highlight” on Rollover and to a frame labeled “unhighlight” on Rollout. On Release each needs to get a different URL.[/SIZE]  
[SIZE=1][/SIZE]  
[SIZE=1]I got it working, but the script is pretty repetitive. Can someone show me how to shorten the script by creating a function or something similar that would handle the rollover and rollout part? Code for two of the movie clips below.[/SIZE]  
[SIZE=1][/SIZE]  
[SIZE=1]Thanks![/SIZE]  
[SIZE=1][/SIZE]  
[SIZE=1]------------------------------------------------------------[/SIZE]  
[SIZE=1][/SIZE]  
[SIZE=1]// On Rollover, highlight button  
this.main\_mc.btn1.onRollOver = function () {  
if(!pressed)  
main\_mc.btn1.gotoAndPlay(“highlight”);  
}

// On Rollout, exit mouseover highlight  
this.main\_mc.btn1.onRollOut = function () {  
if(!pressed)  
main\_mc.btn1.gotoAndPlay(“unhighlight”);  
}

// On Release, getURL  
this.main\_mc.btn1.onRelease = function () {  
getURL("[/SIZE][[SIZE=1]http://www.cnn.com[/SIZE]](http://www.cnn.com)[SIZE=1]");  
main\_mc.btn1.gotoAndPlay(“unhighlight”);  
// on release exit mouse-over  
pressed = true;  
}[/SIZE]  
[SIZE=1]// On Dragout, exit mouse-over  
this.main\_mc.btn1.onDragOut = function () {  
main\_mc.btn1.gotoAndPlay(“unhighlight”);  
}[/SIZE]  
[SIZE=1]/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
// On Rollover, highlight button  
this.main\_mc.btn2.onRollOver = function () {  
if(!pressed)  
main\_mc.btn2.gotoAndPlay(“highlight”);  
}

// On Rollout, exit mouseover highlight  
this.main\_mc.btn2.onRollOut = function () {  
if(!pressed)  
main\_mc.btn2.gotoAndPlay(“unhighlight”);  
}

// On Release, getURL  
this.main\_mc.btn2.onRelease = function () {  
getURL("[/SIZE][[SIZE=1]http://www.espn.com[/SIZE]](http://www.espn.com)[SIZE=1]");  
main\_mc.btn1.gotoAndPlay(“unhighlight”);  
// on release exit mouse-over  
pressed = true;  
}[/SIZE]  
[SIZE=1]// On Dragout, exit mouse-over  
this.main\_mc.btn2.onDragOut = function () {  
main\_mc.btn2.gotoAndPlay(“unhighlight”);  
}[/SIZE]
