PDA

View Full Version : plz, i'm really desperate


skyflower
07-10-2005, 07:55 PM
guys,

at least tell me if there's hope.

I'm trying to load jpegs of different sizes and and space them evenly. Here's my code:

total_images = _global.total;
h_pos = 10; // starting horizontal position of grid
v_pos = 10; // starting vertical position of grid
img_clips = new Array(); // movieclips to contain thumbs
img_urls = new Array(); // urls of the jpgs to be loaded as thumbs

for (i=0; i<total_images; i++) {
img_urls.push("images/img" + i + ".jpg"); // populate thumb_graphics with jpg urls
}

function loadImage(num:Number) {
// create container
initObj = {_x: h_pos, _y: v_pos};
curr = this.attachMovie("img_container", "ic" + num + "_mc", num, initObj);
img_clips.push(curr);
// load image
var imgURL = img_urls[num];
img_clips[num].loadMovie(imgURL);
img_clips[num].onEnterFrame = checkIfDone();
}

function checkIfDone() {
var lod = this.getBytesLoaded();
var tot = this.getBytesTotal();
if (lod && tot){
var percent_loaded = lod/tot;
if (percent_loaded == 1){
count++;
if (count < total_images) {
h_pos += this[img_clips[i]]._width;
loadImage(count);
}
delete this.onEnterFrame;
}
}
}

var count=0;
loadImage(count);



where _global.total is the total number of images to load.

so I figured where my problem is. I am creating bunch of empty movie clips and loading jpegs into them. Then, I'm keeping references to these movies in an array. Now, I have onFrameEnter event, that waits until jpeg is loaded, and then updates h_pos (the place to start next movie clip at) and goes to download next jpeg. So, all jpegs get downloaded, so my function works. But, the call to this._width always returns 115, and calls to img_clips[count]._width, or this[img_clips[count]]._width, or eval(img_clips[count])._width all return "undefined".

WHY??????????????????

I've seen people doing it on countless scripts, and mine is the only one not working. What am I doing wrong???

Oh, btw, if I change it so that all movies are created at coordinates (0,0), they are scattered all over the place horizontally.

PLZ HELP

sleekdigital
07-10-2005, 09:23 PM
First, are you sure what "this" refers to in this code? I have not done things this way in a while, so I'm not sure. Make sure you are checking the properties of the actual clip and not the main timeline.

Otherwise ...

Your width check is probably executing too early. For awhile, getBytesTotal() will be 0 or a really low number, so the code in your "if" statement will end up executing too early. Try changing this ..

if (percent_loaded == 1){

to this ...

if (percent_loaded == 1 && tot > 15){

and see if that does the trick for you. Sometimes I even just wait until the _width is greater than 0 to do anything with the clip...

if (myclip._width > 0) {

skyflower
07-10-2005, 09:39 PM
hi,

thanx for responding.

I tried your tricks and they don't work. I actually should mention that this is the first time I'm using arrays in actionscript, and I have a problem with referencing them.You said do if(my_clip._width > 0), well, my clips are all pushed into array. So if I do img_clips[i], I get "undefined", if I do eval(img_clips[i]), I get 0. So I can't use if(my_clip._width > 0) because the whole problem revolves around accessing my_clip._width

:(

sleekdigital
07-10-2005, 09:55 PM
I just did a quick check, and in your checkIfDone() function "this" will be a reference to your clip.

But this line ...
img_clips[num].onEnterFrame = checkIfDone();

Should be this...

img_clips[num].onEnterFrame = checkIfDone;

skyflower
07-10-2005, 10:09 PM
Okay,

It seems to work :D , although I'm not sure cause now my scroll pane doesn't update itself (all these images are inside scrollpane).

Could you please explain to me why I should omit parentheses in that function call? Isn't that like passing an address of that function? I come from C++, so to me some of the syntax is AS is really strange.

skyflower
07-10-2005, 10:17 PM
Okay, my scroll pane doesn't update anymore. :mad:
I put this.works_pane.refreshPane() at the very end of the script, and I have no scroll bar.

What's weird is that before I changed that function call the scroll bar appeared. :confused:

I don't get it.

sleekdigital
07-10-2005, 11:01 PM
Isn't that like passing an address of that function?

Yes, and that is exactly what you need to do. If you use the parens, the function executes and onEnterframe gets set to the return value. Without the parens, you are setting onEnterframe to the function itself (which is what we want) instead of the return value of the function.

I put this.works_pane.refreshPane() at the very end of the script, and I have no scroll bar.


If you are using the mx 2004 scroll pane, refreshPane is not an available method. You should use the invalidate() method.

If you are interested, I have some code that loads items into a scroll pane and allows you to set the spacing between items ...

http://www.layer51.com/proto/d.aspx?f=1396
http://www.sleekdigital.com/downloads/scrolllistexample.zip

skyflower
07-10-2005, 11:10 PM
thanx, thanx, thanx

but, my scrollpane still doesn't have any scrollbars :confused:

I tried the invalidate() in few different places, and it doesn't work

sleekdigital
07-10-2005, 11:15 PM
I would call it where you know all of your content is loaded and you are finished positioning the items. It has always worked fine for me. If you look at my code you can see I have a function that runs on an interval. It checks to see that all items are loaded are not. When they are loaded I call a function that positions all the items, and finally calls the scrollpane's invalidate method.

skyflower
07-10-2005, 11:21 PM
oh oh oh I fixed it!!! :rolleyes:

I dug in forums and found that I should call
_parent.invalidate()

instead of
this.works_pane.invalidate()
(that's the target that I got from the little target button in actions panel)


thanx, thanx, thanx :p :p :p :p :p :p :p

sleekdigital
07-10-2005, 11:26 PM
As long as you have a proper reference to your scroll pane and you are calling invalidate at the correct time, it will work.