Referencing getter/setter functions in actionscript 3

为君一笑 提交于 2019-12-31 07:23:12

问题


How does one get a reference the the getter and setter functions in actionscript 3?

if a method is defined on the calls, e.g.

public function blah():String { ...}

I can get a reference to it by just saying blah or this.blah

How do get a reference to

public function get blah2():String {}
public function set blah2(b:String):void {}

Thanks!


回答1:


Original response:

Unfortunately, you will not be able to store references to those as functions. The getter and setter methods are actually built around the idea that you shouldn't be able to and they therefore function as a property.

Is there a reason that you need to reference the functions specifically?


The comment I'm responding to:

I want to dynamically add external interface methods based on custom metadata tags, e.g. [External]. I was able to do this for the regular methods, but I'm trying to extend this to getter/setters as well. To do this, I need to get a reference to the function dynamically, so I can execute it with the right args using the apply function.

I think you're better off using a multi-step approach in that case. Since getters and setters function as a property and not a method, it would make sense to test to see if it is a property and then simply assign it a value directly. Would you be able to use this:

if( foo.blah2 is Function )
{
    foo.blah2.apply( foo, arr );
}
else
{
    foo.blah2 = arr[ 0 ];
}


来源:https://stackoverflow.com/questions/1478923/referencing-getter-setter-functions-in-actionscript-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!