Problem with onRelease set on dynamicly created mcs

  • posidan
  • Newbie
  • Newbie
  • posidan
  • Posts: 11

Post 3+ Months Ago

Hi!
Ok, im trying to do a photogallery here, dynamically loaded from a XML. The XML part is perfectly working, i can create my movieclips with no problem either, and place them where i want them. the thing now is that even if i try to add a onRelease event on each mc i dynamically create, it doesnt seem to work. Im sure its something really easy that i just dont understand, but im stuck here and the project is due in a week (with still many things to complete...)

So any help would be more than appreciated.

Heres the loop where i create my mcs and attach them to my thumbnail container mc:

Code: [ Select ]
for (i=0; i<_root.pix_number; i++) {
 // if theres more than 10 pictures, we add another film overlay
 if (count > 20) {            
  _root.film.thumbs.attachMovie("film_overlay","overlay"+i,i);
  new_film = _root.film.thumbs["overlay"+i];
  new_film._x = -1847;
  count = 1;
 }
                
 var mc = film.thumbs.pix_container.createEmptyMovieClip("mc" + i, i);
 // Position the new mc
 mc._x = 705 - (i*70 + (6.8*(i+1)));
 mc._y = 15;

 // Adds a event listener to the thumbnail so that when its clicked
 // it loads a picture in the photobucket
 mc.onRelease = function () {
  trace("mc clicked");
  // load photo in photobucket
 }
                
 var url = "images/" + pixArray[i].thumbnail;
 myLoader.load(mc, url);
 count++;
}
  1. for (i=0; i<_root.pix_number; i++) {
  2.  // if theres more than 10 pictures, we add another film overlay
  3.  if (count > 20) {            
  4.   _root.film.thumbs.attachMovie("film_overlay","overlay"+i,i);
  5.   new_film = _root.film.thumbs["overlay"+i];
  6.   new_film._x = -1847;
  7.   count = 1;
  8.  }
  9.                 
  10.  var mc = film.thumbs.pix_container.createEmptyMovieClip("mc" + i, i);
  11.  // Position the new mc
  12.  mc._x = 705 - (i*70 + (6.8*(i+1)));
  13.  mc._y = 15;
  14.  // Adds a event listener to the thumbnail so that when its clicked
  15.  // it loads a picture in the photobucket
  16.  mc.onRelease = function () {
  17.   trace("mc clicked");
  18.   // load photo in photobucket
  19.  }
  20.                 
  21.  var url = "images/" + pixArray[i].thumbnail;
  22.  myLoader.load(mc, url);
  23.  count++;
  24. }


myLoader is a qlod.loaderClass object here. I just cant click on the pictures to make them load a bigger one in the frame i have.

Any help would be greatly appreciated...THANKS
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

The loader is resetting your events on that clip when it is loaded.

Create a blank MC inside of var mc = film.thumbs.pix_container.createEmptyMovieClip("mc" + i, i); & name it "loader". Then assign onRelease to "mc" & load the thumbnail into "loader"
  • posidan
  • Newbie
  • Newbie
  • posidan
  • Posts: 11

Post 3+ Months Ago

ok, just to be sure i understand what you mean, i should do something like:

var mc = film.thumbs.pix_container.createEmptyMovieClip("mc" + i, i);
mc.createEmptyMovieClip("loader", i);

mc.onRelease = function () {
// code
}

myLoader.load(mc.loader, url);


Is that it? i cant try it right now, but ill try it tonight, and ill get back with results
thanks a lot!
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Pretty much.
Code: [ Select ]
mc.createEmptyMovieClip("loader", i);

"Loader" can be created a 0(zero) depth every time since it will be the only thing inside of "mc" :wink:
  • posidan
  • Newbie
  • Newbie
  • posidan
  • Posts: 11

Post 3+ Months Ago

woohoo!

works perfectly.

I cant thank you enough, you got me out of trouble here.

thanks again!
  • posidan
  • Newbie
  • Newbie
  • posidan
  • Posts: 11

Post 3+ Months Ago

Mmmm i still have one problem with my onRelease.

Now i can catch it, but when i try to load the large version picture when clicking on the thumb, i always get the last one loaded... my code looks like that currently:

