Want to create a list of thumbnails; kind of desperate

I’ve been playing around for about 4 hours now and I can’t find the code to create a list of thumbnails, all 30x30 pixels and lined up at the bottom of the Stage (550x400).

I know I can create 20 symbols with 20 instance names, and access that through the code, but that takes a while. Isn’t there anyway I can create 20 separate movies, load 20 different gif’s in code without making it monsterous? Here’s what I was playing with and it’s not working:


var i = 0 ;
var numThumbs = 4;
//var width = 550;
var x = 15;
var y = 365;
//var middle = middle / 2 ;
var thumbNames = new Array();

for( i = 0; i < numThumbs ; i++ ) {
thumbNames* = “thumb” + (i+1);
}

for( i = 0; i < numThumbs ; i++ ) {
_root.createEmptyMovieClip( thumbNames*, 2 );
thumbNames*.toString()._x = x + (30 * i);
thumbNames*.toString()._y = y;
thumbNames*.toString().loadMovie(“thumb” + (i+1) + “.gif”);

}

Am I not allowed to do this? All i get is a blank screen.

I guess i’m just going to make all the thumbnails without using code?

Why can’t I just create a movie clip array?

Thanks in advance for the help.

  • Anthony

that business with the toString() will break if for sure. if you call toString it returns … wait for it … a string! ; )

once you’re dealing with a string, none of the movieclip methods will work on it.

i compacted what i think you’re trying to accomplish into a function, pass it the number of thumbnails to create:


function makeThumbs(n){
   var m,name;
   while(n--){
      name = "thumb" + (n+1);
      m = _root.createEmptyMovieClip(name, n);
      m._x = 15 + (30 * i);
      m._y = 365;
      m.loadMovie(name + ".gif");
   }
}

Beener got ya… I didn’t know that _root.creat… returned a movieClip object.

when I threw the toString’s in there; it was just messing around and I knew it wouldn’t work, hence my desperation!

In the flash help, under the createmptymovieclip heading it says that it returns nothing, so that’s why I didn’t try it. You can check it out, it’s Help\Flash\ContextHelp.htm if you have the help files.

Oh… all set now, thanks man.

yeah, it’s an error in the documentation. fyi, attachMovieClip also returns a reference to the attached clip. handy dandy!

beener, while I got your attention.

I’m baffled again as how to properly capture events with these new movieclips. I want it so that on a mouse rollover an image is displayed in the middle of the screen. Here’s what I have:

for( i = 0; i < numThumbs ; i++ ) {
var m;
m = _root.createEmptyMovieClip( thumbNames*, i + 1 );
m._x = x + (30 * i);
m._y = y;
m.loadMovie(“thumb” + (i+1) + “.jpg”);

//button action
m.onRollOver = function() {
	trace ( "rolled over" );
}
thumbMovies* = m;

}

But for now I just want a message to pop up, start simple ya know. I created an array thumbMovies so that the buttons would remain outside of the for loop so they could be accessed, however no message is popping up? I don’t see any listeners that need to be added?

Again, any help would be great.

Thanks.

hmm… the function should remain defined in the mc, which is in the array right?

use [code] tags for your code, it makes it much easier to read. or [php] tags if you prefer.

you don’t actually have an array of movieclips per se, but an array of references to movieclips. you’re clips are all on whatever timeline your running this code from.

your code traces for me. you’re testing your movie in the player right (ctrl-enter)? otherwise tracing won’t do anything. also, tracing will be disabled even when testing if that option is set in the publish settings.

Anyone?

Yea I’m testing inside the player.

I just have a single frame in my movie; just playing around. The tracing doesn’t work for me. I role over the image and I get nothing.

I’ve attached the fla I’m using… thanks for the help.

i think i know what’s up.

when you loadMovie your pics you’re replacing the old movie … along with all its event information.

i’ve run into this before. you’d think that moving the event assignment to after the loadmovie would work but it doesn’t. i guess flash needs more time to load the clip.

a solution is to create another clip in the created clip and load your movie into that. leave the event information in the first clip.

should do the trick!

Good call:


for( i = 0; i < numThumbs ; i++ ) {
var action,m;
action = _root.createEmptyMovieClip( thumbNames*, i + 1);
action._x = x + (30 * i);
action._y = y;
m = action.createEmptyMovieClip( i, i + 1 );
m.loadMovie(“thumb” + (i+1) + “.jpg”);

//button action
action.onRollOver = function() {
	trace ( "rolled over" );
}

}

Does the trick…

So what’s happening is that flash needs extra time to load the MC to enable a listener to handle events? Hmmm…

And about my coding style… are those flash coding styles? I come from c, c++, and java.

Again… THANK YOU.

-Anthony

yeah, i think so. flash can be a little strange about loading clips and code execution.

your coding style looks fine to me, however i’ve not much to compare it to, i’m actionscript born and bred.

when i asked you to use [code] tags, that’s just for the board. anything enclosed in [code] [/code] will preserve it’s whitespace / indentation. makes for readable code.

cheers.