Skip to main content
mkayyali
Inspiring
February 21, 2011
Question

Communicate between custom class

  • February 21, 2011
  • 1 reply
  • 707 views

Hi,

i need to know what is the best way to communicate between custom classes.

For example:

how to get public var value in document class from another class in another package.

i know two ways but i need to know what if i am in the right side or not:

1- public static var Root:Main = this; and then call Main.Root.PublicVarName from another class.

2- make instance from the class ( var classInstance:ClassName = new ClassName() )  then to call function or var ... ( classInstance.PublicVarName ) but in this case i can't call the Main ( Document class ) as i got an error when try to create instance from Document class.

Thanks a lot

This topic has been closed for replies.

1 reply

Kenneth Kawamoto
Community Expert
Community Expert
February 21, 2011

When you instantiate a Class you can pass the Document Class object reference to the instance as an argument, so that the instance can refer to the Document Class.

Or make the var public static var in the Document Class. Then you can access it from any other Classes as "Main.publicStaticVarName".

mkayyali
mkayyaliAuthor
Inspiring
February 21, 2011

Thats what i already do, all what i need to know if this is true or there is better way to communicate between classes

Kenneth Kawamoto
Community Expert
Community Expert
February 21, 2011

Both methods are different from what you described