使用 addChild 时阶段会发生变化吗?

发布于 2024-08-17 04:47:20 字数 677 浏览 3 评论 0原文

我在 Flash CS4 中使用 ActionScript 3 时遇到了一个非常奇怪的错误。我在 for 循环中将影片剪辑添加到舞台中,然后将它们移出视图,以便我可以在需要时将它们拉入并删除。

我已将问题范围缩小到我知道每次使用 addChild() 将一个影片剪辑添加到舞台时,舞台都会向右移动一个像素。我知道这听起来很奇怪,但确实如此……每次添加影片剪辑时,y 轴上的 0 线都会向右移动一个像素。我不知道这是怎么发生的。

这是完成这项工作的代码:

        private function setupSlides():void 
    {
        for(x = 0; x < TOTAL_SLIDES; x++)
        {
            var ClassReference:Class = getDefinitionByName("Slide" + (x+1)) as Class;
            var s:MovieClip = new ClassReference() as MovieClip;
            s.x = 9999;
            s.y = 9999;             
            addChild(s);
            slides[x] = s;
        }
    }

有什么想法吗?

I'm having a very odd bug with ActionScript 3 in Flash CS4. I am adding movie clips to a stage in a for loop and then moving them out of view so that I can pull them in and remove them when I need them.

I've narrowed down the issue to a point that I know that every time one of the movie clips are added to the stage using addChild(), the stage shifts to the right by one pixel. I know that sounds odd, but it's literally true... the 0 line on the y axis is shifted to the right one pixel every time the movie clip is added. I have no idea how this could be happening.

Here's the code that is doing the work:

        private function setupSlides():void 
    {
        for(x = 0; x < TOTAL_SLIDES; x++)
        {
            var ClassReference:Class = getDefinitionByName("Slide" + (x+1)) as Class;
            var s:MovieClip = new ClassReference() as MovieClip;
            s.x = 9999;
            s.y = 9999;             
            addChild(s);
            slides[x] = s;
        }
    }

Any thoughts?

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

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

发布评论

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

评论(1

留蓝 2024-08-24 04:47:20

发布后,我注意到我没有声明循环计数器变量(x)。我声明了它,奇怪的渲染就消失了。我想知道为什么它没有给我一个未声明的变量错误?

这是固定代码:

        private function setupSlides():void 
    {
        for(var x:int = 0; x < TOTAL_SLIDES; x++)
        {
            var ClassReference:Class = getDefinitionByName("Slide" + (x+1)) as Class;
            var s:MovieClip = new ClassReference() as MovieClip;
            s.x = 9999;
            s.y = 9999;             
            addChild(s);
            slides[x] = s;
        }
    }

After posting, I noticed that I had not declared the loop counter variable (x). I declared it, and the strange rendering is gone. I wonder why it just didn't give me an undeclared variable error?

Here's the fixed code:

        private function setupSlides():void 
    {
        for(var x:int = 0; x < TOTAL_SLIDES; x++)
        {
            var ClassReference:Class = getDefinitionByName("Slide" + (x+1)) as Class;
            var s:MovieClip = new ClassReference() as MovieClip;
            s.x = 9999;
            s.y = 9999;             
            addChild(s);
            slides[x] = s;
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文