动态stageWidth和高度在Flash AS3 [英] Dynamic stageWidth and Height in Flash AS3

查看:307
本文介绍了动态stageWidth和高度在Flash AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎将是一个非常容易的事,但它一直给我各种头痛。我有一个视频剪辑是一个画廊,它的鳞甲从被点击一个按钮时调用。当在画廊的图像被点击时,它消失在使用吐温类,并且是的应该的集中在主舞台,但其定心到MovieClip代替。

This seems like it would be a really easy thing to do, but its been giving me all kinds of headaches. I have a movieclip that is a gallery, It's linked to be called from AS when a button is clicked. When an image in the gallery is clicked, It fades in using the Tween class and is supposed to be centered in the main stage, but its centering to the movieClip instead.

下面是code:

//Centers and places image right ondo the display board
function fullLoaded(e:Event):void {
    var myFull:Loader = Loader(e.target.loader);
    addChild(myFull);

    //positioning
    myFull.x = (stage.stageWidth - myFull.width) / 2;
    myFull.y = (stage.stageHeight - myFull.height) /2;

    //register the remove function
    myFull.addEventListener(MouseEvent.CLICK, removeFull);

    new Tween(myFull, "alpha", Strong.easeInOut,0,1,0.5,true);
}

我已经尝试了所有这些组合都无济于事:

I have tried all of these combinations to no avail:

MovieClip(root).stage.stageWidth  
root.stage.stageWidth  
parent.stage.stageWidth

所有这些发生在合适的地方的形象。

None of these place the image in the right spot.

推荐答案

这些设置该属性,使你的舞台有它的ORIGO(为0x0)在左上角:

Set these this property to make your stage have it's origo (0x0) in the top left:

stage.align = StageAlign.TOP_LEFT;

和本作的舞台保持相同规模的窗口更改大小:

And this to make the stage stay the same scale as the window changes size:

stage.scaleMode = StageScaleMode.NO_SCALE;

然后你需要等待,直到你的图像加载你对齐之前,因为在此之前,不会有宽度。我也建议倾听 Event.RESIZE 在舞台上,这是发射时的大小变化。

Then you will need to wait until your image is loaded before you align it, since it won't have a width before then. I would also recommend listening for Event.RESIZE on the stage, this is fired whenever the size changes.

假设所有您当前code,做工精细!

Assuming all that your current code should work fine!

myFull.x = (stage.stageWidth - myFull.width) / 2;
myFull.y = (stage.stageHeight - myFull.height) /2;

这篇关于动态stageWidth和高度在Flash AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