访问文档类中已经存在的 MovieClip 实例?

发布于 2024-12-21 08:20:57 字数 1571 浏览 1 评论 0原文

我在 Flash 中创建了一个游戏,由于游戏的性质,我在 Flash CS4 中手动将许多影片剪辑放置在舞台上。它们不是以编程方式添加到舞台上的,因此我很难在文档类中访问它们。到目前为止,我能够使用的唯一方法是执行 stage.addChild(active_area); (例如),但是有很多影片剪辑,名称都非常不同,所以这个方法似乎不正确。

我发现我的 MovieClip 不是舞台的子级,但实际上是 MainTimeline,因为当我 for 循环 stage.getChildAt(i);< /code>,仅追踪到一个子节点 root1

如何从文档类访问时间轴中放置在舞台上的影片剪辑,而无需手动将它们作为子级添加到舞台中?

[编辑]


所以看起来我的问题不是我无法访问MovieClips,而是我没有修改MovieClips的值,所以我没有注册任何更改他们。

这是我修复后的代码:

    function manage_cursor(e:Event):void {
        prevX=currX;
        prevY=currY;
        currX=stage.mouseX;
        currY=stage.mouseY;
        var i:int;

        if (currY > (stage.stageHeight/2)) {

            for (i = 0; i < this.numChildren; i++) {
                if (this.getChildAt(i).name!="active_area" && stage_kelp.y > kelp.min_y_mod) {
                    this.getChildAt(i).y-=1;                    
                }
            }
        }
        if (currY < (stage.stageHeight/2)) {
            for (i = 0; i < this.numChildren; i++) {
                if (this.getChildAt(i).name!="active_area" && this.stage_kelp.y < kelp.max_y_mod) {
                    this.getChildAt(i).y+=1;
                }
            }
        }

    }

之前的问题是我正在检查 stage.numChildren;,使用 stage.getChildAt(i),并修改该子项,这是时间线。这给了我舞台上所有其他 MovieClip 被移动的效果,所以我假设它们的 y 值正在被更改,但它们没有,因此,我的条件都没有被触发,给我一种错觉,以为我无法访问 MovieClips。按照下面答案中的包的建议,将 stage 更改为 this 解决了我的问题。

I have created a game in flash, and due to the nature of the game, I have many movieclips placed on the stage manually in Flash CS4. They are not programmatically added as children to the stage, and so I am having difficulty getting access to them in the document class. So far the only method I have been able to use is to do stage.addChild(active_area); (for example), but there are many movie clips, all very differently named, so this method seems incorrect.

I've discovered that my MovieClips are not children of the stage, but in fact MainTimeline, as when I for loop through stage.getChildAt(i);, only one child, root1, is traced out.

How can I access movieclips that were placed on the stage in the timeline from the document class, without having to manually add them as children to the stage?

[EDIT]


So it looks like my problem wasn't that I couldn't access the MovieClips, it was that I wasn't modifying the MovieClips' values, so I wasn't registering any change in them.

Here is the code after I fixed it:

    function manage_cursor(e:Event):void {
        prevX=currX;
        prevY=currY;
        currX=stage.mouseX;
        currY=stage.mouseY;
        var i:int;

        if (currY > (stage.stageHeight/2)) {

            for (i = 0; i < this.numChildren; i++) {
                if (this.getChildAt(i).name!="active_area" && stage_kelp.y > kelp.min_y_mod) {
                    this.getChildAt(i).y-=1;                    
                }
            }
        }
        if (currY < (stage.stageHeight/2)) {
            for (i = 0; i < this.numChildren; i++) {
                if (this.getChildAt(i).name!="active_area" && this.stage_kelp.y < kelp.max_y_mod) {
                    this.getChildAt(i).y+=1;
                }
            }
        }

    }

The problem before was that I was checking stage.numChildren;, using stage.getChildAt(i), and modifying that child, which was the TimeLine. This gave me the effect of all my other MovieClips on stage being moved, so I was under the assumption their y values were being changed, but they weren't, thus, none of my conditionals were triggering, giving me the illusion that I wasn't getting access to the MovieClips. Changing stage to this, as recommended by package in the answers below, fixed the problem for me.

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

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

发布评论

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

评论(2

絕版丫頭 2024-12-28 08:20:57

在您的文档类中尝试此代码:

trace(this["movieclip_name"]);

this 引用您的文档类中的MainTimeline

Try this code in your Document Class:

trace(this["movieclip_name"]);

this refers to the MainTimeline in your Document Class.

你与清晨阳光 2024-12-28 08:20:57

您是否尝试过导出 ActionScript 的 MovieClip 并为其指定标识符?之后,您通常可以仅使用标识符来访问 MovieClip。

Have you tried exporting the MovieClip for ActionScript and given it an identifier? You can usually just use the identifier to access the MovieClip after that.

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