Adobe AIR 和不同的操作系统文件系统

发布于 2024-10-16 03:10:55 字数 2518 浏览 1 评论 0原文

另一个 Adob​​e Air 问题要问您,但首先这里是我负责的项目的一些背景知识。它是一个 AIR 应用程序,可以从 USB 闪存盘读取资源,并且必须在 WIN 和 MacOS 上运行。问题是,如何将资源加载到 MacOS 上的应用程序中!听起来很简单,并且可以在 Windows 上无缝运行。

这是我想要做的代码片段:

            var loader:Loader = new Loader(); 
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ok);
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);

            var p:String;

            if (os == "mac")
            {
                p = "/Volumes/" + keyVolume.rootDirectory.name + File.separator + "0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg";
            }
            else
            {
                p = keyVolume.rootDirectory.name + File.separator + "0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg";
            }

            var temp:File = new File(p);
            Debugger.Display.text += "\nAttempting to load: " + p;
            Debugger.Display.text += "\nDoes it exist? " + temp.exists;
            loader.load(new URLRequest(p));

...变量 OS 和 keyVolume 已在早期代码中成功设置。另外,我还为 ok() 和 ioErro() 定义了事件侦听器回调。

运行时,它会在 Windows 上打印:

Attempting to load: G:\0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg
是否存在:true

...然后成功加载资源。

在 MacOS 上,它打印出:

Attempting to load: /Volumes/AC/0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg
是否存在: true

...然后每次都会失败并出现 IOError 。

谁能看到我在这里缺少的东西吗?我是否有某种权限错误或其他问题(文件具有“读/写”访问权限)。 USB 闪存盘的格式为 MS-DOS FAT32,这可能是个问题吗?

编辑

我在 MacOS 中将新的 USB 闪存盘格式化为 FAT16,并将文件放入其中,但没有成功。问题依然存在。

编辑

我现在只是尝试从 /users/-USERNAME-/Desktop 加载资产,但仍然收到相同的错误,因此看起来这不仅仅是 USB 记忆棒上的权限问题,它比这更广泛。

编辑

问题已解决!我终于正确地措辞了我的 Google 搜索,它揭示了答案

这些更改将解决问题:

            var loader:Loader = new Loader(); 
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ok);
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);

            var p:String = keyVolume.rootDirectory.nativePath + ((os == "mac") ? File.separator : "") + "0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg";
            var temp:File = new File(p);
            Debugger.Display.text += "\nAttempting to load: " + temp.url;
            Debugger.Display.text += "\nDoes it exist? " + temp.exists;
            loader.load(new URLRequest(temp.url));

我还稍微改进了涉及操作系统检测的逻辑语句。

我希望有人觉得这很有用!

Another Adobe Air question for you but first here some background into the project I have been tasked with. It is an AIR app that will read assets from a USB key and must work on both WIN and MacOS. The problem is, how do I load assets into the app on MacOS! Sounds simple enough and works seamlessly on Windows.

Here is a code snippet of what i am trying to do:

            var loader:Loader = new Loader(); 
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ok);
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);

            var p:String;

            if (os == "mac")
            {
                p = "/Volumes/" + keyVolume.rootDirectory.name + File.separator + "0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg";
            }
            else
            {
                p = keyVolume.rootDirectory.name + File.separator + "0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg";
            }

            var temp:File = new File(p);
            Debugger.Display.text += "\nAttempting to load: " + p;
            Debugger.Display.text += "\nDoes it exist? " + temp.exists;
            loader.load(new URLRequest(p));

... the variable OS and keyVolume are being successfully set in earlier code. Also, I have the event listener callbacks defined as well for ok() and ioErro().

When this is run it prints out on windows:

Attempting to load: G:\0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg
Does it exist: true

... and then successfully loads the asset.

On MacOS, it prints out:

Attempting to load: /Volumes/AC/0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg
Does it exist: true

... and then fails with an IOError every time.

Can anyone see something that I am missing here? Do I have some sort of permission error or something (file has "read / write" access). The USB key is formatted in MS-DOS FAT32, could that be a problem?

EDIT

I formatted a new USB key in MacOS to FAT16 and put the files onto it with no success. Problems remain.

EDIT

I am now just trying to load an asset from /users/-USERNAME-/Desktop and still am receiving the same error, so it looks like it isn't a permissions issue on just the USB stick, it is more widespread than that.

EDIT

PROBLEM SOLVED! I finally worded my Google search correctly and it revealed the answer.

These changes will fix the problem:

            var loader:Loader = new Loader(); 
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ok);
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);

            var p:String = keyVolume.rootDirectory.nativePath + ((os == "mac") ? File.separator : "") + "0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg";
            var temp:File = new File(p);
            Debugger.Display.text += "\nAttempting to load: " + temp.url;
            Debugger.Display.text += "\nDoes it exist? " + temp.exists;
            loader.load(new URLRequest(temp.url));

I have also refined the logical statement involving the OS detection a bit as well.

I hope someone finds this useful!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2024-10-23 03:10:55

问题解决了!我终于正确地措辞了我的 Google 搜索,它揭示了答案

这些更改将解决问题:

            var loader:Loader = new Loader(); 
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ok);
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);

            var p:String = keyVolume.rootDirectory.nativePath + ((os == "mac") ? File.separator : "") + "0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg";
            var temp:File = new File(p);
            Debugger.Display.text += "\nAttempting to load: " + temp.url;
            Debugger.Display.text += "\nDoes it exist? " + temp.exists;
            loader.load(new URLRequest(temp.url));

我还稍微改进了涉及操作系统检测的逻辑语句。

我希望有人觉得这很有用!

PROBLEM SOLVED! I finally worded my Google search correctly and it revealed the answer.

These changes will fix the problem:

            var loader:Loader = new Loader(); 
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ok);
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);

            var p:String = keyVolume.rootDirectory.nativePath + ((os == "mac") ? File.separator : "") + "0a0ff0ff-f7ae-4b9c-9637-843b1d6c80e8.jpg";
            var temp:File = new File(p);
            Debugger.Display.text += "\nAttempting to load: " + temp.url;
            Debugger.Display.text += "\nDoes it exist? " + temp.exists;
            loader.load(new URLRequest(temp.url));

I have also refined the logical statement involving the OS detection a bit as well.

I hope someone finds this useful!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文