You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@royale.apache.org by GitBox <gi...@apache.org> on 2020/12/11 16:04:42 UTC

[GitHub] [royale-asjs] carlosrovira commented on issue #1001: Problem using element.addEventListener

carlosrovira commented on issue #1001:
URL: https://github.com/apache/royale-asjs/issues/1001#issuecomment-743279899


   Trying this code seems to work ok:
   
   **Component `Tester`**
   
   ```as3
   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:
   
   ```xml
   <component:Tester/>
   
   <j:Button text="add focus listener" click="addListenerToTester(event)"/>
   ```
   
   and
   
   ```as3
   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");
       }
   }
   ```
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org