我正在尝试检查外部文件是否存在,如果存在,则将某个影片剪辑的可见性的值更改为true。我知道如何在AS2中做到这一点,但我正在使用AS3。
这是我曾经使用过的AS2代码:
onClipEvent (load) {
fileExists = new LoadVars();
fileExists._parent = this;
fileExists.onLoad = function(success) {
//success is true if the file exists, false if it doesnt
if (success) {
_root.visiblity = 1;
//the file exists
}
};
fileExists.load('visibility.exe');//initiate the test}
}
如何让它在AS3中工作?谢谢!
发布于 2013-06-13 16:09:01
flash.net.URLLoader
类。来自Adobe ActionScript 3.0 Reference
var urlRequest:URLRequest = new URLRequest("visibility.exe");
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, urlLoader_error);
urlLoader.load(urlRequest);
function urlLoader_complete(evt:Event):void {
trace("file found");
}
function urlLoader_error(evt:IOErrorEvent):void {
trace("file obviously not found");
}
不要忘记导入所需的类。
发布于 2014-10-09 23:50:45
在AS3中有一种不同的方法(该示例假设您在用户的文档目录中搜索该文件,请对其进行相应的更改):
var tmp_file:File = File.documentsDirectory.resolvePath('my_file.txt');
if (tmp_file.exists) {
// File exists
} else {
// File doesn't exist
}
发布于 2016-03-16 10:10:25
var tmp_file:File = File.documentsDirectory.resolvePath('my_file.txt');
if (tmp_file.exists) {
// File exists
} else {
// File doesn't exist
}
“保持简单愚蠢”--亲吻
谢谢你的代码,我一直在苦苦挣扎。
.addEventListener(Event.COMPLETE, Myfunction)
在MC或时间线中不会触发一半的时间,在类或任何包含的代码中也不会触发。
如果你只是想看看文件是否在那里,我推荐上面的代码。如果你使用air for android,你可以使用:
File.applicationStorageDirectory.resolvePath("my_file.txt");
以存储到本机Appdata目录。
https://stackoverflow.com/questions/17081749
复制相似问题