In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: forked from: hello world

...
@author michiro
Get Adobe Flash player
by Adel.Benothman 17 Apr 2012
    Embed
/**
 * Copyright Adel.Benothman ( http://wonderfl.net/user/Adel.Benothman )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1aiq
 */

// forked from bradsedito's forked from: hello world
// forked from sinketu's hello world
package 
{
    import caurina.transitions.*;
    import caurina.transitions.properties.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;
    /**
     * ...
     * @author michiro
     */
    [SWF(backgroundColor="0x000000", frameRate="100", width="465", height="465")]
    public class Main extends Sprite 
    {
        private static const FONTSIZE:Number = 46;
        private static const DENSITY:Number = 26;
        private var leftSp:Sprite;
        private var rightSp:Sprite;
        private var spArrayLeft/*Sprite*/:Array=[];
        private var spArrayRight/*Sprite*/:Array = [];
        private var myStringArray:Array = ["ADELOTHMAN","ASSCT","TUNISIE"];
        private var myCharArray:Array = [];
        private var myString:String;
        private var firstFlag:Number = 0;
        public var tempArray:Array = [];
        private var myWrapper:Sprite;
        private var myTimer:Timer;
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        /**
         * 初期化
         * @param    e
         */
        private function init(e:Event = null):void 
        {
            DisplayShortcuts.init();
            ColorShortcuts.init();
            
            removeEventListener(Event.ADDED_TO_STAGE, init);
            //addChild(new Stats());
            
            var myBG:Sprite=new Sprite();
            myBG.graphics.beginFill(0x0);
            myBG.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            myBG.graphics.endFill();
            addChild(myBG);
            
            myWrapper = new Sprite();
            addChild(myWrapper);
            
            leftSp = new Sprite();
            for (var i:uint = 0; i < 5;i++ ){
                var sp:Sprite = haguruma(i,0);
                spArrayLeft.push(sp);
                leftSp.addChild(sp);
            }
            leftSp.x = -130+5;
            leftSp.y = 220;
            myWrapper.addChild(leftSp);
            
            rightSp = new Sprite();
            for (i = 0; i < 5;i++ ){
                sp = haguruma(i,1);
                spArrayRight.push(sp);
                rightSp.addChild(sp);
            }
            rightSp.x = 592-5;
            rightSp.y = 220;
            myWrapper.addChild(rightSp);
            
            setAnimation();
            
            stage.addEventListener(MouseEvent.CLICK, xClick);
            
            myTimer = new Timer(6000, 1);
            myTimer.addEventListener(TimerEvent.TIMER, xTimer);
            
        }
        
        /**
         * アニメーションスタート
         */
        private function setAnimation():void {
            var temp:Number = 0;
            if (firstFlag != 1) {
                firstFlag = 1;
                temp = 0;
            }else {
                temp = Math.floor(Math.random() * myStringArray.length);
            }
            myString = myStringArray[temp];
            for (var i:uint = 0; i < spArrayLeft.length; i++ ) {
                //myCharArray.push(String.myString
                Tweener.addTween(spArrayLeft[i], { rotation: 360+270 + 360 / DENSITY * -(myString.charCodeAt(i) - 65), time:5,transition:"easeOutCubic"});
            }
            for (i = 0; i < spArrayRight.length; i++ ) {
                Tweener.addTween(spArrayRight[i], { rotation: 90 + 360 / DENSITY * (myString.charCodeAt(spArrayLeft.length + spArrayRight.length - i - 1) - 65), time:5, transition:"easeOutSine"
                ,onComplete:setBrightness,onCompleteParams:[i]});
            }
            Tweener.addTween(leftSp, { _brightness: -2.55, time:0 } );
            Tweener.addTween(leftSp, { _brightness: 0, time:2.5 ,transition:"linear" } );
            
            Tweener.addTween(rightSp, { _brightness: -2.55, time:0 } );
            Tweener.addTween(rightSp, { _brightness: 0, time:2.5,transition:"linear" } );
        }
        
        /**
         * クリックしたらリセット
         * @param    e
         */
        private function xClick(e:MouseEvent):void 
        {
            myTimer.stop();
            Tweener.removeAllTweens();
            for (var i:uint = 0; i < tempArray.length; i++ ) {
                Tweener.addTween(tempArray, { _brightness:0, time:0 } );
            }
            tempArray = [];
            for (i = 0; i < spArrayLeft.length; i++ ) {
                //myCharArray.push(String.myString
                Tweener.addTween(spArrayLeft[i], { rotation: 0, time:0});
            }
            for (i = 0; i < spArrayRight.length; i++ ) {
                Tweener.addTween(spArrayRight[i], { rotation: 0, time:0 });
            }
            setAnimation();
        }

        /**
         * 光らせる。
         * 
         * @param    num
         */
        public function setBrightness(num:Number):void {
            myTimer.start();
            if (num == spArrayRight.length - 1) {
                for (var i:uint = 0; i < spArrayLeft.length; i++ ) {
                    var temp:Sprite = spArrayLeft[i].getChildByName("sp" + (myString.charCodeAt(i) - 65));
                    Tweener.addTween(temp, { _brightness:2.55, time:3 } );
                    tempArray.push(temp);
                }
                for (i = 0; i < spArrayRight.length; i++ ) {
                    temp = spArrayRight[i].getChildByName("sp" + (myString.charCodeAt(spArrayLeft.length + spArrayRight.length - i - 1) - 65));
                    Tweener.addTween(temp, { _brightness:2.55, time:3 } );
                    tempArray.push(temp);
                }
            }
        }
        
        private function xTimer(e:TimerEvent):void 
        {
            xClick(null);
        }
        
        /**
         * 歯車を作る
         * 
         * @param    num 
         * @param    num2
         * @return
         */
        private function haguruma(num:Number,num2:Number=0):Sprite
        {
            
            var mySprite:Sprite = new Sprite();
            addChild(mySprite);
            
            for (var i:uint = 0; i < DENSITY; i++ ) {
                var myTextField:TextField = textPropertySet(400, 40,false,0x131413,false,false);
                textFormatProperty(myTextField,FONTSIZE, 0x131413, "Verdana", TextFormatAlign.LEFT, 1);
                myTextField.text = String.fromCharCode(65+i);
                var myBitmapData:BitmapData = new BitmapData(myTextField.textWidth, myTextField.textHeight, true, 0x00ffffff);
                var myBitmap:Bitmap = new Bitmap(myBitmapData);
                myBitmap.smoothing = true;
                myBitmapData.draw(myTextField);
                
                var mySp:Sprite = new Sprite();
                myBitmap.x = -myBitmap.width/2;
                myBitmap.y = -myBitmap.height/2;
                mySp.addChild(myBitmap);
                var temp:Number
                if (num2 == 0) {
                    temp = 1;
                }else {
                    temp = -1;
                }
                if(temp==1){
                    mySp.rotation = (360 / DENSITY) * i + (90);
                }else {
                    mySp.rotation = (360 / -DENSITY) * i +(90*temp);
                }
                mySp.x = Math.sin((360 / DENSITY) * -i *temp* Math.PI / 180) * (150+num*FONTSIZE) ;
                mySp.y = Math.cos((360 / DENSITY) * -i*temp* Math.PI / 180) *(150+num*FONTSIZE) ;
                
                mySprite.addChild(mySp);
                mySp.name = "sp" + i;
            }
            return mySprite
        }
        
        /**
         * クラス化するほどでもないメソッド1
         * 
         * @param    w
         * @param    h
         * @param    txttype
         * @param    txtColr
         * @param    b
         * @param    thick
         * @param    sharp
         * @param    auto
         * @param    multi
         * @param    wrap
         * @param    embed
         * @return
         */
        private function textPropertySet(w:Number = 200, h:Number = 40, select:Boolean = false , txtColr:uint = 0x0, multi:Boolean = true, wrap:Boolean = true, auto:String = TextFieldAutoSize.LEFT, txttype:String = TextFieldType.DYNAMIC, b:Boolean = false, thick:Number = 1, sharp:Number = 1, embed:Boolean = false ):TextField {
            var txt:TextField=new TextField;
            txt.width = w;
            txt.height = h;
            txt.selectable = select;
            txt.type= txttype;
            txt.textColor = txtColr;
            txt.thickness = thick;//(埋め込みフォント時のみ動作)
            txt.sharpness = sharp;//(埋め込みフォント時のみ動作)
            txt.border = b;
            txt.autoSize = auto;
            txt.multiline = multi;
            txt.wordWrap = wrap;
            txt.embedFonts = embed;//(埋め込みフォント時のみ動作)
            return txt;
            
        }
        
        /**
         * クラス化するほどでもないメソッド2
         * 
         * @param    txt
         * @param    size
         * @param    color
         * @param    font
         * @param    format
         * @param    space
         * @param    lead
         * @param    bold
         * @param    kerning
         */
        private function textFormatProperty(txt:TextField, size:Number = 10,color:uint = 0x0,  font:String = "Verdana", format:String = TextFormatAlign.LEFT, space:Number = 0, lead:Number = 0, bold:Boolean = false, kerning:Boolean = false ):void
        {
            var myTextFormat:TextFormat = new TextFormat();
            myTextFormat.size = size;
            myTextFormat.font = font;
            myTextFormat.align = format; // 整列
            myTextFormat.color = color;// 文字の色
            myTextFormat.letterSpacing = space;// 文字間スペースの量(単位:ピクセル)
            myTextFormat.leading = lead;// 行間の垂直の行送り
            myTextFormat.bold = bold;// 太字にするか?
            myTextFormat.kerning = kerning;// カーニングが有効か?(埋め込みフォント時のみ動作)
            
            txt.defaultTextFormat = myTextFormat; 
        }
        
    }
    
}