Join Login


Video Tutorials
Blog



Royalty Free Images

Ui Loader Component


By: RiverCityGraphix      Views: 6338      Share: Bookmark and Share

In this tutorial, you will learn how to use the Ui Loader Component in Flash CS4.

The Ui Loader Component in Flash is great for loading in pieces of a whole project. Many users will never see an entire Flash file and will not want to wait while the entire file loads. It makes much more sense to load what they wan to see when they want to see it. This is what the ui loader allows you to do. You can bring in images, swfs, etc. dynamically from external sources and display then at runtime. You can also find the percentage loaded with the code used in this tutorial and display that to the user as well. The ui loader is a great component with many uses. Good luck using it in your projects.

ActionScript 3.0
var imgurl:String = "http://www.rivercitygraphix.com/images/barn.jpg";
var myrequest:URLRequest = new URLRequest(imgurl);
myloader.scaleContent = true;
myloader.load(myrequest);

myloader.addEventListener(Event.COMPLETE, loaddone);
myloader.addEventListener(ProgressEvent.PROGRESS, loadprogress);

function loadprogress (event:ProgressEvent):void{
percenttxt.text = Math.round(event.target.percentLoaded) + "%";
}

function loaddone (event:Event):void{
percenttxt.text = "";
}

//////////////////////////////////////////////////////////////////
btn1.label = "Image 1";
btn2.label = "Image 2";
btn3.label = "Image 3";
btn4.label = "Image 4";

btn1.addEventListener(MouseEvent.CLICK, loadimage1);
btn2.addEventListener(MouseEvent.CLICK, loadimage2);
btn3.addEventListener(MouseEvent.CLICK, loadimage3);
btn4.addEventListener(MouseEvent.CLICK, loadimage4);

function loadimage1 (event:MouseEvent):void{
var imgurl:String = "http://www.rivercitygraphix.com/images/barn.jpg";
var myrequest:URLRequest = new URLRequest(imgurl);
myloader.scaleContent = true;
myloader.load(myrequest);

myloader.addEventListener(Event.COMPLETE, loaddone);
myloader.addEventListener(ProgressEvent.PROGRESS, loadprogress);

function loadprogress (event:ProgressEvent):void{
percenttxt.text = Math.round(event.target.percentLoaded) + "%";
}

function loaddone (event:Event):void{
percenttxt.text = "";
}
}




function loadimage2 (event:MouseEvent):void{
var imgurl:String = "http://www.rivercitygraphix.com/images/butterfly.jpg";
var myrequest:URLRequest = new URLRequest(imgurl);
myloader.scaleContent = true;
myloader.load(myrequest);

myloader.addEventListener(Event.COMPLETE, loaddone);
myloader.addEventListener(ProgressEvent.PROGRESS, loadprogress);

function loadprogress (event:ProgressEvent):void{
percenttxt.text = Math.round(event.target.percentLoaded) + "%";
}

function loaddone (event:Event):void{
percenttxt.text = "";
}
}



function loadimage3 (event:MouseEvent):void{
var imgurl:String = "http://www.rivercitygraphix.com/images/bridge.jpg";
var myrequest:URLRequest = new URLRequest(imgurl);
myloader.scaleContent = true;
myloader.load(myrequest);

myloader.addEventListener(Event.COMPLETE, loaddone);
myloader.addEventListener(ProgressEvent.PROGRESS, loadprogress);

function loadprogress (event:ProgressEvent):void{
percenttxt.text = Math.round(event.target.percentLoaded) + "%";
}

function loaddone (event:Event):void{
percenttxt.text = "";
}
}


function loadimage4 (event:MouseEvent):void{
var imgurl:String = "http://www.rivercitygraphix.com/images/coast.jpg";
var myrequest:URLRequest = new URLRequest(imgurl);
myloader.scaleContent = true;
myloader.load(myrequest);

myloader.addEventListener(Event.COMPLETE, loaddone);
myloader.addEventListener(ProgressEvent.PROGRESS, loadprogress);

function loadprogress (event:ProgressEvent):void{
percenttxt.text = Math.round(event.target.percentLoaded) + "%";
}

function loaddone (event:Event):void{
percenttxt.text = "";
}
}




Free Source Files Zip

Fotolia