all groups > flash actionscript > may 2004 >
You're in the

flash actionscript

group:

Is it possible to...?


Is it possible to...? jigen3
5/9/2004 5:58:26 PM
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
Re: Is it possible to...? TimSymons
5/10/2004 12:14:56 PM
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
Re: Is it possible to...? jigen3
5/10/2004 1:19:46 PM
Re: Is it possible to...? jigen3
5/11/2004 2:53:22 PM
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
Re: Is it possible to...? TimSymons
5/11/2004 3:24:11 PM
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
Re: Is it possible to...? jigen3
5/11/2004 4:28:47 PM
(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
Re: Is it possible to...? julesguise
5/11/2004 4:41:57 PM
write it like this.

cityRef.onRelease = function(){
displayInfo();
Re: Is it possible to...? TimSymons
5/11/2004 5:19:59 PM
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
Re: Is it possible to...? jigen3
5/12/2004 9:45:39 AM
AddThis Social Bookmark Button