# AS2.0 Linkage and attachMovie Woe

**URL:** <https://forum.kirupa.com/t/as2-0-linkage-and-attachmovie-woe/207641>\
**Category:** flash\
**Created:** [November 20, 2006, 9:33am UTC](https://forum.kirupa.com/t/as2-0-linkage-and-attachmovie-woe/207641 "2006-11-20T09:33:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![softyengin](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@softyengin](https://forum.kirupa.com/u/softyengin)\
**Post date:** [November 20, 2006, 9:33am UTC](https://forum.kirupa.com/t/as2-0-linkage-and-attachmovie-woe/207641/1 "2006-11-20T09:33:54Z")

</div>

attachMovie woes

Hi I am having some trouble with Classes with respect to a movieclips ‘As 2.0 class’ in the linkage settings.  
After an attachMovie i am expecting my Class members to exist but they are not

OK, This is what i was doing…

I create a MovieClip called Class1\_mc and another called Class2\_mc, original eh.  
i then stick an instance of class2\_mc INSIDE of Class1\_mc, call it clipinner

ok so i assign Class1 to Class1\_mc and Class2 to Class2\_mc via the linkage settings.

I then create Class1.as and Class2.as.

class Class2 extends MovieClip  
{

```
function Class2()
{
}

function onLoad()
{
    trace(this + " Loaded.");
}

```

}

and

class Class1 extends MovieClip  
{

```
function Class1()
{
}

function onLoad()
{
    trace(this + " Loaded.");
}

```

}

ok in first frame i write

stop();  
attachMovie(“Class1\_mc”, “clip”, 20);  
trace("class should be loaded and ready to use by now!!! " + clip);

so i attach my MovieClip and print some text out, this is what the output window says…

//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
class should be loaded and ready to use by now!!!  
\_level0.clip Loaded.  
\_level0.clip.clipinner Loaded.  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

WOW! look at the order of the traces, the inner clips are LAST!

ok so my point is this

[**CONFUSED RANT** I KNOW movie clips arent always available straight away as they need to load in etc usually but i thought ATTACHMOVIE always returned the object straight away without loading delays, there is nothing to LOAD here??]

Anyway, What i was wanting to do was…

stop();  
var myClip = attachMovie(“Class1\_mc”, “clip”, 20);  
myClip.clipinner.ClassMethodCall(‘somevalue’);

but i couldnt because it didnt exist

the following,

trace(myClip.clipinner.ClassMethodCall); == undefined

why is this undefined???

If i am going about this totally wrong PLEASE tell me.

What are the ‘best practises’ for attaching Classes to MovieClips? is this the best way?  
I am expecting the code to work like c++, if i create a class all inherited classes get created before new returns.

I know this is FLASH and i know i didnt do NEW it was ATTACHMOVIE but i dont see the point in being able to link to a class when it isnt available until some random point i the future. There must be a better way to do this?

Right get your thinking hats on, this is driving me mental

I ended up creating the classes with new and passing in the MovieClip instance, that works but the other way just seemed so convenient!

Cheers
