# addChild from separate as file

**URL:** <https://forum.kirupa.com/t/addchild-from-separate-as-file/278858>\
**Category:** flash\
**Created:** [January 6, 2009, 7:23pm UTC](https://forum.kirupa.com/t/addchild-from-separate-as-file/278858 "2009-01-06T19:23:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobcooper](https://avatars.discourse-cdn.com/v4/letter/b/b19c9b/32.png) [@bobcooper](https://forum.kirupa.com/u/bobcooper)\
**Post date:** [January 6, 2009, 7:23pm UTC](https://forum.kirupa.com/t/addchild-from-separate-as-file/278858/1 "2009-01-06T19:23:43Z")

</div>

Hi There,

I’m trying to build an attachmovie class so I can add a child movieclip from the library and define the x and y coords using only one line of as in the fla

Here is my fla code:

var newMovie:AttachClip = new AttachClip(“movie\_mc”, 10, 10);

And here is my as code:

package {  
import flash.display.\*;  
import flash.utils.getDefinitionByName;  
// create class  
public class AttachClip extends MovieClip {  
// define vars  
var movieName:MovieClip;  
var movieX:Number;  
var movieY:Number;

```
    function AttachClip(movieVal:String, movieX:Number, movieY:Number) {
        var movieDefinition = getDefinitionByName(movieVal);
        movieName = new movieDefinition;
        movieName.x = movieX;
        movieName.y = movieY;
        
        addChild(movieName);
    }
}

```

}

The trouble is that it is not adding the child to the stage, now I have a feeling that I need to tell flash where to add the child to but I cant figure out how to reference the stage from the as file, any thoughts?

Thanks,

Bob
