English 中文(简体)
软体添加剂
原标题:Add setter in a prototype in Flex

在灵活性方面,你可以增加某类类型原型的功能,但你如何添加一套装置?

例如,通过<代码>A某些(非动力)类别,你可以这样做:

var o:Object = new A();
A.prototype.myFunction = function():void{trace("foo");}
o.foo();

这将称为<代码>foo功能。 但是,你如何添加一套物,以便把财产划上ter子(如果你宣布A类“正常”方式的 set子一样)。 因此,我希望的是:

// doesn t work!    
A.prototype["set myProperty"] = mySetter; 
o.myProperty = "test"; // should call mySetter

PS:选择原型是一种异常的事情,可以灵活操作,而不是我一般建议的内容。 但为了这个问题,只是假设有理由积极增加一套办法。

最佳回答

第1/2号行动对此提供了支持,呼吁增加财产(姓名、采集器、装置)。 可以在单个物体或原型上这样做。 即便有“es”旗帜,AS3也不支持这一点。

举例来说,这里说明如何做:

var A = function() {};

A.prototype.addProperty("myProp", 
    function() { 
        trace("myProp getter: " + this._myProp); 
        return this._myProp; 
    }, 
    function(value) {
        trace("myProp setter: " + value); 
        this._myProp = value; 
    });

var a = new A();
a.myProp = "testing";
var x = a.myProp;
问题回答

据我所知,没有办法使用老的搭乘机/打字机方法(实际上,我认为使用任何种类的假装的内部软体分班的总数为0)。

无论如何,采集器/打字器在打字的原型游戏中都有。 即便有,我也想到,除了你试图用闪电来弥补这种困难,还有更好的选择。 运动员的结构较好。 页: 1





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签