flash on 2011-6-10

by s26
♥0 | Line 58 | Modified 2011-06-10 14:43:40 | MIT License
play

ActionScript3 source code

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

package {
    import flash.net.SharedObject;
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.events.*;
    
    public class FlashTest extends Sprite {
        
        private var _btn:Sprite;
        private var _textField:TextField;
        
        public function FlashTest() {
            init();
        }
        
        private function init():void{
            _textField = new TextField();
            _textField.text = "counter";
            addChild(_textField);
            _textField.x = (stage.stageWidth-_textField.width)/2;
            _textField.y = (stage.stageHeight-_textField.height)/2;
            
            
            var _txt:TextField = new TextField();
            _txt.text = "button";
            _txt.textColor = 0xffffff;
            addChild(_txt)
            
            _txt.mouseEnabled = false;
            
            
             _txt.x =30;
             _txt.y = 45;
             
             _txt.height = 20;
            
            _btn = new Sprite();
            _btn.graphics.beginFill(0x000000,1);
            _btn.graphics.drawRect(0,0,100,100);
            _btn.graphics.endFill();
            _btn.addChild(_txt);
            
            _btn.buttonMode = true;
            
            _btn.addEventListener(MouseEvent.ROLL_OVER,function(e:Event){
                _btn.alpha = 0.8;
            })
            
            _btn.addEventListener(MouseEvent.ROLL_OUT,function(e:Event){
                _btn.alpha = 1;
            })
            
            
            _btn.addEventListener(MouseEvent.CLICK,function(e:Event){
            //    _shared.data.countin++;
                _date = new Date();
                _interval = int((_date.getTime()-_shared.data.countin)/1000);
                _shared.data.countin = _date.getTime();
                _textField.text = _interval.toString() + "秒経過";
            })
            
            
            addChild(_btn);
            
            
            var _shared:SharedObject = SharedObject.getLocal("test2");
            var _interval:Number 
            var _date:Date= new Date();
            if(_shared.data.countin == undefined){
                _interval = int(_date.getTime()/1000); 
                _shared.data.countin = _date.getTime();
            }else{
                _interval = int((_date.getTime()-_shared.data.countin)/1000);
                _shared.data.countin = _date.getTime();
            }
             //_textField.text = "cossunter" + _shared.data.countin;
           
             
             _textField.text = _interval.toString() + "秒経過";
             
        }
    }
}