Hi, I just recently started working with Flash CS3 and decided to try my fate in AS3. I did my research and read my sources and still I am having a problem with event handling on a button.
I want to have dynamic hover text on a series of buttons. Below I have implemented one of the buttons and I get this error at runtime:
TypeError: Error #2007: Parameter listener must be non-null.
at flash.events::E ventDispatcher/addEventListene r()
I understand the error, it thinks that onHoverEnter() is null but I have debugged and it seems not to be null to begin with. Please help.
Thanks,
Karl
[CODE=ACTIONSCRI PT]
lwrist.addEvent Listener(MouseE vent.MOUSE_OVER , captionFN(true, lwsttext, lwrist));
lwrist.addEvent Listener(MouseE vent.MOUSE_OUT, captionFN(false , null, null));
var xo:int;
var yo:int;
function captionFN(showC aption:Boolean, captionText:Str ing, bName:SimpleBut ton) {
if (showCaption) {
var hoverCaption:Mo vieClip = new MovieClip();
MovieClip(root) .addChild(hover Caption);
desc.capdesc.te xt = captionText;
desc.width = 7*desc.capdesc. text.length;
desc.alpha = 75;
//
if ((bName.width+b Name.x+desc.wid th)>stage.width ) {
xo = -2-desc.width;
yo = -17;
} else {
xo = 2;
yo = -17;
}
hoverCaption.ad dEventListener( "enterFrame ", onHoverEnter);
var onHoverEnter = function(ev:Eve nt):void {
desc.x = root.mouseX+xo;
desc.y = root.mouseY+yo;
desc.visible = true;
}
} else {
hoverCaption.re moveEventListen er("enterFrame" , onHoverEnter);
desc.visible = false;
}
}
[/CODE]
I want to have dynamic hover text on a series of buttons. Below I have implemented one of the buttons and I get this error at runtime:
TypeError: Error #2007: Parameter listener must be non-null.
at flash.events::E ventDispatcher/addEventListene r()
I understand the error, it thinks that onHoverEnter() is null but I have debugged and it seems not to be null to begin with. Please help.
Thanks,
Karl
[CODE=ACTIONSCRI PT]
lwrist.addEvent Listener(MouseE vent.MOUSE_OVER , captionFN(true, lwsttext, lwrist));
lwrist.addEvent Listener(MouseE vent.MOUSE_OUT, captionFN(false , null, null));
var xo:int;
var yo:int;
function captionFN(showC aption:Boolean, captionText:Str ing, bName:SimpleBut ton) {
if (showCaption) {
var hoverCaption:Mo vieClip = new MovieClip();
MovieClip(root) .addChild(hover Caption);
desc.capdesc.te xt = captionText;
desc.width = 7*desc.capdesc. text.length;
desc.alpha = 75;
//
if ((bName.width+b Name.x+desc.wid th)>stage.width ) {
xo = -2-desc.width;
yo = -17;
} else {
xo = 2;
yo = -17;
}
hoverCaption.ad dEventListener( "enterFrame ", onHoverEnter);
var onHoverEnter = function(ev:Eve nt):void {
desc.x = root.mouseX+xo;
desc.y = root.mouseY+yo;
desc.visible = true;
}
} else {
hoverCaption.re moveEventListen er("enterFrame" , onHoverEnter);
desc.visible = false;
}
}
[/CODE]