# attachMovie problem

**URL:** <https://forum.kirupa.com/t/attachmovie-problem/170742>\
**Category:** flash\
**Created:** [November 29, 2005, 6:20am UTC](https://forum.kirupa.com/t/attachmovie-problem/170742 "2005-11-29T06:20:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kritikal](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kritikal/32/1699_2.png) [@kritikal](https://forum.kirupa.com/u/kritikal)\
**Post date:** [November 29, 2005, 6:20am UTC](https://forum.kirupa.com/t/attachmovie-problem/170742/1 "2005-11-29T06:20:05Z")

</div>

I had this problem for a while now but never been able to solve it so here goes.

I have a backgrounds.swf a index.swf and menu.swf When the user clicks on a button the backgrounds.swf knows on what’s the current page and what the next one is so it’s supposed to attach them from the library to a movieclip and does an animation.

menu.swf calls backgrounds.swf by doing

```auto

//bkContainer is where backgrounds.swf is loaded
_root.bkContainer.attachBk(currBk,nextBk); //currBk and nextBk are defined when a user clicks on something like so
var currBk:String = _root.currMovie;
var nextBk:String = clicked;

```

now in backgrounds.swf I have

```auto

function attachBk (currBk, nextBk) {
    trace("function attachBk loaded");
    trace("currBk: " + currBk);
    trace("nextBk: " + nextBk);
    if (currBk == undefined) {        
        var targetBk = this.attachMovie(nextBk,"bkHolder1",this.getNextHighestDepth());
        trace("targetBk:" + targetBk); //returns undefined.....
    }
    else {
        _root.bkContainer.attachMovie(nextBk,"bkHolder2",1);
        var targetBk = _root.bkContainer.attachMovie(currBk,"bkHolder1",2);
        trace("targetBk:: " + targetBk); //returns undefined....
//whatever animation goes here
    }
}

```

for some unknown reason targetBk returns undefined when currBk and nextBk return the correct values, I can’t figure out what’s the problem. I know there’s nothing wrong with the code because if I run backgrounds.swf alone by adding attachBk(“aboutBk”,“polariceBk”); it works perfectly.

I’m running out of ideas, I even tried storing the values in my index.swf and adding an onEnterFrame function in the backgrounds.swf that checks when the page is changed and should attach the backgrounds but I also get an undefined targetBk.

Any reason why it’s doing that… any help would be greatly appreciated!!
