Function not defined immediately after create MovieClip instance

Hello kirupa flashers,

I create a new MovieClip, call it Somehow, and link it to the name “MyClip”, for example.
Inside of the Clip, there must be a Function like this:

 
this.sayHello = function() { return("Hello"); } 

(In fact, my script should do different things, but this should be enough at first :slight_smile:

In my root frame, i do something like that:

 
attachMovie("MyClip", "MyClip01", 1);
trace(MyClip01);
trace(MyClip01.sayHello());

For the first trace i get “_level0.MyClip01”, which is correct.
But i cant call the function sayHello(), it says: “Undefined”.
And when i put the last line in the second frame, or as a button action, it is working, but
this is not what i want.

The reason is, that i get a big struct object where all the information is stored about
the Clips i have to create and how to initialize them and so on.

It LOOKS LIKE this:


for(i=1; i<=100; i++) {
 attachMovie("MyClip", "MyClip"+i, i);
 theClip = eval("MyClip"+ i);
 theClip.tellSomething(i*i);
}

They must be MovieClips, because the functions not only response with hello, like in the example.

So I want to create the Clip copies and call the functions in one step. This example is also not working when i put it inside of a onLoad, or onEnterFrame and so on…

And ideas? I doubt that its so difficult…

Eclipse2k