File() FileStream in web app

非 Y 不嫁゛ 提交于 2019-12-12 02:43:43

问题


I've made desktop app, and i want it to work also as an web app. I get errors on lines with File() type and FileStream, is there any way to bypass this ?


回答1:


To piggyback on @Florian F's correct response, here is how you might implement it:

Create an interface to abstract your file access

public interface IGetTheStuffService {
    function getSomeTofu():Tofu;
}

Create a file-based implementation

public class FileStuffService implements IGetTheStuffService {
    public function getSomeTofu():Tofu {
        // File-based implementation
    }
}

And an HTTP-based implementation

public class HTTPStuffService implements IGetTheStuffService {
    public function getSomeTofu():Tofu {
        // HTTP-based implementation
    }
}

In your consumer, rely on the IGetTheStuffService

[Inject] public var tofuService:IGetTheStuffService;

public function doSomeStuff():void {
    var tofu:Tofu = tofuService.getSomeTofu();
    // act on the tofu
}

Notice the Inject meta tag. This is where your Dependency Injection (DI) system would push in your dependency based on the configuration (FileStuffService for Air apps or HTTPStuffService for Web apps). Parsley and RobotLegs use [Inject] where fiex-ioc uses [IocBind]

Of course, you could go without a DI container... you would just inject the parameter directly.

But you get the idea... a pretty simple pattern, actually.




回答2:


The File() class is only available for AIR applications, that's why you get the error.

This is how I would do it :

  1. You need to isolate platform dependant code and put in a separate library.
  2. Other code that work the same whatever the platform should be in another isolated library.
  3. Create 2 projects that will be simple wrappers. A Flex project that is only coupled to the common code. An AIR Project that is coupled to both common and platform dependant code.

You'll then probably need to use Interfaces at some time to switch between implementations that are platform specific



来源:https://stackoverflow.com/questions/4802489/file-filestream-in-web-app

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