I’m trying to make an old fashioned 2D sidescroller game similar to the old Mario games, and i’m stuck with a lil problem: I want to add coins that can be collected by the player. I’ve made (with some help) a coin class that unloads the coins when the player touches them:
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class Coin extends MovieClip
{
var character:MovieClip;
public function Coin()
{
this.addEventListener(Event.ENTER_FRAME, update);
}
public function update(e:Event):void
{
character = MovieClip(root).character;
if (this.hitTestObject(character))
{
this.removeEventListener(Event.ENTER_FRAME, update);
parent.removeChild(this);
}
}
}
}
This works fine when i drag coins onto the stage and walk into them, but the problem is that i want to place every instance into another movieclip called gameLevel, i want gameLevel to hold all of my other movieclips for the sake of scrolling. If i drag the coins into gameLevel i will get the access of undefined property error when i test the game. The code still works though, it unloads the coins, but i’m guessing that error probably is a bad thing
Does anyone know how i can reference the coins when they are inside of gameLevel? Thanks in advance!