Code: [ Select ]
            for (i=0; i<_root.pix_number; i++) {
                // if theres more than 10 pictures, we add another film overlay
                if (count > 20) {
                    _root.film.thumbs.attachMovie("film_overlay","overlay"+i,i);
                    new_film = _root.film.thumbs["overlay"+i];
                    new_film._x = -1847;
                    count = 1;
                }
                
                var mc = film.thumbs.pix_container.createEmptyMovieClip("mc" + i, i);
                mc.createEmptyMovieClip("thumb", 0);
                // Position the new mc
                mc._x = 705 - (i*70 + (6.8*(i+1)));
                mc._y = 15;
                mc.picture = pixArray[i];

                // Adds a event listener to the thumbnail so that when its clicked
                // it loads a picture in the photobucket
                mc.onRelease = function () {
                    _root.scene_mc.large_pic_mc.loadMovie("file://d:/Programmation/RogerioBarbosa/site/images/" + mc.picture.filename);
                }
                
                var url = "images/" + pixArray[i].thumbnail;
                myLoader.load(mc.thumb, url);
                count++;
            }
  1.             for (i=0; i<_root.pix_number; i++) {
  2.                 // if theres more than 10 pictures, we add another film overlay
  3.                 if (count > 20) {
  4.                     _root.film.thumbs.attachMovie("film_overlay","overlay"+i,i);
  5.                     new_film = _root.film.thumbs["overlay"+i];
  6.                     new_film._x = -1847;
  7.                     count = 1;
  8.                 }
  9.                 
  10.                 var mc = film.thumbs.pix_container.createEmptyMovieClip("mc" + i, i);
  11.                 mc.createEmptyMovieClip("thumb", 0);
  12.                 // Position the new mc
  13.                 mc._x = 705 - (i*70 + (6.8*(i+1)));
  14.                 mc._y = 15;
  15.                 mc.picture = pixArray[i];
  16.                 // Adds a event listener to the thumbnail so that when its clicked
  17.                 // it loads a picture in the photobucket
  18.                 mc.onRelease = function () {
  19.                     _root.scene_mc.large_pic_mc.loadMovie("file://d:/Programmation/RogerioBarbosa/site/images/" + mc.picture.filename);
  20.                 }
  21.                 
  22.                 var url = "images/" + pixArray[i].thumbnail;
  23.                 myLoader.load(mc.thumb, url);
  24.                 count++;
  25.             }



Note that pixArray is an array containing Picture objects, defined elsewhere in the code, but that simply contains a thumbnail filename, a filename, a name, a description and some other properties.

i cant seem to make it load the good picture... it loads all right, but with the same picture on each thumb.

Thanks for helping a noob. ;)
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

This should keep the last image from being used every time,
Code: [ Select ]
film.thumbs.pix_container["mc"+i].picture = pixArray[i];
film.thumbs.pix_container["mc"+i].onRelease = function () {
        _root.scene_mc.large_pic_mc.loadMovie("file://d:/Programmation/RogerioBarbosa/site/images/" + this.picture.filename);
      }
  1. film.thumbs.pix_container["mc"+i].picture = pixArray[i];
  2. film.thumbs.pix_container["mc"+i].onRelease = function () {
  3.         _root.scene_mc.large_pic_mc.loadMovie("file://d:/Programmation/RogerioBarbosa/site/images/" + this.picture.filename);
  4.       }

Which is replacing,
Code: [ Select ]
mc.picture = pixArray[i];

      // Adds a event listener to the thumbnail so that when its clicked
      // it loads a picture in the photobucket
      mc.onRelease = function () {
        _root.scene_mc.large_pic_mc.loadMovie("file://d:/Programmation/RogerioBarbosa/site/images/" + mc.picture.filename);
      }
  1. mc.picture = pixArray[i];
  2.       // Adds a event listener to the thumbnail so that when its clicked
  3.       // it loads a picture in the photobucket
  4.       mc.onRelease = function () {
  5.         _root.scene_mc.large_pic_mc.loadMovie("file://d:/Programmation/RogerioBarbosa/site/images/" + mc.picture.filename);
  6.       }
  • posidan
  • Newbie
  • Newbie
  • posidan
  • Posts: 11

Post 3+ Months Ago

woohoo again!

ok, of all board, this is the best. Fast and efficient answers, thank you very much.

id like to know though... in your first answer, you said that the load action resetted the onRelease event each time.....

being a programmer, i see MCs as objects, which they are, but if id do a loop like that in say, java, id create objects and their attributes would never be resetted... is there a concept i dont get here, im learning fast, but id like to understand why i got these errors (i mean, what causes them, what is the action stack when i do a loop like i did...)

if you have time, obviously.
thanks
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Not sure why Macromedia decided to do it this way but I guess they're thinking of it as,
The object/mc is a container, if somthing is being loaded into this container then the actions set before for that container may not be needed or may cause errors for the containers new content. Better reset thoose actions to null as to avoid any errors.

Now if you loadMovie & setup your loader to assign the event handelers once its content has been loaded then there is no need for a sub-mC to load content into. Using 3rd party loader classes tend to nix that ability though :( I find it easiest to just load things into sub-mcs & skip trying to syncronize everything.

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 17 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.