actionscript 3 - Sharing variables in OOP AS3 -


in main.as have following:

package  {      import flash.display.movieclip;      public class main extends movieclip {          public var damage:number;          public function main() {             // constructor code              var char:character = new character();             addchild(char);         }     } } 

and have package called character.as

package  {      import flash.display.movieclip;       public class character extends movieclip{          public function character() {             trace(damage);         }     } } 

i need able share damage set in main.as character. there way make speed more global?

why don't make damage public property of character , it'll accessible via main class :

char.damage = 100; trace (char.damage); 

to this, add property character class :

public class character extends movieclip {      public var damage:number;      public function character() {         trace(damage);     } } 

but given comment, take rather global , accessible everywhere opposed applying oop concepts.

if so... define public static in main class :

public static var damage:number; 

and access anywhere :

main.damage = 100;  trace(main.damage); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -