# Calling function

**URL:** <https://forum.kirupa.com/t/calling-function/184213>\
**Category:** Uncategorized\
**Created:** [April 3, 2006, 11:26am UTC](https://forum.kirupa.com/t/calling-function/184213 "2006-04-03T11:26:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pensamente](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/pensamente/32/1208_2.png) [@pensamente](https://forum.kirupa.com/u/pensamente)\
**Post date:** [April 3, 2006, 11:26am UTC](https://forum.kirupa.com/t/calling-function/184213/1 "2006-04-03T11:26:30Z")

</div>

dunno what’s wrong in here… its suposed to call the function inItems() with different parammeter value…  
menu1  
menu2  
menu3  
…  
:hangover:

[AS]function inItems(who) {  
var anim1:Tween = new Tween(who, “\_alpha”, Strong.easeOut, 0, 100, 2, true);  
}  
var intervalId:Number;  
var count:Number = 1;  
var maxCount:Number = 6;  
var duration:Number = 500;  
function executeCallback():Void {  
inItems([“menu”+count]);  
trace(“menu”+count);  
if (count\>=maxCount) {  
clearInterval(intervalId);  
}  
count++;  
}  
intervalId = setInterval(this, “executeCallback”, duration);[/AS]

---

<div class="post-metadata">

**Author:** ![devonair](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@devonair](https://forum.kirupa.com/u/devonair)\
**Post date:** [April 3, 2006, 2:58pm UTC](https://forum.kirupa.com/t/calling-function/184213/2 "2006-04-03T14:58:50Z")

</div>

hey, pensamente,

You just discovered one of the many benefits of typing your variables…  
[“menu”+count] is an Array instance containing a single member which is a String instance. Neither an array nor a string can be animated with the Tween class - you need a MovieClip… You can do that using array access (which is what I think you were going for)… Try something like this:

[AS]import mx.transitions.Tween;  
import mx.transitions.easing.\*;  
//  
// type your “who” argument, so if you try to pass anything but a movieclip, Flash will throw a type mismatch error  
function inItems(who:MovieClip):Void {  
var anim1:Tween = new Tween(who, “\_alpha”, Strong.easeOut, 0, 100, 2, true);  
}  
// create a reference to the \_root level…  
var myRoot:MovieClip = this;  
var intervalId:Number;  
var count:Number = 2;  
var maxCount:Number = 4;  
var duration:Number = 500;  
function executeCallback():Void {  
// use array access to target the movie clips on the root with your custom root reference  
inItems(myRoot[“menu”+count]);  
if (count++\>=maxCount) {  
clearInterval(intervalId);  
}  
}  
intervalId = setInterval(this, “executeCallback”, duration);[/AS]

---

<div class="post-metadata">

**Author:** ![pensamente](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/pensamente/32/1208_2.png) [@pensamente](https://forum.kirupa.com/u/pensamente)\
**Post date:** [April 4, 2006, 10:00am UTC](https://forum.kirupa.com/t/calling-function/184213/3 "2006-04-04T10:00:11Z")

</div>

i think i understood the logic, but to be honest it’s quite new to me to “type my variables”… i used just to

myvar = x  
or  
\_global.myvar = x

never read nothing about this known benefits  
but i start using some cause i saw scripts write this way

thx for the class 😉

(heheh…i know, some english classes would be great!)
