新NativeWindow中的舞台尺寸

时间:2018-03-10 14:19:50

标签: actionscript-3 flash actionscript flash-cs6

我正在构建一个Flash桌面应用程序,用户点击一个按钮并在新窗口中打开一个SWF文件(游戏),我使用NativeWindow来实现它,我做了以下内容:

var windowOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
windowOptions.systemChrome = NativeWindowSystemChrome.STANDARD;
windowOptions.type = NativeWindowType.NORMAL;

var newWindow:NativeWindow = new NativeWindow(windowOptions);
newWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
newWindow.stage.align = StageAlign.TOP_LEFT;
newWindow.bounds = new Rectangle(100, 100, 2000, 800);

newWindow.activate();
var aLoader:Loader = new Loader;
aLoader.load(new URLRequest(path));
newWindow.stage.addChild(aLoader);

结果如下: enter image description here 游戏并没有占据整个空间。当我改变" NO_SCALE"到" EXACT_FIT":

newWindow.stage.scaleMode = StageScaleMode.EXACT_FIT;

我得到了这个: enter image description here

它只显示游戏的左上角。我也试过" SHOW_ALL"和#34; NO_BORDER"。我得到了和#34; EXACT_FIT"相同的结果。 当我单独打开游戏的SWF文件时,它会正常显示:

enter image description here

任何想法如何将SWF游戏显示为上图?

2 个答案:

答案 0 :(得分:0)

最佳解决方案是以像素为单位设置外部游戏的尺寸。你必须拉伸装载机以适应你的舞台。如果您尝试将不同尺寸的不同游戏加载到舞台,请使用其URL地址保存swf尺寸。

var extSWFW:Number = 550;
var extSWFH:Number = 400;
var extURL:String = "./Data/someSwf.swf";

var mainStageWidth:Number = 1024;
var mainStageHeight:Nubmer = 768;

var aLoader:Loader = new Loader;
aLoader.load(new URLRequest(extURL));
newWindow.stage.addChild(aLoader);

aLoader.scaleY = aLoader.scaleX = Math.min(mainStageWidth/extSWFW,mainStageHeight/extSWFH);

答案 1 :(得分:0)

非常难以确定加载的SWF的尺寸,因为它刻在它的标题中,您可以在加载时读取并解析它。这是工作样本:

package assortie 
{
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.geom.Rectangle;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;

    public class Dimensions extends Sprite
    {
        private var loader:Loader;

        public function Dimensions() 
        {
            super();

            loader = new Loader;
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);

            loader.load(new URLRequest("outer.swf"));
        }

        private function onLoaded(e:Event):void
        {
            var aBytes:ByteArray = loader.contentLoaderInfo.bytes;

            var aRect:Rectangle = new Rectangle;
            var aRead:BitReader = new BitReader(aBytes, 8);
            var perEntry:uint = aRead.readUnsigned(5);

            aRect.left   = aRead.readSigned(perEntry) / 20;
            aRect.right  = aRead.readSigned(perEntry) / 20;
            aRect.top    = aRead.readSigned(perEntry) / 20;
            aRect.bottom = aRead.readSigned(perEntry) / 20;

            aRead.dispose();
            aRead = null;

            trace(aRect);
        }
    }
}

import flash.utils.ByteArray;

internal class BitReader
{
    private var bytes:ByteArray;
    private var position:int;
    private var bits:String;

    public function BitReader(source:ByteArray, start:int)
    {
        bits = "";
        bytes = source;
        position = start;
    }

    public function readSigned(length:int):int
    {
        var aSign:int = (readBits(1) == "1")? -1: 1;

        return aSign * int(readUnsigned(length - 1));
    }

    public function readUnsigned(length:int):uint
    {
        return parseInt(readBits(length), 2);
    }

    private function readBits(length:int):String
    {
        while (length > bits.length) readAhead();

        var result:String = bits.substr(0, length);

        bits = bits.substr(length);

        return result;
    }

    static private const Z:String = "00000000";

    private function readAhead():void
    {
        var wasBits:String = bits;

        var aByte:String = bytes[position].toString(2);

        bits += Z.substr(aByte.length) + aByte;

        position++;
    }

    public function dispose():void
    {
        bits = null;
        bytes = null;
    }
}