I'm not sure I understand.

The compiler is supposed to generate a closure for any parameters of type 
function.  Is it not doing that?  In ActionScript, you shouldn't need to mess 
with this/that/self.  I have not looked at any of the code involved, but 
assuming you are calling something defined like this:

public function setTimeout(fn:Function):void

Then the ActionScript for SWF should work like this:

Public class MyClass
{
   Public function MyClass()
   {
       setTimeout(myPrivateFunction);
   }
   private function myPrivateFunction():void
   {
   }
}

The Transpiler should then generate:

MyClass = function() {
    
setTimeout(org.apache.royale.utils.Language.closure(MyClass_myPrivateFunction, 
this, "myPrivateFunction");
}

MyClass.prototype.MyClass_myPrivateFunction = function() {};

And it should all work just fine.  If it isn't, start at the beginning and make 
sure the param for setTImeout is a Function and not an Object or *.  And see if 
the Transpiler generated the call to Language.closure.

HTH,
-Alex


On 12/3/18, 2:53 AM, "Harbs" <[email protected]> wrote:

    I just spent a long time tracking down a bug:
    
    I needed to delay execution of a private method called “doPackage()”. 
Because of “this” weirdness, I used “that” as a reference:
    setTimeout(function():*{that.doPackage()},50);
    
    And declared this as that:
    var that:* = this;
    
    The problem is that “doPackage” is now a fully qualified so doPackage is 
not defined.
    The solution is to declare the type of that like so:
    var that:PackagePanel = this;
    
    I’m not sure if there’s a way to resolve this better.
    
    Harbs
    
    

Reply via email to