Hi,
I have added an event “changing” to a List component and when I am trying to remove the same, its not removing. Following is the code.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import spark.events.*;
private function preventSelection():void
{
}
private function removeHandler():void
{
ExternalInterface.call('console.log', cb.hasEventListener(IndexChangeEvent.CHANGING));
cb.removeEventListener(IndexChangeEvent.CHANGING, preventSelection);
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout />
</s:layout>
<s:List id="cb" labelField="name" changing="preventSelection()"></s:List>
<s:Button id="btn1" label="Remove Event" click="removeHandler()"></s:Button>
</s:Application>
When I click the button, the first time I see “true” as output in console which is correct since the event is added, but I see the same “true” as output even though when I click the button again and again. So the fact is that the event is not removed. I tried to inspect the issue and generated actionscript and what I see is the below code (only required code part is added)
private function _Main_List1_i() : spark.components.List
{
var temp : spark.components.List = new spark.components.List();
temp.labelField = "name";
temp.addEventListener("changing", __cb_changing);
temp.id = "cb";
if (!temp.document) temp.document = this;
cb = temp;
mx.binding.BindingManager.executeBindings(this, "cb", cb);
return temp;
}
public function __cb_changing(event:spark.events.IndexChangeEvent):void
{
preventSelection()
}
Then in the application, I have changed to remove the “__cb_changing” handler instead of “preventSelection”.
private function removeHandler():void
{
ExternalInterface.call('console.log', cb.hasEventListener(IndexChangeEvent.CHANGING));
cb.removeEventListener(IndexChangeEvent.CHANGING, __cb_changing);
}
Now I am able to see “false” from second time onwards which is expected behaviour. **So is this a bug? **
Files are attached for your reference, please add your view.