Flash AS3 中的动态舞台宽度和高度

发布于 2024-07-19 06:17:23 字数 802 浏览 4 评论 0原文

这看起来似乎是一件非常容易做到的事情,但它却让我各种头疼。 我有一个影片剪辑,它是一个画廊,它被链接为当单击按钮时从 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

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

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.

Here is the 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红尘作伴 2024-07-26 06:17:23

设置这些属性以使您的舞台在左上角具有原点(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;

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;

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.

Assuming all that your current code should work fine!

myFull.x = (stage.stageWidth - myFull.width) / 2;
myFull.y = (stage.stageHeight - myFull.height) /2;
乖乖 2024-07-26 06:17:23

MovieClip(root).addChild(myFull);
不要忘记对 removeChild 执行相同的操作

MovieClip(root).addChild(myFull);
don't forget to do the same to removeChild

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文