# Calling a function in a dynamically attached MC?

**URL:** <https://forum.kirupa.com/t/calling-a-function-in-a-dynamically-attached-mc/255852>\
**Category:** flash\
**Created:** [March 27, 2008, 4:17pm UTC](https://forum.kirupa.com/t/calling-a-function-in-a-dynamically-attached-mc/255852 "2008-03-27T16:17:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian914](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@brian914](https://forum.kirupa.com/u/brian914)\
**Post date:** [March 27, 2008, 4:17pm UTC](https://forum.kirupa.com/t/calling-a-function-in-a-dynamically-attached-mc/255852/1 "2008-03-27T16:17:21Z")

</div>

I am having problems with this and I can’t quite figure out what I am doing wrong.  
I have the following AS inside a function in my movieclip.

this.attachMovie(“team\_” + whichProfile, “team\_” + whichProfile, this.getNextHighestDepth());  
var teamProfile = [“team\_” + whichProfile];  
this[teamProfile].fadeInPhotos();

The variable whichProfile is a number. I have several movie clips with different content that are named team\_0, team\_1, team\_2, etc. Inside those clips, I have a function called fadeInPhotos, which I am not trying to call from the timeline that team\_0, team\_1, team\_2, etc. are getting attached to. Somehow that does not work.

I did the following cascading trace and got the following output:  
//have I got the name right?  
trace("teamProfile: " + teamProfile);  
//is the name a string  
trace("teamProfile is a string: " + ((typeof teamProfile==“string”)? “yes”: “no”));  
//is the movieclip correctly pathed  
trace("this[teamProfile] is: " + this[teamProfile]);  
//is the function defined  
trace("this[teamProfile].fadeInPhotos is: " + this[teamProfile].fadeInPhotos);  
//does the function return a value  
trace("this[teamProfile].fadeInPhotos() is: " + this[teamProfile].fadeInPhotos());

Output:  
teamProfile: team\_0  
teamProfile is a string: no  
this[teamProfile] is: \_level0.team\_0  
this[teamProfile].fadeInPhotos is: undefined  
this[teamProfile].fadeInPhotos() is: undefined

I even tried hardwiring this, like so, and still get an undefined:  
trace("Team 0 " + this.team\_0.fadeInPhotos());

What am I doing wrong?

Thanks a lot for having a look at this!!!
