A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: gallery

  1. #1
    Junior Member
    Join Date
    Mar 2006
    Posts
    12

    gallery

    Hello all. I am attempting to create a photo gallery. This is my actionscript:

    frame11:
    cmc= 1;
    nmc= 1;

    frame12:
    tmc = "pix/tn"+nmc+".jpg";
    imc = "mc"+cmc;
    loadMovie(tmc, imc);

    frame13:
    if (cmc >= 3) {
    gotoAndPlay(14);
    };
    ;
    cmc=cmc+1;
    gotoAndPlay(12);

    frame14:
    stop();

    There are MC's on the stage with the naming conventions "mc1", "mc2", etc. My problem is that right now "tn1.jpg" loads into every movie clip, instead of loading "tn2.jpg" into "mc2" and so forth. I have used trace and the numbers are advancing appropriately & sequentially. I'm stumped, can anyone assist? Thank you.

  2. #2
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    Hi,

    It doesn't look as though you are incrementing nmc. Add this code to frame 13 at the bottom:

    nmc = nmc + 1;

    Or alternatively, just use cmc all the way through, since you want the numbers to match:

    tmc = "pix/tn"+cmc+".jpg";

    Hope this helps.

    PS. Think about your naming conventions. It's very confusing to read!

  3. #3
    Junior Member
    Join Date
    Mar 2006
    Posts
    12
    thanks... I'm so frazzled, that should have been apparent. I am having trouble now with setting onpress:

    tmc = "pix/tn"+nmc+".jpg";
    imc = "mc"+cmc;
    loadMovie(tmc, imc);
    imc.onPress = function() {loadMovie (nmc+".JPG", "PICHOLDER");
    };

    So, obviously this won't work because imc is not being seen as a variable. Once I change it to "mc1" or something, it functions fine.

  4. #4
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    Hi,

    You have set imc as a String, and you want it to be a MovieClip. Use eval() to evaluate the path and return the MovieClip:

    imc = eval("mc"+cmc);

    Hope this helps.

  5. #5
    Junior Member
    Join Date
    Mar 2006
    Posts
    12
    Where should I place this code? Replacing imc = "mc"+cmc with imc = eval("mc"+cmc) causes the swf to display just the one movie clip in the center of the stage...

  6. #6
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    Hi,

    I'm really not sure what you mean. Is it possible for you to upload the whole .fla for me to look at? Or at least all of the code that you have now?
    "If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton

  7. #7
    Junior Member
    Join Date
    Mar 2006
    Posts
    12
    sure, the fla is located at http://********openrecords.com/gallery.fla

    the first row of pictures are some models for my movieclip buttons actionscript...clicking on them will show what the behavior should be.

    Thanks. - James

  8. #8
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Location
    Leeds, UK
    Posts
    606
    Oh I see...

    The problem here is that when you define your on press event, Flash doesn't hard-code the value of nmc into the function - it stays variable. This means that you can change the value of nmc later on, and each of the onPress events will read the new value. In this case, all of the onPress events look up the most recent value of the nmc, which in this case is 4.

    The trick is to copy the value of nmc into a variable on the clip itself that won't change, like this:

    code:

    Frame 12:

    tmc = "pix/tn"+nmc+".jpg";
    imc = "mc"+cmc;
    loadMovie(tmc, imc);
    //Make a copy of nmc on the imc itself;
    eval(imc).ind = nmc;
    eval(imc).onPress = function() {
    //Now reference the copy instead of nmc;
    loadMovie(this.ind+".JPG", "PICHOLDER");
    };



    Hope this helps.
    "If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton

  9. #9
    Junior Member
    Join Date
    Mar 2006
    Posts
    12
    Quote Originally Posted by dmonkey
    Oh I see...

    The problem here is that when you define your on press event, Flash doesn't hard-code the value of nmc into the function - it stays variable. This means that you can change the value of nmc later on, and each of the onPress events will read the new value. In this case, all of the onPress events look up the most recent value of the nmc, which in this case is 4.

    The trick is to copy the value of nmc into a variable on the clip itself that won't change, like this:

    code:

    Frame 12:

    tmc = "pix/tn"+nmc+".jpg";
    imc = "mc"+cmc;
    loadMovie(tmc, imc);
    //Make a copy of nmc on the imc itself;
    eval(imc).ind = nmc;
    eval(imc).onPress = function() {
    //Now reference the copy instead of nmc;
    loadMovie(this.ind+".JPG", "PICHOLDER");
    };



    Hope this helps.
    The thing is, nmc is operating correctly... The proper clips are loading in the corresponding holders. Basically here's my pseudo-code:

    Initially, there are 9 movie clips named mc1, mc2, etc.

    //Initialize cmc & nmc ("cmc" represents the number of the current container mc, while "nmc" represents the variable number of the thumbnail jpg to be loaded)

    //Load the current jpg (tmc=tn1.jpg) into the current holder clip (imc=mc1)

    //Check cmc to see if we have loaded into the final holder (3 in this case)

    //If we have loaded into the final holder then stop

    //If we haven't loaded into the final holder then increment both cmc & nmc by 1 and reload the current jpg (tmc=tnX.jpg) into the current holder clip (imc=mcX)

    Now here is the part that is malfunctioning: I want to set the onpress for variable "imc".

    If I change the "imc" to a hard-coded clip such as "mc1" then everything operates appropriately. However, when leaving it as a "imc" or even _root[imc] I do not get the correct functionality.

    I hope this isn't too dilapidated. Thanks - James

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center