Search code examples
flashimportaudiocs4

got a debug error 1046 in flash CS4 after trying to play a sound after clicking button


Noobie flash programmer here. I am trying to get the flash movie to play an imported punch sound after the user clicks a button. I got this error: "1046: Type was not found or was not a compile-time constant: punch."

here is the code:

stop();


var punch:punch = new punch();

btn2.addEventListener(MouseEvent.CLICK, playSound2);


function playSound2(e:MouseEvent):void
{
    punch.play();
}

changing "var punch:punch = new punch();" to "var punchSound:punch = new punch();" solved my problem but I was wondering why "var punch:punch = new punch();" didn't work?

Thanks in advance


Solution

  • you need to import the punch class
    and the reason why var punch:punch did not work is because you can not have a var and a class named the same.
    by standards the first letter of a class name should be capital so the following would work if you had a claass named Punch

    var punch:Punch = new Punch( );