button is null because document.createElement("button") is not an instance of MyButton. Is this supposed to work?
MyButton.as package { public class MyButton extends HTMLButtonElement { public function MyButton() { super(); this.addEventListener("click", button_clickListener, false); } private function button_clickListener(event : MouseEvent) : void { alert("Hello World"); } } } WebProject1.as package { public class WebProject1 { public function WebProject1() { var button : MyButton = document.createElement("button") as MyButton; button.innerHTML = "Press Me"; document.body.appendChild(button); } } } This code compiles fine, but when I run it, I am getting a null for variable button. Console log: Uncaught TypeError: Cannot set property 'innerHTML' of null Thanks, Om