1 Reply Latest reply on Jun 4, 2007 3:42 AM by Newsgroup_User

    public and private vars behavior

    Level 7
      i've done a little test here, and got some wierd results - wonder if anyone
      can explain.
      i've created the following class:

      class Tests.test1 {
      private var myPrivate:String;
      public var myPublic:String;

      function test1(){
      this.myPrivate = "private var";
      this.myPublic = "public var";

      and in the fla file i put this code:

      import Tests.test1;
      var myTest:test1 = new test1();

      now, if you try to compile this code you get an error - "The member is
      private and cannot be accessed." - makes sense. however, if in the second
      line, you put -
      var myTest = new test1()
      without the type-casting, voila - no compile error, and the private var's
      value is traced.
      moreover, if you leave the second line as is, and add the following code
      (after removing the first trace line so it will be compiled) -

      function tracePrivate(test){

      again - no compile error, and the private var's value is being traced.

      if that's so - what's the deal with private vars?
      thanks in advance,