AS3 - How to access the Document Class from another class


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  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

You need to login to post a comment.