« Alert component: non-modal pop-ups | Main | Customize your Help panel (in 5 easy steps) »

Checking a ScrollPane's download progress (or lack thereof)

Somebody emailed me recently about this topic, so I came up with a quick and dirty solution. Not sure if there's a better way, but thought that somebody out there may find this useful, so here it is:

1. Drag a ScrollPane component onto your Stage and give it an instance name of my_scrollPane.

2. Add the following ActionScript to frame 1 of the main timeline. (Watch for wrapping lines!)

my_scrollPane.addEventListener("complete", myLoaderCompleteListener); function myLoaderCompleteListener(eventObj:Object):Void { if (eventObj.target.getBytesTotal() == -1) { eventObj.target.visible = false; var t:TextField = eventObj.target._parent.createTextField("error_txt", 10, eventObj.target.x, eventObj.target.y, 100, 20); t.autoSize = "left"; t.text = "unable to load file"; return; } // continue setting up. } my_scrollPane.contentPath = "http://www.deseloper.com/thisImageFileDoesntExist.jpg";

3. Save and test.

Because the image file doesn't exist, the complete event is dispatched to the ScrollPane instance and getBytesTotal() returns -1. The complete listener checks that the image was successfully loaded. If not, the ScrollPane instance is hidden and a text field is created and displays an error message.

Voila.

Comments

Nice Jen. Much cleaner than using setInterval(). :)

Excellent coding Jen. this probably rude of me, since this is off the scrollpane topic, where can I email you regarding a problem that I have ( it is perhaps a good tutorial subject for you. Thois has to do loading icons to a list component thru xmlconnector.

hi jen, jerome here... tried your tutorials for newbies like me. so nice to have these available online. i keep myself updated with your articles. have already tried a few projects myself, and learning more... a roar from the islands of the philippines. thanks, mate!

is there any possibility that i can do this with datagrid also?

i mean progress bar to run while a datagrid is being populated with data

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement block must be terminated by '}'
my_scrollPane.addEventListener("complete", myLoaderCompleteListener); function myLoaderCompleteListener(eventObj:Object):Void { if (eventObj.target.getBytesTotal() == -1) { eventObj.target.visible = false; var t:TextField = eventObj.target._parent.createTextField("error_txt", 10, eventObj.target.x, eventObj.target.y, 100, 20); t.autoSize = "left"; t.text = "unable to load file"; return; } // continue setting up. } my_scrollPane.contentPath = "http://www.deseloper.com/thisImageFileDoesntExist.jpg";

Total ActionScript Errors: 1 Reported Errors: 1

hello Jen. im currently exploring the scroll pane component and i just read your topic. any idea why is it when i load several loadClip component within scroll pane, i cannot see the other loadclip component even if the vScrollPolicy is set to "true".

I'm having a hard time accessing a movieClip inside my scrollPane. I've made a function that loads different mc's using contentPath, but when I try to access buttons on the mc used in the scrollpane like this:

var filmstrip = my_sp.spContentHolder;
filmstrip.x_mc.x_btn.onRelease = function()
etc.

it works great the first time, but once I load another mc dynamically, it doesn't recognize "filmstrip" as the spContentHolder.

I know this is a little off topic from the tutorial, but I always find your explanations really great, so I thought I'd give it a try.
Thanks!
Wendy

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)