March 22nd, 2007 by Kyle
Tags: accessor, ActionScript, calllater-calllater(), component, Flex
Posted in: ActionScript, Flex
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:
{
import mx.controls.Alert;
public class MyClass
{
public function set stuff(value:String):void{
Alert.show("setter for stuff: " + value);
}
public function junk(value:String):void{
Alert.show("function junk: " + value);
}
}
}
Here is a simple app demonstrating the workaround:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script>
<![CDATA[
public var foo:MyClass;
public function init():void{
foo=new MyClass();
}
]]>
</mx:Script>
<!–
The following will not compile with this error:
Error 1119: Access of possibly undefined property stuff through a reference with static type MyClass.
<mx:Button label="call setter within callLater"
click="callLater(foo.stuff,['bunch of stuff'])"/>
–>
<mx:Button label="call function within callLater"
click="callLater(foo.junk,['bunch of junk'])"/>
<mx:Button label="call setter within callLater"
click="callLater(function():void{foo.stuff=’bunch of stuff’})"/>
</mx:Application>
A complete Flex Builder 2.0.1 Project Archive (.zip) of this sample can be found here.
Tweet
1 Comment »

December 11th, 2009 at 12:09 pm
Thanks for the trick.
I wrote an article using the exact same trick to do complexe ArrayCollection on my blog.