flash - AS2: Simple class not working -


so i'm trying learn create public class, , in class file:

    class com.rcn.menu.menu{      public var title:string;     public var menuitems:array;      public function createmenu(title:string, menuitems:array) {         return title;     }      function createtitlebar(title:string):void  {     } } 

and in seperate swf use code:

    import com.rcn.menu.menu;  var accountability:menu = createmenu("hello",[a,b,c,d]); trace(accountability); 

yet accountability traces undefined, can tell why is?

you have use new keyword make instance of class.

try this:

public class com.rcn.menu.menu{      public var title:string;     public var menuitems:array;      public function menu(title:string, menuitems:array) {         this.title = title;         this.menuitems = menuitems;     }      public function tostring():string{        return title;     }  } 

and create instance:

import com.rcn.menu.menu;  var accountability:menu = new menu("hello",[a,b,c,d]); trace(accountability); 

cheers


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -