# Refererncing movieclips from inside a class instatiated in the DocumentClass

**URL:** <https://forum.kirupa.com/t/refererncing-movieclips-from-inside-a-class-instatiated-in-the-documentclass/323812>\
**Category:** Uncategorized\
**Created:** [July 19, 2011, 2:51pm UTC](https://forum.kirupa.com/t/refererncing-movieclips-from-inside-a-class-instatiated-in-the-documentclass/323812 "2011-07-19T14:51:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lotus\_](https://avatars.discourse-cdn.com/v4/letter/l/9fc29f/32.png) [@lotus\_](https://forum.kirupa.com/u/lotus_)\
**Post date:** [July 19, 2011, 2:51pm UTC](https://forum.kirupa.com/t/refererncing-movieclips-from-inside-a-class-instatiated-in-the-documentclass/323812/1 "2011-07-19T14:51:23Z")

</div>

Hi, I have this very simple ImageLoader class:

package {

import flash.display.MovieClip;  
import flash.events.Event;  
import flash.events.ProgressEvent;  
import flash.net.URLRequest;  
import flash.display.Loader;

public class ImageLoader extends MovieClip {

var imageLoader:Loader;

public function ImageLoader(img:String)  
{ loadAsset(img); }

public function loadAsset(url:String):void {  
//warning here  
**preloader**.visible = true;  
imageLoader = new Loader();  
imageLoader.load(new URLRequest(url)); imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading); imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded); } //;

public function imageLoaded(evt:Event):void {  
//warning here  
**imageLoaderClip**.addChild(imageLoader);  
**preloader**.visible = false; } //

public function imageLoading(evt:ProgressEvent):void {  
var loaded:Number = evt.bytesLoaded / evt.bytesTotal; updateProgress(loaded); }

public function updateProgress(value:Number) {  
**preloader**.progress.width = value \* preloader.bar.width;  
} } }

**This works perfectly if this is the DocumentClass**.

BUT, if instead the DocumentClass is like this one:

package {  
import flash.display.MovieClip;  
public class LoadTest extends MovieClip  
{  
public function LoadTest()  
{**var img = new ImageLoader(“DSC04550.JPG”);** }  
}  
}

this doesn’t work anymore, because of the presence of the stage movieclips “preloader” and “imageLoaderClip”.

Which is the most common way to make the things work? I thought to pass a reference to the ImageLoader class as a parameter (eg I pass the preloader and the movieclip that loads the images). Is there any other (and better) way when dealing with situations like this one? Thank you!
