2013-06-13 5 views
1

외부 파일이 있는지 확인하고있는 경우 특정 동영상 클립의 표시 여부를 true로 변경하려고합니다. AS2에서 수행하는 방법을 알고 있지만 AS3에서 작업 중입니다.actionscript 3 : 외부 파일이 있는지 확인하고 동영상 클립 숨김을 확인하십시오.

이것은 내가 작업하는 데 사용되는 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에서 작동하게하는? 감사!

답변

4

클래스 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"); 
} 

필수 클래스를 가져 오는 것을 잊지 마세요.

+0

정말 고마워요! 완벽한 작품 :) – nezma

+0

@nezma 멋지다! SO에 오신 것을 환영합니다! 단순화를 위해 – Cherniv

3

AS3에서 할 수있는 다른 방법 (예 당신은 사용자의 문서 디렉토리에있는 파일을 검색하는 것으로 가정, 그에 따라 변경) :

var tmp_file:File = File.documentsDirectory.resolvePath('my_file.txt'); 

if (tmp_file.exists) { 
    // File exists 
} else { 
    // File doesn't exist 
} 
+0

upvote! – Craig

0
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 또는 타임 라인으로 표시되거나 전혀 표시되지 않습니다.

파일이 있는지 확인하려는 경우 위 코드를 사용하는 것이 좋습니다. 안드로이드에 대한 사용 공기는 당신이 사용할 수있는 경우 :

File.applicationStorageDirectory.resolvePath("my_file.txt"); 

네이티브 APPDATA 디렉토리에 저장합니다.