On 1/6/16, 6:35 PM, "Andy Dufilie" <andy.dufi...@gmail.com> wrote:

>button is null because document.createElement("button") is not an instance
>of MyButton.

Andy is right.  We have not tried to extend the type system into the
built-in classes.  Not sure we could guarantee that would work.  More
below...


>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 {

Add the following as the ASDoc for the WebProject1() method, then it
should work:

/**
 * @flexjsignorecoercion MyButton
 */
>public function WebProject1() {
>var button : MyButton = document.createElement("button") as MyButton;
>button.innerHTML = "Press Me";
>document.body.appendChild(button);
>}
>}
>}

I've pondered other ways to tell the compiler to not actually generate the
type-checking code since it doesn't actually get used at runtime by the
runtime.  Lots of options here:

1) Extend the type system by adding FLEXJS_CLASS_INFO to existing classes
2) Use @flexjsignorecoercion
3) Automatically suppress type-checking code for all external definitions
4) Compiler options to suppress type-checking
Etc.

-Alex

Reply via email to