我的公司有一款可以在线阻止各种内容类型的产品,我目前正在设计何时*.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();