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

Tweener:onUpdateと特殊プロパティ"_text"でランダムテキスト

Get Adobe Flash player
by meat18 05 Sep 2009
package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import caurina.transitions.Tweener;
    import caurina.transitions.properties.*;
    
    public class FlashTest extends Sprite {
        private var tfs:Array = [];
        private var sourceTxt:String = "_/-=+%&$#!?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
        private var targetText:String;
        
        public function FlashTest() 
        {
            //TextShortcutsの特殊プロパティを使用可能にする
            TextShortcuts.init();
            
            //2行目と4行目のテキストを等幅フォントに設定
            var format:TextFormat = new TextFormat();
            format.font = "Courier New";
            
            //TextFieldを生成
            for(var k:int = 0;k<4;k++)
            {
                var tf:TextField = TextField(addChild(new TextField)); 
                tf.y=k*20;
                tf.autoSize = "left";
                if(tfs.length %2 !=0)
                {
                    tf.defaultTextFormat = format;
                    tf.text = "CLICK!";
                    tf.addEventListener(MouseEvent.CLICK,onClick);
                }
                tfs.push(tf);
            }
            tfs[0].text = "TweenerのTextShortcutの特殊プロパティ_textを使います";
            tfs[2].text = "↓onUpdateでランダムテキスト処理をしてみた";
        }
        
        //TextShortcutの特殊プロパティ"_text"をつかってみる
        private function onClick(e:Event):void
        {
            targetText = "TextField is clicked!";
            Tweener.addTween(e.target,
            {
                onUpdate:rndText, 
                onUpdateParams:[e.target],
                _text:targetText,
                transition : "linear",
                time:0.7,
                onComplete:function():void
                {
                    targetText = "CLICK!";
                    Tweener.addTween(e.target,
                    {
                        onUpdate:rndText,
                        onUpdateParams:[e.target],
                        delay:0.7,
                        _text:targetText,
                        transition : "linear",
                        time:0.7
                    })
                }
            });
        }
        //ランダムテキスト処理
        private function rndText(a:TextField):void
        {
            if(a == tfs[3] && a.text != targetText)
            {
                var Length:int = a.length;
                a.text = "";
                for(var i:int=0;i<Length;i++)
                {
                    a.appendText(sourceTxt.charAt(int(Math.random()*(sourceTxt.length-1))));
                }
            }
        }
    }
}