Skip to main content
Inspiring
October 24, 2009
Question

Connect Gallery buttons rather than thumbnails?

  • October 24, 2009
  • 3 replies
  • 1529 views

This seems like it should be easy, but I cannot figure out how to do this in AS3. And after pouring through several books and lots of sample projects, no one quite seems to be using this method to create galleries.

The goal: A gallery with circles for buttons that, when clicked, move already loaded images into view.

I have built a widget that creates the buttons and loads the images, but how do I make a connection between one dynamically created sprite (the button) and another (the corresponding image)?

When adding children, is there a way to find its reference in the display object list? The buttons are named and will trace their names when clicked, but I don't see this when I'm listing the display objects. And I'm not sure how I can use these names or provide similar names for my loaded images. (My confusion is becoming evident here -- or at least clouding my mind -- so I'll just leave it at that.)

BTW, I have come across several tools/players that do something similar to what I want, but I'd prefer not to use someone else's controller. (It seems like the time to code this should be less than the time to skin/understand/customize someone else's FLA/SWF.)

Thanks,

Tim

This topic has been closed for replies.

3 replies

senortimAuthor
Inspiring
November 17, 2009

Success! I was in fact able to create an array of loaders. The errors I was getting were because of the (stupid) error of not specifying the size of my array before trying to get nth members of it.

I feel like my code is clunky, but it works. I used addChildAt() and getChildAt() to set the added graphics to an array. Then I used the names of the dynamically created buttons to get the indexes into this array.

The only question now is whether the graphics are being added in desired order or loaded order!

kglad
Community Expert
Community Expert
November 17, 2009

their depths will be determined by the depths of the loaders.  the time when they appear on stage will be determined by time it takes to load.

senortimAuthor
Inspiring
November 18, 2009

Great to know. Thanks!


oluc
Known Participant
October 25, 2009

If you are not opposed to loading the images through xml this is a great tutorial:

http://www.tutvid.com/tutorials/flash/tutorials/xmlSimpleGallery.php

If you need help after this I can probably help you. I used this tutorial and with a lot of help through study and forums, changed it to get pictures to slide on and off the stage with a next and back button.

I saw your BTW note, but I can give you my files if you are interested.

senortimAuthor
Inspiring
November 2, 2009

Thanks, Oluc. I didn't mean to imply that I'm not interested in other people's solutions! :-)  (I meant things in the Lightbox-vein, which can be difficult to skin, especially if the FLA isn't included.)

I would love to take a look at your file.

@kglad - I can set up logical connections between the buttons and graphics. I'm loading them in the same while loop. The buttons I'm naming "b_image1", etc. and putting in the sprite's name property. How do I get the "name" of a sprite I've added to a container. (My container is living within a static movieclip, which I'm using to mask the images.)

--Tim

senortimAuthor
Inspiring
November 2, 2009

That was weird; I thought I posted this a week ago, but it just popped back up in my browser! In any case, the question is still relevant. I haven't figured out the solution. :-(

kglad
Community Expert
Community Expert
October 24, 2009

there must be some logic to the relationship between a button and its corresponding image or, you must provide the link.  so, for example if your loader names were the same as your buttons names (but with "LDR" appended to the loader names), you have a logical enough setup that nothing more needs to be done.

if, however, you see no logic between your button names and loader names you will need to provide the relationship.  associative arrays are ideal for this.

senortimAuthor
Inspiring
November 17, 2009

It's no problem to use an index to link these. Ideally, I want Button_1 to control Image_1 and so having Loader_1 do this makes sense.

What I'm not seeing is how to do this with event listeners. I'm going to have lots of different functions referring to the loaders, and the only way I've used this so far in my AS3 career is with globals defined outside of functions on the timeline. (I've never used classes of my own creation.)

I've tried creating a global array of loaders, but Flash kicks out tons of errors, telling me I can't use null objects. Or I try doing something like this:

        var pictLdr+i = new Loader();

and get a syntax error.

I can envision that this is easier with classes (for an experience object oriented programmer!). But is there a way to do this without classes?

kglad
Community Expert
Community Expert
November 17, 2009

you can use:

this["pictLdr"+i] = new Loader();