Someone told me that I had to use a setter…how would I implement that into my code! (I am fairly new to AS3)
On my external AS file for the coin I have the following:
package
{
import flash.display.MovieClip
import flash.events.*;
public class coin extends MovieClip
{
var player_mc:MovieClip;
public static var coinsCollected:uint = 0;
public function coin()
{
// constructor code
this.addEventListener(Event.ENTER_FRAME,update);
}
function update (event:Event):void
{
player_mc=MovieClip(root).player_mc;
if(this.hitTestObject(player_mc))
{
coinsCollected += 1;
this.removeEventListener(Event.ENTER_FRAME,update) ;
parent.removeChild(this);
}
}
}
}
And in the main movie I made a dynamic text box gave it an instance name of “score” and in my action script I wrote:
score.text = String(coin.coinsCollected);