I am trying to write a smooth transition piece and I don’t know what is happening.
I left it last night and it was working, I think, now its not.
here it is.
function btnclick(event:Event):void
{
if(event.target == load1 || load2)
{
trace("working");
}
else
{
trace("not ");
}
}
on my stage, I have 3 buttons,
load1.addEventListener(MouseEvent.CLICK, btnclick);
load2.addEventListener(MouseEvent.CLICK, btnclick);
load3.addEventListener(MouseEvent.CLICK, btnclick);
the 3 buttons instances are
load1, load2 and load3.
When i click buttons load1 or load2, I get the trace “working”, but when I press button load3, i am still getting “working” when its supposed to say “not”
just to check i changed it to this:
function btnclick(event:Event):void
{
if(event.target == load1 || load2)
{
trace("working");
}
else if (event.target == load3)
{
trace("not ");
}
}
and the same problem, they all say “working”
Any ideas what it is that I am missing?
Try this:
But I recommend you to use
currentTargetinstead oftarget:The problem with you code was in
event.target == load1 || load2. And it is equivalent of(event.target == load1) || (load2)whereBoolean(load2)istrueifload2isn’tnull. Soevent.target == load1 || load2is alwaystruein your case.