royale-asjs
royale-asjs copied to clipboard
Problem using element.addEventListener
When I add an event listener to an element, for example this way textInput.element.addEventListener('focus', onInputFocus), listeners previously assigned to the object (textInput in the example) are removed.
Trying this code seems to work ok:
Component Tester
package component
{
import org.apache.royale.core.StyledUIBase;
COMPILE::JS
{
import org.apache.royale.core.WrappedHTMLElement;
import org.apache.royale.html.util.addElementToWrapper;
import org.apache.royale.events.MouseEvent;
}
public class Tester extends StyledUIBase
{
public function Tester()
{
}
COMPILE::JS
override protected function createElement():WrappedHTMLElement
{
addElementToWrapper(this,'input') as HTMLInputElement;
element.setAttribute('type', 'text');
addEventListener(MouseEvent.CLICK, clickHandler);
return element;
}
COMPILE::JS
protected function clickHandler(event:MouseEvent):void
{
console.log("textinput clicked");
}
}
}
Then used:
<component:Tester/>
<j:Button text="add focus listener" click="addListenerToTester(event)"/>
and
private function addListenerToTester(event:Event):void
{
COMPILE::JS
{
console.log("adding listener");
event.target.element.addEventListener('focus', onInputFocus)
}
}
private function onInputFocus(event:Event):void
{
COMPILE::JS
{
console.log("onInputFocus");
}
}
@raudjcholo Can this be closed?