Skip to main content
June 7, 2009
Question

Run Time MovieClip eventListeners

  • June 7, 2009
  • 1 reply
  • 637 views

I'm working on an image gallery which builds dynamically at runtime, simple enough.

imageList is an array loaded with the images to display.

(sorry for the mess, work in progress)

var imageList:Array = _root.images.split(",");
var imageArray = new Array();
var count = 0;
for( var i = 0; i < imageList.length; i++ ){
    _root.createEmptyMovieClip("myMC"+i, (i + 1));
    _root["tmpMCL"+i] = new MovieClipLoader();
    imageArray = new Array();
    imageArray = this.createEmptyMovieClip("myMC"+i, (i + 1) );
    _root["tmpMCL"+i].loadClip("imagemaker.php?src="+imageList, imageArray);
}


imageArray[0]._x = 10;
imageArray[0]._y = 10;
for( i = 1; i < imageArray.length; i++ ) {
    imageArray._x = (( i % 3 ) * 160 ) + 10;
    imageArray._y = (Math.floor( i / 3 ) * 160 ) + 10;
}

The images load, in rows of 3, without any trouble.  However, I would like to create an onClick or onMouseUp event that will send out  a getURL('') command for each of the MovieClips, with differing urls for each obviously, for viewing the full size images.

I've tried doing...

imageArray.onMouseUp = function() {}

imageArray.onClick = function() {}

imageArray.addEventListener( MouseEvent.MOUSE_UP, function() {} )

even a nested...

imageArray.addEventListener( Event.ENTER_FRAME, function() { imageArray.onMouseUp = function () {} } )

But nothing ever happens when I run the file and click on a thumbnail.

Any suggestions?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
June 7, 2009

try:

var imageList:Array = _root.images.split(",");
var imageArray = new Array();
var count = 0;

var dep:Number=0;

var mcl:MovieClipLoader=new MovieClipLoader();
for( var i = 0; i < imageList.length; i++ ){
    //_root["tmpMCL"+i] = new MovieClipLoader();  // you only need one mcl
  //  imageArray = new Array();  // this doesn't look right

var parentMC:MovieClip=this.createEmptyMovieClip("parentMC"+dep, dep++)

var mc:MovieClip = parentMC.createEmptyMovieClip("myMC", dep++)

    imageArray.push(parentMC);

parentMC.ivar=i;
mcl.loadClip("imagemaker.php?src="+imageList, mc);

parentMC.onRelease=function(){

// getURL(something dependent on this.ivar);

}

}


imageArray[0]._x = 10;
imageArray[0]._y = 10;
for( i = 1; i < imageArray.length; i++ ) {
    imageArray._x = (( i % 3 ) * 160 ) + 10;
    imageArray._y = (Math.floor( i / 3 ) * 160 ) + 10;
}


June 7, 2009

This made it so the clips would actually do something, though with some changes,

var imageList:Array = _root.images.split(",");
var imageArray = new Array();
var count = 0;

var dep:Number=0;

var mcl:MovieClipLoader=new MovieClipLoader();
for( var i = 0; i < imageList.length; i++ ){
    //_root["tmpMCL"+i] = new MovieClipLoader();  // you only need one mcl
  //  imageArray = new Array();  // this doesn't look right

var parentMC:MovieClip=this.createEmptyMovieClip("parentMC"+dep, dep++)

var mc:MovieClip = parentMC.createEmptyMovieClip("myMC", dep++)

    imageArray.push(parentMC);

parentMC.ivar=i;
mcl.loadClip("imagemaker.php?src="+imageList, mc);

parentMC.onRelease=function(){

// getURL(something dependent on this.ivar);

}

}

Yes, this made things work, with a little tweaking.  I used i instead of dep, no real reason to have two counters that I can see, having parentMC and mc on the same level ( i + 1 ) seems to work just fine.

Also, using imageArray.push(parentMC) does not ensure that th parentMC.ivar assignment will be truthful, and ends up using the onRelease function for the wrong MC when I try clicking on one.  imageArray = parentMC fixed the problem.

I'm still not sure why mine didn't work, unless it was simply using onRelease over the other event types, along with some sloppy coding, hehe.

One more thing, the images are not showing up when the page is viewed in IE, the flash file loads up fine, as I can see other, none-dynamic, elements in the flash file, but for some reason the gallery images themselves just dont show up.

As you can see from my code, I filter every image through a php script (imagemaker.php) which turns every image into a thumbnail for faster viewing.  Does anyone know why the image in the gallery might now show up when viewed using Internet Explorer? ( I don't know if this problem persists with other browsers, only that it works on FireFox and not on IE )

kglad
Community Expert
Community Expert
June 7, 2009

the code i gave should work without any tweaking.  that said, you can change things or do things differently and that may work just as well.

all the images (assuming your php file is returning the correct path/file names correctly) will load into the upper left because parentMC and mc aren't changed from their default positions.

if you fail to see any images correctly, check your php file's return.