I’m trying to create a virtual piano and I am having difficulty.
If I write the code as follows:
var keys: Array = ["c","csharp","d","dsharp","e","f","fsharp","g","gsharp","a","asharp","b","c2"];
for (var i:int = 0; i < keys.length; i++) {
this["play" + keys* + "sound"] = function (event:MouseEvent):void {
this[keys* + "sound"]= getDefinitionByName (this[keys*]) as Class;
keys* = new this[keys* + "sound"]();
}
;
this["key_" + keys*].addEventListener(MouseEvent.ROLL_OVER, (this["play" + keys* + "sound"]));
this["key_" + keys*].addEventListener(MouseEvent.CLICK, (this["play" + keys* + "sound"]));
}
where all of the sounds are linked to the names in the keys array, I receive the following error after clicking the keys:
ArgumentError: Error #1507: Argument name cannot be null.
at global/flash.utils::getDefinitionByName()
at MethodInfo-40()
If I change the first two lines in the function declaration to
this[keys* + "sound"]= new [keys*]();
this[keys* + "sound"].play(550);
I get the following error after clicking the keys:
TypeError: Error #1007: Instantiation attempted on a non-constructor.
at MethodInfo-40()
I need to create this for a final project in an online course - the project is due next Friday and this is only part of it.
Any help is HIGHLY appreciated.