yishayw opened a new issue #143: Wrong "this" in Function given as Param
URL: https://github.com/apache/royale-compiler/issues/143
 
 
   Consider this App
   
   ```
   <mx:Application xmlns:local="*" xmlns:fx="http://ns.adobe.com/mxml/2009"; 
xmlns:mx="library://ns.apache.org/royale/mx" 
        width="600" height="400">
        <fx:Script>     
        <![CDATA[
   
                public function buttonFunction():void
                {
                        this.perform();
                }
   
                private function perform():void
                {
                        trace('done');
                }
        
        ]]>
        </fx:Script>
        <local:MyBox>
                <local:MyButton label="click"/>
        </local:MyBox>
   </mx:Application>
   ```
   
   Where MyButton is
   
   ```
   package 
   {
        import mx.controls.Button;
        import mx.events.MouseEvent;
   
        public class MyButton extends Button
        {
                private var _function:Function;
                public function MyButton()
                {
                        super();
                        addEventListener(MouseEvent.CLICK, clickHandler);
                }
                
                public function set clickFunction(value:Function):void
                {       
                        _function = value;
                }
   
                private function clickHandler(e:Event):void
                {
                        _function();
                }
   
        }
   }
   ```
   
   and MyBox is
   
   ```
   package 
   {
        import mx.containers.Box;
        import org.apache.royale.core.IChild;
        public class MyBox extends Box
        {
                
                public function MyBox()
                {
                }
   
                override public function 
addElement(c:org.apache.royale.core.IChild, dispatchEvent:Boolean = true):void
                {
                        (c as MyButton).clickFunction = 
parentApplication.buttonFunction;
                        return super.addElement(c, dispatchEvent);
                }
        }
   }
   ```
   
   Clicking the button results in 
   
   ```
   Examples.js:84 Uncaught TypeError: this.Examples_perform is not a function
       at MyButton.Examples.buttonFunction [as MyButton__function] 
(Examples.js:84)
       at MyButton.MyButton_clickHandler (MyButton.js:46)
       at Function.goog.events.fireListener [as googFireListener] 
(events.js:744)
       at Object.org.apache.royale.core.ElementWrapper.fireListenerOverride [as 
fireListener] (ElementWrapper.js:62)
       at HTMLButtonElement.goog.events.handleBrowserEvent_ (events.js:870)
       at HTMLButtonElement.f (events.js:289)
   ```
   
   Because "this" is MyButton instead of Examples
   
   
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to