# Passing a MovieClip reference to a function in an external class

**URL:** <https://forum.kirupa.com/t/passing-a-movieclip-reference-to-a-function-in-an-external-class/306980>\
**Category:** flash\
**Created:** [March 25, 2010, 4:04pm UTC](https://forum.kirupa.com/t/passing-a-movieclip-reference-to-a-function-in-an-external-class/306980 "2010-03-25T16:04:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fex](https://avatars.discourse-cdn.com/v4/letter/f/ba9def/32.png) [@fex](https://forum.kirupa.com/u/fex)\
**Post date:** [March 25, 2010, 4:04pm UTC](https://forum.kirupa.com/t/passing-a-movieclip-reference-to-a-function-in-an-external-class/306980/1 "2010-03-25T16:04:15Z")

</div>

Howdy, folks!

My situation is seemingly simple: I want to create a MovieClip, pass this MovieClip to a function in another class where it will be modified.

The problem is, when I pass the MovieClip as a parameter to a function and start making changes, the changes are only made locally. The “copy” of the MovieClip inside the function gets changed, but the “real” MovieClip back in my main game class remains unchanged.

Here’s the code from my Main class:

```auto
var resourceLoader:ExternalResourceLoader = new ExternalResourceLoader();    
var myMovieClip:MovieClip;

function Main() {
   resourceLoader.loadSWFIntoMC("awesomeAnimation.swf",myMovieClip,stage,testCallback);
}

function testCallback() {
   trace(myMovieClip);
   // Returns null. This MovieClip is never created - only the local copy inside the "loadSWFIntoMC" function.
}

```

And here’s the function being called (from an external .AS class file):

```auto

public function loadSWFIntoMC(filename:String, targetMC:MovieClip, parentWindow:Stage, callbackFunction:Function=null) {
            targetMC=new MovieClip();
            targetMC.fullyLoaded=false;
            var loader = new Loader();
            var loadRequest:URLRequest=new URLRequest(filename);
            loader.load(loadRequest);
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event) {
                targetMC=loader.content;
                parentWindow.addChild(targetMC);
                targetMC.fullyLoaded=true;
                if (callbackFunction!==null) {
                    callbackFunction.call();
                }
            });
        }

```

Thanks in advance for the help!
