フルスクリーンモード

by ProjectNya
//////////////////////////////////////////////////////////////////////////////
フルスクリーンモード
//////////////////////////////////////////////////////////////////////////////
♥0 | Line 141 | Modified 2010-06-30 15:42:48 | MIT License
play

ActionScript3 source code

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

////////////////////////////////////////////////////////////////////////////////
// フルスクリーンモード
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.StageScaleMode;
     import flash.display.StageAlign;
    import flash.display.StageDisplayState;
    import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;
    import flash.system.Security;
    import flash.system.LoaderContext;
    import flash.display.Shape;
    import flash.geom.Matrix;
    import flash.display.GradientType;

    [SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var background:Shape;
        private var loader:Loader;
        private static var piyoPath:String = "http://www.project-nya.jp/images/flash/piyo2d.swf";
        private var Piyo:Class;
        private var piyo:MovieClip;
        private var label:Label;

        public function Main() {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
        }

        private function init(evt:Event = null):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            draw();
            Security.allowDomain("www.project-nya.jp");
            loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete, false, 0, true);
            loader.load(new URLRequest(piyoPath), new LoaderContext(true));
            stage.addEventListener(Event.RESIZE, resize, false, 0, true);
            stage.addEventListener(MouseEvent.CLICK, click, false, 0, true);
        }
        private function complete(evt:Event):void {
            loader.removeEventListener(Event.COMPLETE, complete);
            var content:MovieClip = MovieClip(evt.target.content);
            //Piyoクラス
            Piyo = MovieClip(content.piyo).constructor;
            setup();
            loader = null;
        }
        private function setup():void {
            //Piyoインスタンス
            piyo = new Piyo();
            addChild(piyo);
            piyo.x = 232;
            piyo.y = 380;
            piyo.scale = 2;
        }
        /////////////////////////////////////////////
        //フルスクリーン
        /////////////////////////////////////////////
        private function resize(evt:Event):void {
            background.width = stage.stageWidth;
            background.height = stage.stageHeight;
            piyo.x = uint(background.width/2);
            piyo.y = uint(background.height/465*350) + 30;
            label.x = piyo.x - 60;
            label.y = uint(background.height/465*100);
            if (stage.displayState == StageDisplayState.NORMAL) {
                piyo.scale = 2;
                label.text = "click to fullscreen";
            } else {
                piyo.scale = 4;
                label.text = "click to normal";
            }
        }
        private function click(evt:MouseEvent):void {
            if (stage.displayState == StageDisplayState.NORMAL) {
                stage.displayState = StageDisplayState.FULL_SCREEN;
            } else {
                stage.displayState = StageDisplayState.NORMAL;
            }
        }
        /////////////////////////////////////////////
        //背景
        /////////////////////////////////////////////
        private function draw():void {
            background = new Shape();
            addChild(background);
            drawSky();
            drawGround();
            label = new Label(120, 40);
            label.x = 232 - 60;
            label.y = 100;
            label.text = "click to fullscreen";
            label.textColor = 0xFFFFFF;
            label.alpha = 0.6;
            addChild(label);
        }
        private function drawSky():void {
            var matrix:Matrix = new Matrix();
            matrix.createGradientBox(465, 350, 0.5*Math.PI, 0, 0);
            background.graphics.beginGradientFill(GradientType.LINEAR, [0x3F68AB, 0x77B2EE], [1, 1], [0, 255], matrix);
            background.graphics.drawRect(0, 0, 465, 350);
            background.graphics.endFill();
        }
        private function drawGround():void {
            var matrix:Matrix = new Matrix();
            matrix.createGradientBox(465, 115, 0.5*Math.PI, 0, 350);
            background.graphics.beginGradientFill(GradientType.LINEAR, [0x99CC33, 0x7EB133], [1, 1], [0, 255], matrix);
            background.graphics.drawRect(0, 350, 465, 115);
            background.graphics.endFill();
        }

    }

}


import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;

class Label extends Sprite {
    private var txt:TextField;
    private static var fontType:String = "Arial";
    private var txtWidth:uint;
    private var fontSize:uint;

    public function Label(w:uint, s:uint) {
        txtWidth = w;
        fontSize = s;
        draw();
    }

    private function draw():void {
        txt = new TextField();
        txt.width = txtWidth;
        addChild(txt);
        txt.autoSize = TextFieldAutoSize.CENTER;
        txt.type = TextFieldType.DYNAMIC;
        txt.selectable = false;
        //txt.embedFonts = true;
        //txt.antiAliasType = AntiAliasType.ADVANCED;
        var tf:TextFormat = new TextFormat();
        tf.font = fontType;
        tf.size = fontSize;
        tf.align = TextFormatAlign.CENTER;
        txt.defaultTextFormat = tf;
    }
    public function set text(param:String):void {
        txt.text = param;
    }
    public function set textColor(param:uint):void {
        txt.textColor = param;
    }

}

Forked