(Actionscript 2.0) Passing a MovieClip to an external script. How to clean up
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开发者_如何学JAVA 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.
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?
精彩评论