Skip to main content
July 18, 2009
Question

I can't add an onRelease to an attached movie clip

  • July 18, 2009
  • 2 replies
  • 950 views

Im pulling images from an xml file and I want to attach an onRelase and onRollOver event to each one, but it's not working

var thumbWidth = 24;

var thumbHeight = 24;

var xml = new XML();

xml.ignoreWhite = true;

xml.onLoad = function(loaded) {

if (loaded) {

for(i=1;i<=6;i++) {

var btn:MovieClip = holder_mc.attachMovie("thumb_mc","thumb_"+i+"_mc",i);

btn._x = i*128 - 126;

btn._xscale = thumbWidth;

btn._yscale = thumbHeight;

btn.onRelease = function() {

trace("clicked");

}

btn.loadMovie(xml.firstChild.childNodes[i-1].firstChild.firstChild.nodeValue);

}

}

};

xml.load("lookbook.xml");

I never get that trace

Thanks!

This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
July 18, 2009

if you don't understand basic preloading you'll find it easier to use the 2nd option i listed:


var thumbWidth = 24;

var thumbHeight = 24;

var xml = new XML();

xml.ignoreWhite = true;

xml.onLoad = function(loaded) {

if (loaded) {

for(i=1;i<=6;i++) {

var btn:MovieClip = holder_mc.attachMovie("thumb_mc","thumb_"+i+"_mc",i);

var targetMC:MovieClip = btn.createEmptyMovieClip("targetMC",0);

btn._x = i*128 - 126;

//scaling/sizing is also something best done after loading is complete

btn._xscale = thumbWidth;

btn._yscale = thumbHeight;

btn.onRelease = function() {

trace("clicked");

}

targetMC.loadMovie(xml.firstChild.childNodes[i-1].firstChild.firstChild.nodeValue);

}

}

};

xml.load("lookbook.xml");

I never get that trace

Thanks!

July 18, 2009

I've been trying to get it to load in a mc inside a button.  But I can't get that to work.  The code you gave also doesn't load the images either.  I've done pre loaders before but not for loadMovie and Every test i do to see if it's loaded seems to say its loaded, even though the onRelease still doesnt work.

I'm gonna keep trying to get your code to work, anything else I'm missing?

kglad
Community Expert
Community Expert
July 18, 2009

you can use a true button.  use a movieclip button.

kglad
Community Expert
Community Expert
July 18, 2009

you must wait until loading is complete before assigning mouse handlers or, even easier, load into a child movieclip of btn.

July 18, 2009

Thanks,

So how could I test to see if its loaded?

something like btn.onEnterFrame = function() {

     if(btn.getBytesLoaded > btn.getBytesTotal) {

          stuff

     }

}

?