(Actionscript 2.0) 将 MovieClip 传递给外部脚本。如何清理

发布于 2024-09-30 17:06:08 字数 1197 浏览 1 评论 0原文

我创建了一个类,其中包含舞台上的所有影片剪辑。这些变量指的是舞台上实例的名称。只要我将所有功能保留在一个类中,一切看起来都很好。但是,当我尝试使用另一个类来管理影片剪辑的属性时,我遇到了资源清理问题。

//File (MainScreen.as)
import utils.Container;

class MainScreen extends MovieClip
{
    private var clip1:MovieClip;
    private var clip2:MovieClip;
    private var container:Container

    public function MainScreen()
    {
        container = new Container(clip1);
    }

    public function CleanUpMess()
    {
        container.CleanUpMess(); // <-- This part seems fine

        //? <-- Should I be calling other things here?
    }
}

我相信它与下面显示的分配有关 mClip = Clip 我想通过引用传递这部电影以供 Container 类使用,但我相信当有两个对 Container 类的引用时,垃圾收集器会感到困惑相同的影片剪辑。有没有一种方法可以让我不再需要这个参考文献。

//File (Container.as)
class utils.Container
{
    private var mClip:MovieClip;
    public function Container(clip:MovieClip)
    {
        mClip = clip;
    }

    public function CleanUpMess()
    {
        mClip.removeMovieClip(); // <--- Doesn't seem to work
        removeMovieClip(mClip); // <--- Doesn't seem to work
    }
}

我在 Actionscript 2.0 文档中找到了 MovieClip.removeMovieClip(),但我认为我使用它不正确,或者它不适用于我的情况。

I've created a class that contains all of the movie clips from the stage. These variables are referring to the instance's name on the stage. Everything seems fine as long as I keep all of my functionality in a single class. However, when I try to use another class to manage the properties of a movie clip, I run into resource clean up issues.

//File (MainScreen.as)
import utils.Container;

class MainScreen extends MovieClip
{
    private var clip1:MovieClip;
    private var clip2:MovieClip;
    private var container:Container

    public function MainScreen()
    {
        container = new Container(clip1);
    }

    public function CleanUpMess()
    {
        container.CleanUpMess(); // <-- This part seems fine

        //? <-- Should I be calling other things here?
    }
}

I believe it's related to the assignment shown below mClip = clip I want to pass this movie by reference to be used by the Container class but I believe the garbage collector is getting confused when there are two references to the same MovieClip. Is there a way I can give it a hit that this reference is no longer needed.

//File (Container.as)
class utils.Container
{
    private var mClip:MovieClip;
    public function Container(clip:MovieClip)
    {
        mClip = clip;
    }

    public function CleanUpMess()
    {
        mClip.removeMovieClip(); // <--- Doesn't seem to work
        removeMovieClip(mClip); // <--- Doesn't seem to work
    }
}

I've found MovieClip.removeMovieClip() in the Actionscript 2.0 documentation, but I think I'm using it incorrectly, or that it doesn't apply to my situation.

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

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

发布评论

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

评论(1

无言温柔 2024-10-07 17:06:08

如果您正在调用 container.CleanUpMess();,则无需在该类中设置任何其他内容,除非它不在类中的 CleanUpMess() 函数内文件。 CleanUpMess() 方法位于类中,因此可以访问您传递给构造函数方法的影片剪辑。您应该能够只调用类文件中的影片剪辑变量并从那里更改其属性。

例如:

public function CleanUpMess()
{
mClip.x = 10;
mClip.y = 30;
}

这有帮助吗?

if you are calling container.CleanUpMess(); you don't need to set up anything else in that class unless it is not within the CleanUpMess() function in the class file. the CleanUpMess() method is in the class and therefore has access to the movieclip you passed in to the constructor method. you should be able to just call the movie clip variable in the class file and change its properties from there.

ex:

public function CleanUpMess()
{
mClip.x = 10;
mClip.y = 30;
}

does that help at all?

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