homepage Welcome to WebmasterWorld Guest from 54.204.127.59
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
Forum Library, Charter, Moderator: open

Flash and Shockwave Forum

    
Dynamic Thumbnails and Dynamic Images
Sending variables to a function.
inveni0




msg:3857741
 8:12 pm on Feb 25, 2009 (gmt 0)

I have a problem that is a bit difficult to describe, but I'll try my best.

I am building a custom thumbnail gallery. The application reads an xml file and populates thumbnails based on how many are provided in the xml script. This all works great.

My next step is to make the thumbnails clickable. When the user clicks the thumbnail, it should create a MovieClip from my library and load an image into a UILoader within that clip. My thumbnails and full size images are each loaded into XMLList variables. The index numbers match. This works, but with a flaw. The actionscript I have does not know which full image goes with which thumbnail. The code looks like this:


//make thumb clickable
MovieClip(getChildByName("thumb"+nt)).buttonMode = true;// creates the hand cursor
MovieClip(getChildByName("thumb"+nt)).addEventListener("click", openImage);
function openImage(obj:Object) {
var image:imageView = new imageView();
image.name = "image";
addChild(image);
MovieClip(getChildByName("image")).imageClose.buttonMode = true;
MovieClip(getChildByName("image")).addEventListener("click", closeImage);
MovieClip(getChildByName("image")).imageFull.source = document.imageList[t];
}

As you can see, the problem is that my variable 't' ages as each thumbnail is created. Now, when the user clicks a thumbnail, it attempts to load document.imageList[t], where 't' does not exist within my array of file names.

What I've been trying to do to solve this problem is pass a variable to the openImage function:


//make thumb clickable
MovieClip(getChildByName("thumb"+nt)).buttonMode = true;// creates the hand cursor
MovieClip(getChildByName("thumb"+nt)).addEventListener("click", openImage(t));
function openImage(view:Number) {
var image:imageView = new imageView();
image.name = "image";
addChild(image);
MovieClip(getChildByName("image")).imageClose.buttonMode = true;
MovieClip(getChildByName("image")).addEventListener("click", closeImage);
MovieClip(getChildByName("image")).imageFull.source = document.imageList[view];

As you can see, I'm trying to openImage(t) on click, and then using saving that value of 't' as 'view' within the function openImage, so that, when creating the thumbnail, it's onClick event is registered with the appropriate image index number. But this doesn't work.

Any ideas? I feel like this brick wall is about to fracture my skull.

 

inveni0




msg:3860157
 2:06 am on Mar 1, 2009 (gmt 0)

Geez...did this forum die?

Anyhow, I crafted a work around. Basically, I hid a textfield in my thumbnail. Now, when it's created, I store the path to the full image in that text box. Then, within my onClick event, I use currentTarget to get the value of that text box.

It's not the cleanest way, but it works!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved