flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Dufilie <andy.dufi...@gmail.com>
Subject Re: [FlexJS] Extending builtin HTML elements
Date Thu, 07 Jan 2016 02:35:12 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message