The event broadcaster keeps a map of event types and the event listener. By
creating a new Delegate object everytime you are creating a new Listener.
So the broadcaster can no find the previous one to remove. If you want to
keep the Delegate ref stuff going. Try this:
class LogonWindowViewHelper extends ViewHelper {
private var keyPressDelegate:Delegate;
public function LogonWindowViewHelper() {
super();
keyPressDelegate = Delegate.create(this, this.enterKeyPressed);
}
public function addListenerForKeyStroke() {
view.username.addEventListener('keyUp', this.keyPressDelegate);
}
public function removeListenerForKeyStroke() {
view.username.removeEventListener('keyUp', this.keyPressDelegate);
}
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Andriy Panas
Sent: Friday, November 11, 2005 6:01 AM
To: [email protected]
Subject: [flexcoders] removing listener for "KeyUp" event from
<mx:TextInput> field
Dear flexcoders,
I have a problem with removing the custom listener for "KeyUp" event for
my <mx:TextInput> field. The new listener for 'KeyUp' event that I add
during 'focusIn' event never gets deleted.
Every time I move focus to the <mx:TextInput> field one new listener is
added for 'KeyUp' event and old listeners for 'KeyUp'
event stays intact too!
I end up with multiple calls to 'enterKeyPressed' function :(.
In my MXML I have the following entry:
------------cut MXML here--------------------- <mx:FormItem label="UserId"
required="true">
<mx:TextInput id="username" width="150"
focusIn="logonWindowViewHelper.addListenerForKeyStroke()"
focusOut="logonWindowViewHelper.removeListenerForKeyStroke()"/>
</mx:FormItem>
------------cut MXML here---------------------
where id "logonWindowViewHelper" is a instance of LogonWindowViewHelper AS
class assigned to the View.
2) LogonWindowViewHelper AS class:
-------------cut here AS class----------------------- import
org.nevis.cairngorm.view.ViewHelper;
class LogonWindowViewHelper extends ViewHelper {
public function LogonWindowViewHelper()
{
super();
}
/*--------------------------------*/
function addListenerForKeyStroke()
{
view.username.addEventListener('keyUp',
mx.utils.Delegate.create(this, this.enterKeyPressed));
}
/*--------------------------------*/
function enterKeyPressed (event)
{
if (event.code == 13)
{
logonHandler();
}
}
/*--------------------------------*/
function removeListenerForKeyStroke()
{
// this call does not underegister the listener!! :(
view.username.removeEventListener('keyUp',
mx.utils.Delegate.create(this, this.enterKeyPressed));
}
/*--------------------------------*/
function logonHandler()
{
}
-------------cut here AS class-----------------------
--
Best regards,
Andriy mailto:[EMAIL PROTECTED]
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~->
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/