PDA

View Full Version : AS2 is possible Add code to an existing onRollOver Event???


astrix
02-24-2011, 10:56 AM
AS2 is possible Add code to an existing onRollOver Event???

I created a tooltip code and want to apply in the rollover event to some existing movieclips in my fla that have some code in your rollover event, is possible to add generally code to an existing onRollOver event...

For example, I have a movieclip that have:

mc.onRollOver = function() {
trace("hello")
}

And is possible to add dinamically to this code other onRollOver code from another function without eliminate the previous onRollOver function??? I need to add to some movieclips in the rollover event a function for show the tooltip... But I want to do generally, from a general function...

damTyD
02-24-2011, 01:41 PM
You could store the original function:

var storedAction:Function=myMovie_mc.onRollOver;

and then redefine it, but call the stored function as well

myMovie_mc.onRollOver=function(){
storedAction();
trace("added actions");
}

I wouldn't though. You would be better off handling your tool tips, like you said, with a general function, but define how each tooltip functions based on the object.

For example, if you just wanted to fill some different text for each Object, you could store that text in each object. myMovie_mc.tipText="custom text";

Then, when your rollOver fires, and you create your generic container for the tip, just fill the text with the Objects "tipText" property. Your tooltip object wont care which object it's handling (rolled over), it just needs the property that all of your roll over objects have.

astrix
02-24-2011, 02:51 PM
Ok, but not is automatically, I search for an action without modify any in the code of the fla, add automatically code dinamically to the onrollover event...

Also I experiment how you write, add simple a tooltip text variable to an mc, and search for a code in AS2 for search of a movieclip at mouse pointer, but are problems of stack overflow, for example, I have a Movieclip that added:

my__mc.tooltipMsg = "some text";

And search for the movieclips that mouse is over - sorry, I write actionscript how the old C, I not like the brackets how used standard in actionscrit, is more clear I believe how the old C use the brackets, but is a question of the look of the code, the code works equal -:


//This code search from _root for a movieclip that have tooltipMsg variable asigned
//But, grrr, this code do Stack Overflow if the fla have many MovieClip's
var lastClip:MovieClip = null;
function hitTestChildren(clip)
{
lastClip = null;
for(var i in clip)
{
if (typeof clip[i]=="movieclip")
{
if(clip[i].hitTest(_root._xmouse, _root._ymouse, true))
{
lastClip = clip[i];
if (lastClip.tooltipMsg != null && lastClip.tooltipMsg != undefined && lastClip.tooltipMsg != "")
break;
else
hitTestChildren(lastClip);
}
}
}
return lastClip;
}
onMouseDown = function()
{
trace(hitTestChildren(_root));
}


But this code do Stack Overflow if the Stage have many Mc with Many nested Mc's...

If is possible search around all the Movieclips in a movie, are possible automate, add a tooltip code to any fla without modify anything in the previous code of the fla, but appear to be is difficult search for the movie at the mouse pointer that have variable tooltipMsg...

my__mc.tooltipMsg = "some text";

And appear to be not is possible add dinamically code to an existing onRollOver... Uhmmm, difficult, how solution???

This are my 2 problems:

1.- Add dinamically code to an existing function, appear to be not is possible without any modification of the previous code - how you write damTyD, var storedAction:Function=myMovie_mc.onRollOver;, but is modify the previous code of the fla - ...

2.- Is possible locate the MovieClip's at mouse pointer???, if is possible, is possible check for if any Movieclip have a variable tooltipMsg, and after is easy general add tootltip code to any fla, simply is add the variable tooltipMsg to any movieclip that want to have tooltip action...

Thanks for your answer damTyD, but I search for a form to add tooltip code to any fla without modify nothing in the code of the fla - only add tooltipMsg variable to any Mc that want to have tooltip action -...

Any ideas??? Very thanks for your fast answer damTyD...

astrix
02-24-2011, 03:15 PM
Uhmmm, an idea, simply!!!

When add the tooltipMsg to a MovieClip, also add the MovieClip to an Array, and after is only search in all the movieclips in the array if any are below the mouse pointer - hitTest -, with this is very easy - I believe - add a tooltip to any old or new fla without modify any in the other code of the fla and not need onRollOver...

Are simple the solution... I need to check... After put an example...