Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The error your getting really says it all. Although <code>_myVar</code> is defined in your <code>Main</code> class <code>public var _myVar:String;</code>, it isn't defined in your <code>Emailtofriend</code> class. If you want access to <code>_myVar</code> you need to do one of the following:</p> <p>Parse a reference of your <code>Main</code> object(using <code>this</code>) to your <code>EmailToFriend</code> class:</p> <p><strong>Main.as(document class)</strong>:</p> <pre><code>package { import flash.display.Sprite; import flash.events.Event; public class Main extends Sprite { public var _myVar:String; public function Main():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); }// end function public function create():void { _myVar = "hello"; }// end function private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); create(); var emailToFriend:EmailToFriend = new EmailToFriend(this); emailToFriend.getVar(); }// end function }// end class }// end package internal class EmailToFriend { private var _main:Main; public function EmailToFriend(main:Main) { _main = main; }// end function public function getVar():void { trace(_main._myVar); }// end function }// end class </code></pre> <p>Or to make <code>_myVar</code> a public static property of <code>Main</code> and access it via <code>Main._myVar</code>:</p> <p><strong>Main.as(document class)</strong>:</p> <pre><code>package { import flash.display.Sprite; import flash.events.Event; public class Main extends Sprite { public static var _myVar:String; public function Main():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); }// end function public function create():void { _myVar = "hello"; }// end function private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); create(); var emailToFriend:EmailToFriend = new EmailToFriend(); emailToFriend.getVar(); }// end function }// end class }// end package internal class EmailToFriend { public function EmailToFriend() {} public function getVar():void { trace(Main._myVar); }// end function }// end class </code></pre> <p>Also one small thing, when using underscores for class properties, you should only use them for private properties, not public. Well I say <strong>only</strong> but I really mean it's more common.</p> <p><strong>[UPDATE]</strong></p> <p>This is in response to your comment:</p> <p><strong>Main.as</strong>: </p> <pre><code>package { import EmailToFriend; import flash.display.Sprite; import flash.events.Event; public class Main extends Sprite { public static var _myVar:String; public function Main():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); }// end function public function create():void { _myVar = "hello"; }// end function private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); create(); var emailToFriend:EmailToFriend = new EmailToFriend(); emailToFriend.getVar(); }// end function }// end class }// end package </code></pre> <p><strong>EmailToFriend.as</strong>:</p> <pre><code>package { import Main; public class EmailToFriend { public function EmailToFriend() {} public function getVar():void { trace(Main._myVar); }// end function }// end class }// end package </code></pre>
    singulars
    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.
 

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