从本地 HTML 文件(在应用程序工作区中)访问本地图像(不在应用程序工作区中)时出现问题

发布于 2024-10-21 14:05:28 字数 662 浏览 3 评论 0原文

我有一个 HTML 框并从项目加载本地 html 文件。 在此 HTML 文件中,我使用 jquery,并且想从我的用户目录加载图像。 我从我的用户目录中看到图像,但 jquery 不起作用。 我收到此错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at crop/onLoaded()[/Flex Bundle/workspace/crop/src/crop.mxml:119]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.html::HTMLLoader/onCompleteTimer()
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()

但如果我从应用程序工作区加载图像,则一切正常(我看到图像并且 Jquery 工作)。

这是政策问题吗?该错误表明这是一个“空对象引用”问题,但这不可能是真的......

有什么想法吗?

达米安

I have a HTML box and load a local html file from the project.
In this HTML file I use jquery and I want to load an image from my user directory.
I see the image from my user directory but jquery doesn't works.
I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at crop/onLoaded()[/Flex Bundle/workspace/crop/src/crop.mxml:119]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.html::HTMLLoader/onCompleteTimer()
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()

But if I load an image from the app workspace, everything works fine (I see the image and Jquery works).

Is this a policy problem? The error says that is a "null object reference" problem, but this can't be true...

Any ideas?

Damian

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

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

发布评论

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

评论(2

清风挽心 2024-10-28 14:05:28

如果将图像放在另一个目录中是否有帮助?

您可以将图像文件放在“我的文档/myairapp”或/home/user/Documents/myairapp 中,然后使用以下命令打开它:

var original = air.File.documentsDirectory.resolvePath("myairapp/test.jpg");

根据文件所在的目录,您可能会遇到权限问题?

Does is help at all if you put the image in another directory?

You could put the image file in My Documents/myairapp or /home/user/Documents/myairapp then open it with:

var original = air.File.documentsDirectory.resolvePath("myairapp/test.jpg");

You could have a permission problem depending on the directory where the file is?

白馒头 2024-10-28 14:05:28

我的将文件从应用程序目录复制到自定义目录的解决方案:

变量:

private var fileName:String = 'config.xml';
private var workingDirectory:String = 'MyNewAppDir';
  1. 简短而简单:
var f:File = File.applicationDirectory.resolvePath(this.fileName );
f.copyTo( File.documentsDirectory.resolvePath(this.workingDirectory+"/"+this.fileName));

或者 2. 又长又复杂:

/**
 * read content
 */
var file:File = File.applicationDirectory.resolvePath( this.fileName );
var read:FileStream = new FileStream();
read.open(file, FileMode.READ);
var content:String = read.readMultiByte( read.bytesAvailable, "utf-8") ;
read.close();

/**
 * save content
 */
var write:FileStream = new FileStream();
write.open( File.documentsDirectory.resolvePath( this.workingDirectory + "/" + this.fileName ), FileMode.WRITE );
write.writeMultiByte( content, "utf-8" );
write.close();

My Solution for copying a file from the application directory to a self defined directory:

Vars:

private var fileName:String = 'config.xml';
private var workingDirectory:String = 'MyNewAppDir';
  1. Short and simple:
var f:File = File.applicationDirectory.resolvePath(this.fileName );
f.copyTo( File.documentsDirectory.resolvePath(this.workingDirectory+"/"+this.fileName));

OR 2. Long and complicated:

/**
 * read content
 */
var file:File = File.applicationDirectory.resolvePath( this.fileName );
var read:FileStream = new FileStream();
read.open(file, FileMode.READ);
var content:String = read.readMultiByte( read.bytesAvailable, "utf-8") ;
read.close();

/**
 * save content
 */
var write:FileStream = new FileStream();
write.open( File.documentsDirectory.resolvePath( this.workingDirectory + "/" + this.fileName ), FileMode.WRITE );
write.writeMultiByte( content, "utf-8" );
write.close();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文