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

Random Text

Get Adobe Flash player
by NWAPages 01 Aug 2011
/**
 * Copyright NWAPages ( http://wonderfl.net/user/NWAPages )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/afBH
 */

package
{
    import flash.display.Sprite;

    [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="60")]
    public class Main extends Sprite
    {

        public function Main()
        {
            var i:int = 1
            
            var rand1:RandomText=new RandomText("Home");
            addChild(rand1);
            rand1.x = 20;
            rand1.y = 32 * i++;

            
            var rand2:RandomText=new RandomText("Contact Us");
            addChild(rand2);
            rand2.x = 20;
            rand2.y = 32 * i++;
            
            var rand3:RandomText=new RandomText("Portfolio");
            addChild(rand3);
            rand3.x = 20;
            rand3.y = 32 * i++;

            var rand4:RandomText=new RandomText("Projects");
            addChild(rand4);
            rand4.x = 20;
            rand4.y = 32 * i++;

            var rand5:RandomText=new RandomText("Services");
            addChild(rand5);
            rand5.x = 20;
            rand5.y = 32 * i++;

            var rand6:RandomText=new RandomText("Login");
            addChild(rand6);
            rand6.x = 20;
            rand6.y = 32 * i++;

            var rand7:RandomText=new RandomText("Demos");
            addChild(rand7);
            rand7.x = 20;
            rand7.y = 32 * i++;
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.utils.Timer;
import flash.events.MouseEvent;
import caurina.transitions.*

class RandomText extends Sprite
{

    private var RandSource:String = "asdfghjklzxcvbnmqwertyuiop";
    private var MainString:String;
    private var Length:int;
    private var ReplaceCount:int;
    private var ReplaceTimer:Timer;
    public var MainTextField:TextField;
    private var bg:Sprite = new Sprite();
    private var check:Boolean = false;
    public function RandomText(main_string:String)
    {
        MainString = main_string;
        Length = MainString.length;
        MainTextField = new TextField();
        MainTextField.defaultTextFormat = new TextFormat(null, 25, 0x000);
        MainTextField.text = MainString;
        MainTextField.autoSize = TextFieldAutoSize.LEFT;
        MainTextField.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
        MainTextField.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
        MainTextField.selectable = false;
        addChild(MainTextField);
        ReplaceTimer = new Timer(10);
        ReplaceTimer.addEventListener(TimerEvent.TIMER, onReplaceTimer);
        var padding:int = 3;
        bg.graphics.beginFill(0xffffff);
        bg.graphics.drawRect( -padding, -padding, MainTextField.textWidth  + padding * 2, MainTextField.textHeight + padding * 2);
        bg.alpha = 0;
        addChildAt(bg, 0);
        addEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
    
    private function onMouseOver(e:MouseEvent):void
    {
        check = true;
        MainTextField.textColor = 0xfff;
        if (ReplaceTimer.running) ReplaceTimer.stop();
        ReplaceCount = 0;
        ReplaceTimer.start();
    }

    private function onMouseOut(e:MouseEvent):void
    {
        MainTextField.textColor = 0x777;        if (ReplaceTimer.running) ReplaceTimer.stop();
        MainTextField.text = MainString;
      }

    private function onReplaceTimer(e:TimerEvent):void
    {
        MainTextField.text = "";
        var i:int = 0;
        for (i = 0; i < ReplaceCount; i++) MainTextField.appendText(MainString.charAt(i));
        for (i = 0; i < 20 - ReplaceCount; i++) MainTextField.appendText(RandSource.charAt(Math.floor(Math.random() * (RandSource.length - 1))));
        if (ReplaceCount == 20) ReplaceTimer.stop();
        ReplaceCount++;
    }
    
    private function onEnterFrame(e:Event):void
    {
        if (check) bg.alpha = 1;
        else bg.alpha = 0;
    }
}