[FlashLite1.1] 중복없이 랜덤으로 데이터 가져오기

Flash Lite — Tags: , — Siaa @ 10:46 am

다수의 데이터가 있고 그 데이터중에서 랜덤으로 몇개만 가져오고 싶을 경우~ 단, 중복되면 안 될 경우!!!
배열을 사용하면 간단히 해결되겠지만, FlashLite1.1 에서는 배열을 쓸 수 없다;;
이럴 경우 아스키코드를 사용하면 조금은 복잡하지만 해결 할 수 있다.

random_num = 3;    //랜덤으로 가져올 데이터 수

text_1 = "TEXT-01";
text_2 = "TEXT-02";
text_3 = "TEXT-03";
text_4 = "TEXT-04";
text_5 = "TEXT-05";
text_6 = "TEXT-06";
text_7 = "TEXT-07";
text_8 = "TEXT-08";
text_9 = "TEXT-09";
text_10 = "TEXT-10";
text_11 = "TEXT-11";
text_12 = "TEXT-12";
text_13 = "TEXT-13";
text_14 = "TEXT-14";
text_15 = "TEXT-15";

order_num = "ABCDEFGHIJKLMNO";    //전체 데이터의 수(15개)

for (i = 1; i <= _root.random_num; i++) {
    rn = random(length(order_num)) + 1;
    _root["n" add i] = substring(order_num, rn, 1);
    if (rn == 1) {
        order_num = substring(order_num, 2, length(order_num));
    }
    else {
        a_txt = substring(order_num, 1, rn - 1);
        b_txt = substring(order_num, rn + 1, length(order_num));
        order_num = a_txt add b_txt;
    }
    _root["n" add i] = ord(_root["n" add i]) - 64;
    textData = eval("text_" add _root["n" add i]);
    trace("textData = " add textData);
}

아스키코드 표
ascii

Share

0 Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2012 blog.flasia.com | powered by WordPress with Barecity