AS3:将加载的动画居中

发布于 2024-09-13 21:44:45 字数 1178 浏览 9 评论 0原文

我有一个问题将动画置于其容器中。

这是容器或加载器:

    public function Main():void
    {
        trace("Constructor...");

        this.addEventListener(Event.ADDED_TO_STAGE, this.addEvent);
    }

    public function addEvent(e:Event):void
    {
        trace("AddedToStage");

        this.stage.scaleMode = StageScaleMode.NO_SCALE;
        this.stage.align = StageAlign.TOP_LEFT;

        var url = new URLRequest("testfile.swf");
        movie = new Loader();
        movie.contentLoaderInfo.addEventListener(Event.COMPLETE, this.eventComplete);
        this.stage.addChild(movie);
        movie.load(url);
    }

    public function eventComplete(e:Event):void
    {
        trace("Complete...");

        movie.x = (this.stage.stageWidth - movie.width) * 0.5;
        movie.y = (this.stage.stageHeight - movie.height) * 0.5;
    }

这与场景中的对象完美配合,但不适用于使用动作脚本添加的对象...就像这样:

    public function Main():void
    {
        trace("Constructor of included file!");

        stage.scaleMode = StageScaleMode.NO_SCALE;

        var movieclip = new symbol_an();
        stage.addChild(movieclip);
    }

您有解决方案吗?

谢谢,问候。

I have a question to center an animation within its container.

This is the container or loader:

    public function Main():void
    {
        trace("Constructor...");

        this.addEventListener(Event.ADDED_TO_STAGE, this.addEvent);
    }

    public function addEvent(e:Event):void
    {
        trace("AddedToStage");

        this.stage.scaleMode = StageScaleMode.NO_SCALE;
        this.stage.align = StageAlign.TOP_LEFT;

        var url = new URLRequest("testfile.swf");
        movie = new Loader();
        movie.contentLoaderInfo.addEventListener(Event.COMPLETE, this.eventComplete);
        this.stage.addChild(movie);
        movie.load(url);
    }

    public function eventComplete(e:Event):void
    {
        trace("Complete...");

        movie.x = (this.stage.stageWidth - movie.width) * 0.5;
        movie.y = (this.stage.stageHeight - movie.height) * 0.5;
    }

This work perfectly with the objects that are on the scene, but not with objects that are added with actionscript... like this:

    public function Main():void
    {
        trace("Constructor of included file!");

        stage.scaleMode = StageScaleMode.NO_SCALE;

        var movieclip = new symbol_an();
        stage.addChild(movieclip);
    }

Do you have a solution?

Thank you, regards.

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

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

发布评论

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

评论(1

只等公子 2024-09-20 21:44:45

它不起作用是什么意思,你的第二个函数没有显示太多...在代码的第二部分中,你可以执行与第一部分相同的操作,基本上获取容器及其子容器的宽度,减去然后将结果除以二。为了让它工作,您必须确保宽度或高度属性实际上有一个值,这取决于您的特定应用程序,因此如果没有更多信息,很难为您提供帮助。

在第二部分中,您没有 ADDED_TO_STAGE 事件侦听器,这可能会引发错误,因为阶段值可能为空。

What do you mean by it's not working , your second function doesn't show much... In the second part of your code you can do the same as in the first one, basically get the width of the container and its child , substract then divide the result by two. For it to work, you have to make sure that the width or height properties actually have a value, this depends on your particular application so it's difficult to help you without having more info.

In the second part , you don't have an ADDED_TO_STAGE event listener , this could possibly throw an error because the stage value could be null.

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