Skip to main content
Participant
March 4, 2009
Answered

event listener confusion

  • March 4, 2009
  • 3 replies
  • 620 views
i've not tried to do anything odd with eventListeners up until now. i have a movieclip with multiple frames that i use AS to attach a textfield to it. problem is i have a eventlistener for when the mouse rollsover the movieclip to go to frame 3 of the movieclip.

here's my function
function doOver(evt:Event) {
evt.target.gotoAndStop(2);
}

however this is throwing the error

ReferenceError: Error #1069: Property selected not found on flash.text.TextField and there is no default value.
at Menu_fla::MainTimeline/doOut()

what's causing the textfield to suddenly take precedence and how do i stop it. when i trace the evt.target - it is my movieclip.
This topic has been closed for replies.
Correct answer luke3design__
Hi bluegenie_Sa,
the event.target refers always to the istance which dispatched the event, in your case the textField istance. But if you want to refer to the movieclip containing the textfield, in the listener function you have to use evt.currentTarget instead of evt.target. This because of event bubbling...but it's a long story...for clearity evt.target refers always to the component which dispatched the event. evt.currentTarget refers to the istance which is listening for that event.
I hope this might help ya!!!!
bye!

3 replies

Participant
March 4, 2009
you're a star - i was tracing currentTarget to check what it was but not putting that in to the gotoAndStop. Thanks alot.
:-)
Inspiring
March 4, 2009
I'm very happy you've found it useful. First times i was using flash i spent several hours to come around this!!!
bye!
Participant
March 4, 2009
argh sorry i pasted the wrong bits. the doOver and doOuts are exactly the same with exception to the frame the movieclip is directed to.

the selected property applies to the movieclip - which points to the same problem, it's referencing the textfield as the evt.target rather than the movieclip itself.

ReferenceError: Error #1069: Property gotoAndStop not found on flash.text.TextField and there is no default value.
at Menu_fla::MainTimeline/doOver()

any idea?
Inspiring
March 4, 2009
Your message is stating that your error occurs in the function doOut(), yet you are posting the function doOver(), so it is hard to tell what's going on, but it sounds like yot try to access a property called "selected", which is not existent with textfields. You mean selectable maybe?
luke3design__Correct answer
Inspiring
March 4, 2009
Hi bluegenie_Sa,
the event.target refers always to the istance which dispatched the event, in your case the textField istance. But if you want to refer to the movieclip containing the textfield, in the listener function you have to use evt.currentTarget instead of evt.target. This because of event bubbling...but it's a long story...for clearity evt.target refers always to the component which dispatched the event. evt.currentTarget refers to the istance which is listening for that event.
I hope this might help ya!!!!
bye!