Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few ways to achieve this. One way would be to pass a reference of the document class to the constructor of the other class:</p> <pre><code>package { public class AnotherClass { private var _doc:Main public function AnotherClass(doc:Main) { _doc = doc; } public function AnotherRandomMethod():void { _doc.SomeRandomMethod(); } } } </code></pre> <p>or to the function itself</p> <pre><code>package { public class AnotherClass { public function AnotherClass() { } public function AnotherRandomMethod(doc:Main):void { doc.SomeRandomMethod(); } } } </code></pre> <p>You could also use a singleton design pattern by declaring a global static variable and assigning the document class to it. Although singletons are regarded as an <a href="http://en.wikipedia.org/wiki/Anti-pattern" rel="nofollow">anti-pattern</a>. For example:</p> <pre><code>package { import flash.display.MovieClip; public class Main extends MovieClip { public static var instance:Main; public function Main() { instance = this; } public function SomeRandomMethod():void { } } } </code></pre> <p>then</p> <pre><code>package { public class AnotherClass { public function AnotherClass() { } public function AnotherRandomMethod():void { Main.instance.AnotherRandomMethod(); } } } </code></pre> <p>Another way would be to make use of the Service Locator pattern (although some view it as an anti-pattern too). <a href="http://gameprogrammingpatterns.com/service-locator.html" rel="nofollow">http://gameprogrammingpatterns.com/service-locator.html</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload