# Preloader in a class?

**URL:** <https://forum.kirupa.com/t/preloader-in-a-class/290320>\
**Category:** flash\
**Created:** [June 12, 2009, 5:06pm UTC](https://forum.kirupa.com/t/preloader-in-a-class/290320 "2009-06-12T17:06:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sendoushi](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Sendoushi](https://forum.kirupa.com/u/Sendoushi)\
**Post date:** [June 12, 2009, 5:06pm UTC](https://forum.kirupa.com/t/preloader-in-a-class/290320/1 "2009-06-12T17:06:06Z")

</div>

Hi there people!  
It seems i moved myself to as3 ehehe.  
I was trying to build my own framework, for personal use solo.  
My first tryout was to make a Preloader class, let’s call it that.

Well but i’m having problems.  
First the code.  
At the fla I have the preloader inside of it progressbar and basebar.  
On the first action of the fla i have:

//position and rotation of the preloader  
var preposx:Number=stage.stageWidth/2 - preloader.width/2;  
var preposy:Number=stage.stageHeight/2 - preloader.height/2;

preloaderRotation(0);  
preloaderPosition(preposx, preposy);

//image load  
function iniciarApp():void {  
addChild(imageLoader);  
}

var imageLoader:Loader;

function loadImage(url:String):void {  
imageLoader = new Loader();  
imageLoader.load(new URLRequest(url));  
}  
//call functions  
loadImage(“pixelHouses.jpg”);  
eventosPreloader();

And here goes my .as :  
package {  
public class preloaderHorizontal {  
public function SetProgress(ProgValPrel:Number) {  
preloader.progressbar.width=ProgValPrel\*preloader.basebar.width;  
}  
public function preloaderPosition(PrelPosX:Number, PrelPosY:Number) {  
preloader.x=PrelPosX;  
preloader.y=PrelPosY;  
}  
public function preloaderRotation(value:Number) {  
preloader.rotation=value;  
}  
public function prelLoading(e:ProgressEvent) {  
var loaded:Number=e.bytesLoaded/e.bytesTotal;  
SetProgress(loaded);  
}  
public function prelLoaded(event:Event) {  
preloader.visible=false;  
iniciarApp();  
}  
public function eventosPreloader() {  
imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, prelLoading);  
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, prelLoaded);  
}  
}  
}

Now, first of all, i have to import the preloaderHorizontal.as how can i do it?  
Then… even though ( i tried as document class ) it didn’t work!  
Any ideas?

Other problem, on the "public function eventosPreloader() i come with some eventlisteners for the imageLoader, is there any way to make imageLoader variable?  
Because not all the mc will be called imageLoader of course!
