(Actionscript 2.0) 将 MovieClip 传递给外部脚本。如何清理
我创建了一个类,其中包含舞台上的所有影片剪辑。这些变量指的是舞台上实例的名称。只要我将所有功能保留在一个类中,一切看起来都很好。但是,当我尝试使用另一个类来管理影片剪辑的属性时,我遇到了资源清理问题。
//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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在调用
container.CleanUpMess();
,则无需在该类中设置任何其他内容,除非它不在类中的CleanUpMess()
函数内文件。CleanUpMess()
方法位于类中,因此可以访问您传递给构造函数方法的影片剪辑。您应该能够只调用类文件中的影片剪辑变量并从那里更改其属性。例如:
这有帮助吗?
if you are calling
container.CleanUpMess();
you don't need to set up anything else in that class unless it is not within theCleanUpMess()
function in the class file. theCleanUpMess()
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:
does that help at all?