View Full Version : ProgressEvent, What object is it currently Tracking?
Censor
January 25th, 2008, 08:48 AM
So I have set up a image gallery where I load data form XML then create an array of Sprites to loader the data. I'm not at my code at the moment so I will try to remember the basics of how it is, might not be correct. Hopefully you will get the Idea of what i'm asking though
So basically I create the loop, but contentLoaderInfo.addEventListeners Complete and progress to them as they go through the loop, like this...
for(var i:Number = 1; i <= Length of XML; i++){
myButtons[i] = new Loader();
myButtons[i].contentLoaderInfo.addEventListener(event.Progress Event, showProgress)
}
function showProgress(evt.PROGRESS){
trace(evt.target)// this is where I want to find out what its currently showing the bytesloaded too
trace( evt.bytesloaded)
}
That works great I have it tracing the progress of every image just fine. Now what I want is to be able to track what object it is showing the progress too, so if its myButton1 or myButton3. Or a way to remove the event listeners to those objects I created once they are completely loaded. I have tried a bunch of stuff nothing has worked I only can get data about the event taking place not the object causing it
Hopefully this makes some sense, to someone haha...
Thank you again everyone
Felixz
January 25th, 2008, 11:25 AM
.addEventListener(ProgressEvent.PROGRESS, showProgress);
.addEventListener(Event.COMPLETE,complete);
function showProgress(event:ProgressEvent) {
trace(event.bytesLoaded/event.bytesTotal,event.bytesLoaded)
}
function complete(event:Event) {
trace("complete");
trace(event.target.loader);
event.target.removeEventListener(ProgressEvent.PRO GRESS,showProgress);
event.target.removeEventListener(Event.COMPLETE,co mplete);
}
Censor
January 25th, 2008, 12:59 PM
.addEventListener(ProgressEvent.PROGRESS, showProgress);
.addEventListener(Event.COMPLETE,complete);
function showProgress(event:ProgressEvent) {
trace(event.bytesLoaded/event.bytesTotal,event.bytesLoaded)
}
function complete(event:Event) {
trace("complete");
trace(event.target.loader);
event.target.removeEventListener(ProgressEvent.PRO GRESS,showProgress);
event.target.removeEventListener(Event.COMPLETE,co mplete);
}
Ahhh so my problem was trying to do it on the ProgressEvent, and not the on complete Event.
Thank you very much!
Censor
January 25th, 2008, 07:32 PM
Ok this has helped me further down the line, but my problem is how do I make the output of ProgessEvent link to something. Like the progress of tbNail[1] and tbNail[2] into a text field for them. So text field one shows loaded % of tbNail[1] and not tbNail[2]
function showProgress(evt:ProgressEvent):void {
//trace(evt.currentTarget)
trace("Loaded:"+Math.round(evt.bytesLoaded/evt.bytesTotal*100)+"%");
loadProgress_txt.text = Math.round(evt.bytesLoaded/evt.bytesTotal*100)+"%";
}
// on jpeg complete load
function onLoadCompletes(evt:Event) {
evt.target.loader.removeEventListener(ProgressEven t.PROGRESS,showProgress);
evt.target.loader.removeEventListener(Event.COMPLE TE, onLoadCompletes);
stage.addChild(evt.target.loader);
}
// load jpegs and buttons attach listeners
function jpegPreLoad(num,thumb) {
tbNail[num] = new Loader();
tbNail[num].name = num;
tbNail[num].x = num*100;
tbNail[num].load(new URLRequest(thumb));
tbNail[num].addEventListener(MouseEvent.MOUSE_OVER, thumbOver);
tbNail[num].addEventListener(MouseEvent.MOUSE_OUT, thumbOut);
tbNail[num].addEventListener(MouseEvent.CLICK, thumbClicked);
tbNail[num].contentLoaderInfo.addEventListener(Event.COMPLETE , onLoadCompletes);
tbNail[num].contentLoaderInfo.addEventListener(ProgressEvent. PROGRESS,showProgress);
tbNail[num].filters = [blur];
}
Censor
January 25th, 2008, 08:02 PM
so I found a way around what I needed by not using the event listener for progress and a Enter Frame listener. There has to be a cleaner way but it gets the job done for now, any enlightenment on this would be great. I haven't found much info about progress events out there
function onEnter(evt:Event){
tbload[evt.target.name].text = Math.round((evt.target.contentLoaderInfo.bytesLoad ed/evt.target.contentLoaderInfo.bytesTotal*100))+"%"
// trace((evt.target.contentLoaderInfo.bytesLoaded/evt.target.contentLoaderInfo.bytesTotal*100)+"%")
}
// on jpeg complete load
function onLoadCompletes(evt:Event) {
//trace(evt.target.loader.name)
evt.target.loader.removeEventListener(ProgressEven t.PROGRESS,showProgress);
evt.target.loader.removeEventListener(Event.COMPLE TE, onLoadCompletes);
stage.addChild(evt.target.loader);
evt.target.loader.removeEventListener(Event.ENTER_ FRAME, onEnter);
}
// load jpegs and buttons attach listeners
function jpegPreLoad(num,thumb) {
tbNail[num] = new Loader();
tbNail[num].name = num;
tbNail[num].x = num*100;
tbNail[num].load(new URLRequest(thumb));
tbNail[num].addEventListener(Event.ENTER_FRAME, onEnter);
tbNail[num].contentLoaderInfo.addEventListener(Event.COMPLETE , onLoadCompletes);
// tbNail[num].contentLoaderInfo.addEventListener(ProgressEvent. PROGRESS,showProgress);
tbNail[num].filters = [blur];
tbload[num] = new TextField();
tbload[num].x = tbNail[num].x
stage.addChild(tbload[num])
}
webmaster4u
April 24th, 2008, 03:52 AM
I had the same problem, and posted about it. Been researching livedocs on ADobe for about an hour and Googling, then was browsing here and found your post.
Solved!
Thanks for the work around, as I've been trying to load some five 3d sprites dynamically (user input determines how many panels are on stage).
I want to show the loading progress for each element because high res pics are stored in each panel....
ProgressEvent gave me a headache for a while, I'll show you how it helped in a few. Thanks again!
peregrinus
May 24th, 2008, 10:48 AM
I've been working on this thing too, your script helpd me alot! Thanks!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.