Groups | Blog | Home
all groups > flash actionscript > november 2007 >

flash actionscript : Dynamic onPress


capitalino
11/2/2007 4:00:29 AM
I am trying to create a MovieClip at the root level, inside that MovieClip I am
creating several dynamic MovieClips. To each one of those MovieClips I am
trying to add an onPress event so I can do something as the MovieClips are
pressed. This is the code I have:

var vPos = 12;
var hPos = 10;
_root.createEmptyMovieClip("panel", _root.getNextHighestDepth());
for(i=0;i<Videos.length;i++) {
ln = i + 1
_root.panel.createEmptyMovieClip("loader"+ln,
_root.panel.getNextHighestDepth());
_root.panel["loader"+ln].loadMovie(Videos[i].attributes.vThumb);
_root.panel["loader"+ln]._y = vPos
_root.panel["loader"+ln]._x = hPos
hPos +=110;

_root.panel["loader"+ln].onPress = function() {
trace("Hello"+ln);
}

//form = new Object();
//form.click = function(eventObj){
// trace("Click");
//}
//_root.panel["loader"+ln].addEventListener("click", form);
}

Everything works except the onPress event

What am I doing wrong?


Your help is greatly appreciated,

kglad
11/2/2007 4:56:01 AM
you must wait until loading is complete before assigning mouse handlers to a
load target.

alternatively, you could load your files into a child movieclip of
_root.panel["loader"+ln] and then your mouse handlers assigned to
_root.panel["loader"+ln] would not be lost when loading starts.
kglad
11/2/2007 4:56:27 AM
AddThis Social Bookmark Button