A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Private ?? (MX2004)

  1. #1
    Junior Member
    Join Date
    Nov 2002
    Location
    norway
    Posts
    28

    Private ?? (MX2004)

    I have tried out some new as stuff in the MX2004P trial.

    Doesnt seem to work:

    The private access modifier - private vars are accessible to
    instant variables, can both get and set them directly - no error messages.

    Strictly typed variables - no protests from the compiler when
    assigning values of wrong types to class instance variables.
    Only when trying to assign wrong types to variables INSIDE the class
    declaration I get errormessages.

    Am I missing something or is this new version buggy???


    Oeyvind

    --

    http://home.online.no/~oeyvtoft/Toft...eset/flash.htm

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361
    well its all regulated at compile time and not beyond that. So if you assign a strictly typed variable to another non-typed variable, the compiler has no way of knowing if it is of the right type or not so wont throw out an error. Same applies to private variables. At compile time, if you directly access a private variable you might get an error, but any dynamic variable or property accessed with associative array syntax won't get caught by the compiler. Privates really arent that private.

  3. #3
    Junior Member
    Join Date
    Nov 2002
    Location
    norway
    Posts
    28

    sample

    Ok, I`ll try to illustrate what happens:

    In frame 1 of 1 frame movie:

    import testing.personFiles.Person;
    var person_01 = new Person ("Nate", 32);
    var person_02 = new Person ("Jane", 28);
    //
    //anAge is a private variable in Person class:
    //
    b = person_01.anAge; // no error when accessing priv var.
    trace (b);
    //Result in outputwindow: 32
    //
    //aName is declared as a String type in Person class:
    //
    person_01.aName = 9999; // no error when using wrong type.
    //
    txt.text = person_01.showInfo () + "\n";
    txt.text += person_02.showInfo ();
    //
    //Result in textfield:
    //Hello, my name is 9999 and I`m 32 years old.
    //Hello, my name is Jane and I`m 28 years old.

    I would expect this script to generate error messages.
    Maybe I`m wrong, but if so it seem that strictly typing
    vars and access modifiers are of little use.

    Any thoughts?

    Oeyvind
    http://home.online.no/~oeyvtoft/ToftWeb/
    http://home.online.no/~oeyvtoft/ToftWeb/html/frameset/3d.htm
    http://home.online.no/~oeyvtoft/ToftWeb/html/frameset/flash.htm

  4. #4
    Junior Member
    Join Date
    Nov 2002
    Location
    norway
    Posts
    28

    Oops...

    Found the solution:

    I didnt strictly type the person_01 variable.

    This:

    var person_01 = new Person ("Nate", 32);
    var person_02 = new Person ("Jane", 28);

    Should be:

    var person_01:Person = new Person ("Nate", 32);
    var person_02:Person = new Person ("Jane", 28);

    Shame on me !!!


    Oeyvind
    http://home.online.no/~oeyvtoft/ToftWeb/
    http://home.online.no/~oeyvtoft/ToftWeb/html/frameset/3d.htm
    http://home.online.no/~oeyvtoft/ToftWeb/html/frameset/flash.htm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center