【问题标题】:Dynamic stageWidth and Height in Flash AS3Flash AS3中的动态stageWidth和Height
【发布时间】:2010-10-24 10:11:24
【问题描述】:

这似乎是一件很容易做到的事情,但它让我很头疼。我有一个作为画廊的影片剪辑,当单击按钮时,它被链接为从 AS 调用。当单击图库中的图像时,它会使用 Tween 类淡入淡出,并且应该在主舞台上居中,但它以movieClip为中心。

代码如下:

//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);
}

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

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

这些都没有将图像放在正确的位置。

【问题讨论】:

  • 嗨,您检查过stage.align 属性吗?
  • 是的,我也试过了,但没有成功:(

标签: flash actionscript-3 web-applications stage


【解决方案1】:

MovieClip(root).addChild(myFull); 不要忘记对removeChild做同样的事情

【讨论】:

    【解决方案2】:

    设置这些这个属性,让你的舞台在左上角有它的 origo (0x0):

    stage.align = StageAlign.TOP_LEFT;
    

    这是为了让舞台在窗口大小改变时保持相同的比例:

    stage.scaleMode = StageScaleMode.NO_SCALE;
    

    那么你需要等到你的图片加载完毕后再对齐它,因为在此之前它没有宽度。我还建议在舞台上收听Event.RESIZE,只要大小发生变化,就会触发它。

    假设您当前的代码应该可以正常工作!

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

    【讨论】:

    • 它不起作用,因为它返回包含影片剪辑的大小,而不是主舞台! :(
    • stage.stageWidth 给出了我确定的阶段宽度。如果您收到奇怪的值,请尝试添加侦听器。
    • 另外,myFull 位置显然与其父级的 x 位置有关。
    猜你喜欢
    • 1970-01-01
    • 2011-01-28
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-20
    相关资源
    最近更新 更多