You technically cannot do this, since callLater() actually takes a function as an argument and a setter is an accessor.

However, rules where meant to be broken (or at least worked around).

You can do it by creating a function inline which sets the property within your callLater invocation.

Here is a simple class with a method and a setter:

  1.  
  2. package
  3. {
  4.         import mx.controls.Alert;
  5.         public class MyClass
  6.         {
  7.                 public function set stuff(value:String):void{
  8.                         Alert.show("setter for stuff: " + value);
  9.                 }
  10.  
  11.                 public function junk(value:String):void{
  12.                         Alert.show("function junk: " + value);
  13.                 }
  14.         }
  15. }
  16.  

Here is a simple app demonstrating the workaround:

  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
  4.  
  5.         <mx:Script>
  6.                 <![CDATA[
  7.                         public var foo:MyClass;
  8.  
  9.                         public function init():void{
  10.                                 foo=new MyClass();
  11.                         }
  12.                 ]]>
  13.         </mx:Script>
  14.  
  15. <!–
  16.         The following will not compile with this error:
  17.  
  18. Error 1119:     Access of possibly undefined property stuff through a reference with static type MyClass.
  19.  
  20.         <mx:Button label="call setter within callLater"
  21.                 click="callLater(foo.stuff,['bunch of stuff'])"/>
  22. –>
  23.         <mx:Button label="call function within callLater"
  24.                 click="callLater(foo.junk,['bunch of junk'])"/>
  25.         <mx:Button label="call setter within callLater"
  26.                 click="callLater(function():void{foo.stuff=’bunch of stuff’})"/>
  27. </mx:Application>
  28.  

A complete Flex Builder 2.0.1 Project Archive (.zip) of this sample can be found here.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Add to favorites
  • LinkedIn
  • Reddit
  • RSS
  • Slashdot
  • Technorati
  • Tumblr
  • Twitter



1 Comment »