I'm trying to check if an external file exists and if so change the value of the visibility of a certain movie clip to true. I know how to do it in AS2, but I'm working in AS3.
This is the AS2 code that I used to work with:
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}
}
How to make it work in AS3? Thanks!
Class flash.net.URLLoader
. From 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");
}
Don't forget to import required classes.