actionscript 3 - error 1024+1023 with buttons(AS3 Action script 3) -


here code:

package  {  import flash.display.simplebutton;   public class button extends simplebutton {       public function button() {      }      public function addlisteners():void {         button.addeventlistener(mouseevent.click, downstate);     }     public function downstate(event:mouseevent):void {         trace('test');     } } 

}

the button made has correct types(up, down, hit, over) errors say: 1023 incompatible override line 16 column 19 1024: overriding function not marked override line 16 column 19

thank helping if want to!

since button class extending simplebutton, public , protected functions , properties simplebutton available in button.

the simplebutton class has property called downstate, when try declare function called downstate in button class, error because it's clashing existing entity called downstate.

to fix error, use name doesn't exist yet in scope (clickhandler in example below)

package  {      import flash.display.displayobject;     import flash.display.simplebutton;     import flash.events.mouseevent; //add missing imports      public class button extends simplebutton {         public function button(upstate:displayobject=null, overstate:displayobject=null, downstate:displayobject=null, hitteststate:displayobject=null){            //super calls base class constructor (simplebutton)            super(upstate, overstate, downstate, hitteststate);             //let's automatically add click listener when button created            addlisteners();        }          public function addlisteners():void {             this.addeventlistener(mouseevent.click, clickhandler);         }          public function clickhandler(event:mouseevent):void {             trace('test');         }     } } 

also notice few important other changes:

  1. i added import mouseevent class (otherwise you'll unknown class error).
  2. i'm adding click listener this, button refers class (not instance of class) , give unknown property or method error.
  3. i've change constructor (the function name matches class , runs when object instantiated/created) accept same parameters simplebutton.

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -