0
votes

How do I change the MovieClip(graphic) that is associated to a class with actionscript 3? For example I have a MovieClip in my library that is named playButton and it's class has the same name. How do I change the MovieClip associated with the class to be playButton2?

The way I display my MovieClips right now is:

private var playButton_:playButton = new playButton();
//in constructor
playButton_.x = 300;
playButton_.y = 300;
addChild(playButton_);

Thanks in advance.

1
Just change it in the library.Aaron Beall

1 Answers

0
votes

You need to declare the variable as being a MovieClip type, after that you can assign it an object of either playButton or playButton2 type. Note though, just changing the variable's value is not enough to remove the old object it referred from display list. You will need to handle these situations manually.

private var _playButton:MovieClip;
// in constructor
_playButton=new playButton();
_playButton.x = 300;
_playButton.y = 300;
addChild(_playButton);

Then, once you don't need the old button, you have to drop the button off display list correctly, remove all the listeners attached, then you simply create a new object and go forward.

// elsewhere
_playButton=new playButton2();
_playButton.x = 300;
_playButton.y = 300;
addChild(_playButton);