1

私の会社には、さまざまな種類のコンテンツをオンラインでブロックできる製品があり、現在、*.swfファイルがブロックされたときの設計に取り組んでいます。Flash で作業してから何年も経ちましたが、助けが必要です。最大限の互換性を確保するには、これを ActionScript 2 で記述する必要があります。

4 フレームのムービー クリップがあります。フレームを切り替えて、ステージ サイズ/比率に応じて異なるロゴ レイアウトを表示します。ただし、いずれの場合も、問題が発生しているステージの中央にロゴを配置する必要があります。ほぼ中央に配置されていますが、一部のシナリオではロゴが切り取られるほど十分にずれています.

問題のコードは最初のフレームにあります。一般に、ムービー クリップを中央に配置するために私が行っていることは次のとおりです。

Stage.align = "TC";
Stage.scaleMode = "noscale";

var blockedContent:MovieClip = _root.mc_blocked;
var stageListener:Object = new Object();
stageListener.onResize = function() {
    blockedContent._y = (Stage.height/2)-(blockedContent._height/2);`
};
Stage.addListener(stageListener);

ただし、コンテキストで確認できるように、コード全体を以下に示します。

// set the Flash movie to have a fixed anchor in the top top center of the screen.
Stage.align = "TC";
// prevent the Flash movie from resizing when the window changes size.
Stage.scaleMode = "noscale";

//--------------------------------------------------------------------
//Add a new listener when the stage is resized
//--------------------------------------------------------------------
var stageListener:Object = new Object();
stageListener.onResize = function() {
    fixLayout();
};
Stage.addListener(stageListener);

//--------------------------------------------------------------------
//Define some variables
//--------------------------------------------------------------------
var blockedContent:MovieClip = _root.mc_blocked;
var StageRatio:Number = 0;
var Sizes:Object = {
    Padding:20,
    VLarge:{w:0, h:0},
    VSmall:{w:0, h:0},
    HLarge:{w:0, h:0},
    HSmall:{w:0, h:0}
};
//--------------------------------------------------------------------
//duplicate the clip, and save the sizes for each frame
//--------------------------------------------------------------------
duplicateMovieClip(blockedContent, "mc_duplicate", _root.getNextHighestDepth());
mc_duplicate._alpha = 0;
mc_duplicate.gotoAndStop(1);
Sizes.VLarge.w = mc_duplicate._width;
Sizes.VLarge.h = mc_duplicate._height;
mc_duplicate.gotoAndStop(2);
Sizes.HLarge.w = mc_duplicate._width;
Sizes.HLarge.h = mc_duplicate._height;
mc_duplicate.gotoAndStop(3);
Sizes.VSmall.w = mc_duplicate._width;
Sizes.VSmall.h = mc_duplicate._height;
mc_duplicate.gotoAndStop(4);
Sizes.HSmall.w = mc_duplicate._width;
Sizes.HSmall.h = mc_duplicate._height;
//Remove it, we are done with it
mc_duplicate.removeMovieClip();

//Uncomment to see if it is centered
//mc_duplicate._alpha = 25;
//mc_duplicate.gotoAndStop(1);

//--------------------------------------------------------------------
//Fix the layout and scale things appropriately
//--------------------------------------------------------------------
function fixLayout() {

    StageRatio = Stage.width/Stage.height;
    //derermine which way to scale the logo
    if (Stage.height-Sizes.Padding>Sizes.VLarge.h+Sizes.Padding || (StageRatio>0.67 && StageRatio<2.45)) {
        if (Stage.width-Sizes.Padding<Sizes.VSmall.w+Sizes.Padding) {
            //Small vertical layout (no logo)
            blockedContent.gotoAndStop(3);
        } else {
            //default state - the large vertical layout
            blockedContent.gotoAndStop(1);
        }
    } else {
        //if it's not as tall as the large vertical...
        if (Stage.width-Sizes.Padding<Sizes.HSmall.w+Sizes.Padding) {
            //Use the small horizontal (no logo)
            blockedContent.gotoAndStop(4);
        } else {
            //Use the large horizontal
            blockedContent.gotoAndStop(2);
        }
    }
    //make sure it's never larger than 100%
    blockedContent._xscale = blockedContent._yscale=100;

    //Resize by the height...
    if (blockedContent._height+Sizes.Padding>Stage.height-Sizes.Padding) {
        blockedContent._height = Stage.height-Sizes.Padding;
        //Match the scales
        blockedContent._xscale = blockedContent._yscale;
    }
    //Resize by the width...  
    if (blockedContent._width+Sizes.Padding>Stage.width-Sizes.Padding) {
        blockedContent._width = Stage.width-Sizes.Padding;
        //Match the scales
        blockedContent._yscale = blockedContent._xscale;
    }

    //Center it up   
    blockedContent._y = (Stage.height/2)-(blockedContent._height/2); //-Sizes.Padding*2;
}

//--------------------------------------------------------------------
//Fade it in, and initially call the layout fix
//--------------------------------------------------------------------
blockedContent._alpha = 0;
setTimeout(function(){
    blockedContent.onEnterFrame=function(){
        this._alpha+=3;
        if(this._alpha>=100){
            delete this.onEnterFrame;
        }
    }
},300);
fixLayout();
4

1 に答える 1

0

blockedContentMovieClip内のコンテンツは既に中央に配置されています。したがって、ステージの高さ (半分で割った値) に従って MC を中央に配置するだけです。コードの一部を削除するだけ(blockedContent._height/2)です:

blockedContent._y = (Stage.height/2);
于 2013-02-05T16:10:01.067 に答える