簡単なプレゼンツール作ってみた

だいたい4,5時間ぐらいで製作。

ソース

package etude
{
    include 'import.as';
    
    [SWF(width="400", height="400", backgroundColor="#ffffff", frameRate="30")]
    public class Etude extends Sprite
    {
        public function Etude()
        {
            addEventListener( Event.ADDED, init);
        }
        public function init( e:Event):void
        {
            removeEventListener( Event.ADDED, init);
            
            stage.scaleMode = StageScaleMode.NO_SCALE;  // 拡大縮小の無効
            stage.align = StageAlign.TOP_LEFT;          // 配置を左上に
            stage.addChildAt( new BackGroundA(), 0);    // 背景の追加
            
            var contents:String = <><![CDATA[
                Enterキーで進む
                Shift+Enterで戻る
                です
                
                プレゼンツール
                もどきです。
                
                htmlタグやスタイルシートを使えます。
                
                <b>太字</b>とか
                
                <font color="#cc6666">色を変えたり</font>とか
                
                <font size="50">大きさを</font>変えたり
                
                <img src="http://s3.amazonaws.com/twitter_production/profile_images/37876602/tw_bigger.png" />
                <br>画像を埋め込んだりなど。
                
                そこそこ表現力豊かです。
                
                終わり
            ]]></>;
            
            addChild( new Presen( contents));
        }
    }
}

include 'import.as';

class Presen extends Sprite
{
    protected var strArray:Array;
    protected var _index:uint = 0;
    protected var textField:TextField;
    
    public function Presen( contents:String)
    {
        this.strArray = parseContents( contents);
        this.textField = createTextField();
        this.addChild( textField);
        
        addEventListener( Event.ADDED, onAdded);
    }
    public function get index():uint
    {
        return _index;
    }
    protected function createTextField():TextField
    {
        var textField:TextField = new TextField();
        with( textField) {
            styleSheet = createStyleSheet();
            multiline = true;
            wordWrap = true;
            selectable = false;
        }
        return textField;
    }
    protected function parseContents( contents:String):Array
    {
        contents = contents.replace( /\r/g, '');
        contents = contents.replace( /^[ \t]*/mg, '');
        contents = contents.replace( /^[\n]/, '');
        contents = contents.replace( /[\n]$/, '');
        
        return contents.split( /\n\n/g);
    }
    protected function onAdded( e:Event):void
    {
        stage.addEventListener( KeyboardEvent.KEY_DOWN, onKeyDown);
        
        updateText();
    }
    protected function onKeyDown( e:KeyboardEvent):void
    {
        if ( e.keyCode == Keyboard.ENTER)
        {
            if( !e.shiftKey) {
                next();
            }
            else {
                prev();
            }
        }
    }
    protected function next():void
    {
        if ( _index >= strArray.length - 1) _index = 0;
        else _index++;
        
        updateText();
    }
    protected function prev():void
    {
        if ( _index <= 0) _index = strArray.length - 1;
        else _index--;
        
        updateText();
    }
    protected function updateText():void
    {
        textField.htmlText = '<default>' + strArray[_index] + '</default>';
        
        textField.width = stage.stageWidth;
        textField.height = stage.stageHeight;
        
        textField.x = 0;
        textField.y = ( stage.stageHeight - textField.textHeight) / 2;
    }
    protected function createStyleSheet():StyleSheet
    {
        var styleSheet:StyleSheet = new StyleSheet();
        
        styleSheet.parseCSS(<><![CDATA[
            default {
                text-align:center;
                color:#333333;
                font-size:30px;
                font-family:メイリオ,MS ゴシック;
            }
            a {
                text-decoration:underline;
            }
        ]]></>);
        
        return styleSheet;
    }
}