flash actionscript:
hello, is it possible to dynamically load a button (or possibly a movieclip) from the library, and then dynamically attach pre-written on(release) event handlers and such to it/ them, so that they respond to mouseclicks? thx. jigen3
You could do this with the attachMovie command using a movieClip as a button. mcRef = this.attachMovie("mcButtonLinkName","newInstanceName",depth); mcRef.onRelease = nameOfExistingFunction; The function will need to be on the same timeline or you should include the path along with the function name, something like this: _root.movieClip1.functionName; HTH. Tim
actually...i seem to having a problem with the code...the function gets immediately called, even though i haven't pressed the button. the function gets called at the same time the movie gets attached. the function is written on the same area as the call to attachmovie())...hmm, am i missing something? jigen3
If you use the mcName.onRelease = nameOfFunction it should wait until you click on the mc. My last post might have been confusing when I mentioned the path. If the function is not on the same timeline but let's sya the _root level then your code should look something like this: mcName.onRelease = _root.nameOfFunction; Is this what you are trying? If it is please post your attachMovie code so that I can see if I can be more help. HTH. Tim
(dang, the timeout period for this forum is very short) i am using flash mx(not 2004), btw, and your previous explanation was pretty clear, but i don't think levels are the problem since i wrote the function called in the same page as the attachMovie(): cityRef = _root.emptyClip.Country_mc.attachMovie("City_bt", "City_bt", 305); cityRef. = displayInfo(); // just out of curiosity, i tried this line too, and got the same result as above //_root.emptyClip.Country_mc.City_bt.onRelease = displayInfo(); function displayInfo() { trace("it's in displayInfo"); _root.emptyClip.attachMovie("CityInfo_mc", "CityInfo_mc", 306); } also, the displayInfo() function doesn't get called on the City_bt's onRelease event, only once at start (when attachMovie is called). thx again. jigen3
write it like this. cityRef.onRelease = function(){ displayInfo();
Or you could write it like this: cityRef = _root.emptyClip.Country_mc.attachMovie("City_bt", "City_bt", 305); cityRef.onRelease = displayInfo; When assigning the function to the onRelease event don't use the "()" at the end of the function name. HTH Tim
Don't see what you're looking for? Try a search.
|