사이트 내 전체검색
[AS] SWF가 위치한 폴더 경로 반환 함수
최고관리자
https://cmd.kr/server/16 URL이 복사되었습니다.

본문

[AS] SWF가 위치한 폴더 경로 반환 함수

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* getFolderPath
* 무비클립이 위치한 폴더의 경로를 절대경로로 반환하는 함수
* @mc : 폴더의 경로를 알고자하는 무비클립
* @subFolder : 타겟 폴더의 경로
*/
getFolderPath = function(mc:MovieClip, subFolder:String):String{
        var url:String = mc._url;
 
        var protocol:String;
        var domain:String;
        var path:String;
 
        // set protocol
        if(url.indexOf("http://") >= 0){
                // web
                protocol = "http://";
        }else{
                // local
                protocol = "file:///";
        }
 
        var urls:Array = url.split(protocol);
        var paths:Array = urls[1].split("/");
 
        // set domain
        domain = paths.shift().toString() + "/";
 
        // remove filename
        paths.pop();
 
        // analyze subfolder structure
        if(subFolder == undefined){
                // none
                subFolder = "";
 
        }else if(subFolder.indexOf("/") == 0){
                // root
                paths = [];
                subFolder = subFolder.slice(1);
 
        }else if(subFolder.indexOf("../") == 0){
                // parent folder
                var subs:Array = subFolder.split("../");
                var count:Number = subs.length-1;
                for(var i:Number=0; i<count; i++){
                        subs.shift();
                        paths.pop();
                }
                subFolder = subs.join("/");
        }else{
                if(subFolder.indexOf("./") >= 0){
                        subFolder = subFolder.slice(2);
                }
        }// end if
 
        // set path
        path = paths.join("/");
 
        // make full path
        url = protocol + domain + path;
 
        // add sub folder to full path
        if(url.lastIndexOf("/") != url.length-1){
                url += "/";
        }// end if
        url += subFolder;
 
        // confirm if "/" is last character
        if(url.lastIndexOf("/") != url.length-1){
                url += "/";
        }// end if
 
        return url;
}// getFolderPath

전에 만들었던 함수를 개선하여, 매개변수로 하위 폴더 정보를 추가할 수 있도록 수정한 버전….

getFolderPath(this);
는 물론이고
getFolderPath(this, "./subfolder");
getFolderPath(this, "sub/subfonder");
getFolderPath(this, "../../../");
getFolderPath(this, "../../subfolder");
getFolderPath(this, "/");
getFolderPath(this, "/fubfolder");
와 같이 원하는 폴더구조를 입력하여 사용할 수 있습니다.

댓글목록

등록된 댓글이 없습니다.

1,139 (23/23P)

Search

Copyright © Cmd 명령어 18.118.119.229