Jump to content

Chetan Sachdev

How to get loader url in progress handler

Recommended Posts

I am trying to get url in progresshandler. I tried typecasting event.target to LoaderItem, but it doesn't seem to work. event.target is of type LoaderMax. How can I get the currently loading item's url in progress handler ?


Please help..

Link to comment
Share on other sites

I don't often use LoaderMax, but does event.data have anything useful in it (maybe it's the current LoaderItem? I couldn't tell...)? You'll need to wait for one of the LoaderMax pro's for a definitive answer sorry.

Link to comment
Share on other sites

Hi Christian. Welcome to the GreenSock forums.


A LoaderMax can technically load many items simultaneously, so the when the progress event fires it isn't necessarily tied to 1 of the child loaders. The progress event only contains data associated with the object that fired that event, in this case your LoaderMax.


First, if you want to ensure that only 1 item is loading at a time, you can set the LoaderMax's maxConnections property to 1.


You have 2 options to figure out which child loader is currently loading.


1: assign onChildProgress or onChildOpen callbacks to the LoaderMax. Below is s brief example of using onChildProgress to gather the url of the currently loading item



import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;

//create SWFLoaders
var swf1:SWFLoader = new SWFLoader("child1.swf",{container:this,y:0,autoPlay:false});
var swf2:SWFLoader = new SWFLoader("child2.swf",{container:this,y:100, autoPlay:false});

//create and populate LoaderMax
var lm:LoaderMax = new LoaderMax({onProgress:progressHandler, onChildProgress:childProgressHandler, onComplete:completeHandler, maxConnections:1});


function progressHandler(e:LoaderEvent):void {


function childProgressHandler(e:LoaderEvent):void {
trace("loading " + e.target.url);

function completeHandler(e:LoaderEvent):void {

this will trace



loading child1.swf
loading child1.swf
loading child2.swf
loading child2.swf

2: you can use the LoaderMax method getChildrenByStatus() to get an array of all the children based on a status. Read here: http://api.greensock.com/as/com/greensock/loading/LoaderMax.html#getChildrenByStatus()




Link to comment
Share on other sites

Have you tried using the "currentTarget" of the event? Just like in Flash when you click on a particular DisplayObject and you've got a listener on the parent but the child was clicked, you can differentiate with target and currentTarget. 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.