Posted By

vip4lyf on 02/28/09


Tagged

as3


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

zimmen
spastic
mattlohmann
spa
drala
tspitzr
gnowenegue


AS3 - How to access the Document Class from another class


 / Published in: ActionScript 3
 

  1. package {
  2. /* Imports */
  3. import flash.display.Sprite;
  4. import com.OtherClass;
  5.  
  6. public class Main extends Sprite {
  7. /* Private Properties */
  8. private static var _instance:Main;
  9. private var otherClass:OtherClass;
  10.  
  11. /* Constructor */
  12. public function Main() {
  13. _instance = this;
  14. otherClass = new OtherClass();
  15. }
  16.  
  17. /* Public Methods */
  18. public static function get instance():Main {
  19. return _instance;
  20. }
  21.  
  22. }
  23. }
  24.  
  25. /************ ***************/
  26.  
  27. package com {
  28. /* Imports */
  29. import flash.display.Sprite;
  30. public class OtherClass {
  31. /* Private Properties */
  32. private var _dc:Sprite;
  33. private var _sh:uint;
  34. private var _sw:uint;
  35. /* Constructor */
  36. public function OtherClass() {
  37. _dc = Main.instance;
  38. _sh = _dc.stage.stageHeight;
  39. _sw = _dc.stage.stageWidth;
  40. }
  41. }
  42. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: MatMadik on June 23, 2011

Please Elaborate. The acid test for me is, can I trace and output a variable from Main through OtherClass? Can I do it with this?

Posted By: vip4lyf on August 10, 2011

Sure. Just declare the variable in the main document class as public and access it from other class. Questions u can email me. [email protected]

You need to login to post a comment.