Skip to main content
Participant
January 3, 2008
Question

Advanced photo gallery - need help with MCs

  • January 3, 2008
  • 1 reply
  • 163 views
Hello all. I have a photo gallery I am creating that can contain up to 120 images. Rather than create buttons and movie clips for each, I am hoping to dynamically build it with 1 movie clip. But I am having trouble with my code. Here's what I am trying to do:

Duplicate a movie clip on the stage with an instance name of e1, giving each successive MC an instance name of e[i+1]
load external images into each movie clip representing images e1 through e120
set the alpha of the movie clip to 50%

then onRollOver:
Set alpha to 100%, resetting to 50% onRollOut

onPress
assign a variable equal to the image loaded (e1 - e120)
pop up a box and pass the variable into it, which will then load a larger version of the same image being called from a different folder.

That being said, here's my flawed code

var i:Number;
for (i = 0; i < 119; i++) {
this.holder.duplicateMovieClip; //duplicates the MC holder already on the stage
this._name = "e"+i;
this["e"+i]_x = _x + 50;
this["e"+i]._alpha = 50;
this.loadMovie("images/thumbnails/e" + i + ".jpg");
}

This code is not working on anything other than the first MC.

Here is the code for mouseover functions:

var i:Number;
for (i = 0; i < 119; i++) {
this["e"+i].onRollOver=function() {this["e"+i]._alpha=100};
this["e"+i].onRollOut=function() {this["e"+i]._alpha=50};
this["e"+i].onPress=function() {
_root.myVar = ["e"+i];
_root.myLargeImage.gotoAndPlay(2)
}
}

The problem with this section of code is that the dynamically loaded movie clips do not accept any event commands (onRollOver, onPress, etc). It is fine before I load external jpegs, but not noce they are loaded

Any help would be GREATLY appreciated.
Thanks
This topic has been closed for replies.

1 reply

Inspiring
January 4, 2008
You rollover code doesn't work because you are assigning the functions
before you load the images. The loaded images remove your code. You should
not use loadMovie and use the MovieClipLoader class instead. Then, in its
onLoadInit method you can assign your functions - so that they are assigned
after the clip is loaded. Also, I'd either just create empty clips, on the
fly, to load into or attach from the library. And duplicateMovieClip is not
a property it is a method - calling like you are doing will not work. If
you'd look in the Help you'll see that duplicateMovieClip can accept an init
object, and also returns a ref to the new clip... So your code can be much
simplified:

this.holder.duplicateMovieClip; //duplicates the MC holder already on the
stage
this._name = "e"+i;
this["e"+i]_x = _x + 50;
this["e"+i]._alpha = 50;

To:

this.holder.duplicateMovieClip("e" + i, this.getNextHighestDepth(),
{_x:theX, _alpha:50});

And you can't set _x to _x + 50 like that... for one you'd need to use more
like this._x = this._x + 50 or this._x += 50. But it still won't work here
since all the new clips are going to be created at x=0. You need to
increment a variable... or base the spacing on your loop variable, i - like
i *50.


--
Dave -
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/


drn24Author
Participant
January 5, 2008
Dave,

Thank you for your help. I modified my code with yours, made some adjustments, and it it working. Thanks again!