flash on 2012-6-25

by tepe
♥0 | Line 112 | Modified 2012-07-04 11:28:51 | MIT License
play

ActionScript3 source code

/**
 * Copyright tepe ( http://wonderfl.net/user/tepe )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1KrQ
 */

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.text.*;
    import flash.net.*;
    
    public class FlashTest extends Sprite {
        private var list:Object = new Object();
        private var list2:Array = new Array();
        private var listNum:int = 10;
        private var so:SharedObject;
        private var tf1:TextField = new TextField();
        private var tf2:TextField = new TextField();
        private var tf3:TextField = new TextField();
        private var tf4:TextField = new TextField();//出題
        private var tf5:TextField = new TextField();//入力
        
        public function FlashTest() {
            
            addChild(tf1);
            addChild(tf2);
            
            //tf4.border = true;
            tf4.y = 200;
            tf4.x = 200;
            tf4.text = "ここに出題";
            tf5.border = true;
            tf5.type = "input";
            tf5.y = 200;
            
            addChild(tf4);
            addChild(tf5);
            tf2.x = 200;
            init();
            //so.clear();
            tf1.border = true;
            tf1.type = "input";
            tf1.addEventListener(KeyboardEvent.KEY_UP,onKey);
            tf5.addEventListener(KeyboardEvent.KEY_UP,onKey2);
            aaa();
            
            
        }
        private function listLength():int{
            var cnt:int=0;
            for(var s:String in list){
                cnt++;
            }
            return cnt;
        }
        //答え合わせ
        private function onKey2(e:KeyboardEvent):void{
            if(e.keyCode == 13){
                if(ans ==tf5.text){
                    aaa();//出題
                    tf5.text ="";
                }

                else{
                    tf5.text = ans;
                    var s2:String ="http://ejje.weblio.jp/content/"+ans;
                    tf4.htmlText = list[ans]+" <a href='" + s2 + "' target='_blank'>"+ '<u><font color="#0088ff">'+ "→"+ans +"</font></u>"+"</a>";
                    tf4.width = tf4.textWidth+20;
                }


            }

        }
        
        //問題リスト生成
        private function setQ():void{
            for(var i:int = 0;i<listNum;i++){
                var obj:Object = new Object();
                
            }

        }



        //出題
        //private var cnt:int = 0;
        private var ans:String;
        private function aaa():void{
            var listNum:int = Math.random()*listLength();
            //tf5.text = listNum.toString();
            var cnt:int=0;
            var str:String;
            for(var s:String in list){
                if(listNum==cnt){
                    str = s;
                    break;
                }
                cnt++;

            }
            cnt++;

            tf4.text = list[str];
            ans = str;
            //var s2:String ="http://ejje.weblio.jp/content/"+ans;
            //tf4.htmlText = list[str]+" <a href='" + s2 + "' target='_blank'>"+ '<u><font color="#0088ff">'+ "→辞書" +"</font></u>"+"</a>";
            //tf4.width = tf4.textWidth+20;
        }

        
        private function init():void{
            so = SharedObject.getLocal("aaa");
            if(so.data.list != undefined){ 
                list = so.data.list;
                tf2.text = "";
                for(var s:String in list){
                    tf2.appendText(s + ":"+list[s]+"\n");
                }
            }
            
        }

        //登録
        private function onKey(e:KeyboardEvent):void{
            var num:int=0;
            var str:String = "";
            if(e.keyCode == 13){
                //未定義の時
                if(tf3.length != 0){
                    list[tf3.text]=tf1.text;
                    so.data.list = list;
                    tf1.text = "";
                    tf3.text = "";
                    removeChild(tf3);
                    tf1.y = 0;
                    tf2.text = "";
                    for(var s:String in list){
                        tf2.appendText(s + ":"+list[s]+"\n");
                    }
                    
                }
                else if(list.hasOwnProperty(tf1.text)==false){ 
                    //list[tf1.text]=str;
                    addChild(tf3);
                    tf1.y = 20;
                    tf3.text = tf1.text;
                    tf1.text = "";
                    

                }
                
            }

            
        }

    }
}