Adding Random Library Instances to Stage Using Arrays

It’s been a long while since I’ve used Flash or AS3 so you’ll have to bear with me. :wink:

I want to create a little music sight reading helper: notes will appear randomly on the bass and treble staffs and when the note appears the correct piano sound can be heard as well (the note should appear/sound for 4 seconds and then be removed from the stage and replaced by another randomly selected note). Only one note will appear at a time in this first version of the program.

I have a Library of Movieclips that are exported to Actionscript on frame 1, and some basic code. I can successfully attach a single MC symbol to the stage using the following code:

var Middle_C: C4_Middle_C = new C4_Middle_C;
addChild(Middle_C);
Middle_C.x = 328;
Middle_C.y = 321;

So that much works, but I now want to create an array to hold the various instance names and add them to the stage programmatically.

This is the code I have so far:

import flash.display.MovieClip;

// Array of Actionscript instance names
var notesArray: Array = ["C4_Middle_C", "D4", "E4", "F4", "G4", "A4", "B4", "C5"];
// Array of y coordinate positions for these instances
var yPosArray: Array = [321, 303, 285, 267, 249, 231, 213, 195];

// Create timer
var timer: Timer = new Timer(4000, 3);

// Add event listeners
timer.addEventListener(TimerEvent.TIMER, addNote);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, noteSoundComplete);

function getRandomElementOf(notesArray: Array): Object {
    var idx: int = Math.floor(Math.random() * notesArray.length);
    return notesArray[idx];
    trace(idx);
}

function addNote(event: TimerEvent): void {
    stage.addChild(getRandomElementOf(notesArray) as MovieClip);
}

function noteSoundComplete(event: TimerEvent): void {
    //Remove this MC from the stage
    this.parent.removeChild(this);
}
timer.start();

But I’m getting the following error -

TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/addChild()
    at flash.display::Stage/addChild()
    at PianoAudio/addNote()
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()

http://burntscarlet.com/_test/help_forums/Kirupa/grand_staff_test.fla.zip