使File.nativePath可绑定?或者如何扩展flash.filesystem.file

时间:2010-11-23 15:12:05

标签: flex file air

我最终希望在Adobe Air中更改.nativePath可绑定或触发事件。我想我只是扩展了File类并且很好。

但我无法在任何地方找到它的来源(所以我知道如何扩展它)。我已经挖了http://opensource.adobe.com/svn/opensource/flex/sdk/了很多,没有看到任何东西。

有没有办法让.nativePath可绑定或扩展文件?

3 个答案:

答案 0 :(得分:1)

alxx,你的代码肯定很接近。谢谢 - 它给了我一个关于如何扩展它的想法。工作代码:

public class FileEx extends File
    {
        public function FileEx(path:String=null)
        {
            super(path);
        }

        [Bindable("nativePathChanged")]
        override public function get nativePath():String
        {
            return super.nativePath;
        }

        override public function set nativePath(value:String):void
        {
            super.nativePath=value;
            dispatchEvent(new Event("nativePathChanged"));
        }
    }

答案 1 :(得分:0)

File Class是Flash程序包的一部分,因此它不是开源的,您将无法掌握代码(除非您深入Adobe开发人员的核心圈子) 。

理论上你可以扩展类,因为它没有标记为final,并且使nativePath可绑定,但我不确定它的好处。您必须扩展您的用例以评估它。

答案 2 :(得分:0)

您不需要source来继承某些东西。只要它不是最终的,只需扩展它并覆盖您需要的东西:

public class BindableFile extends File {
    [Bindable(event="nativePathChanged")]
    override public function get nativePath():String {
        return super.nativePath;
    }
    override public function set nativePath(value:String):void {
        super.nativePath = value;
        dispatchEvent("nativePathChanged");
    }
}

未经测试,但看起来很逼真:)

相关问题