Help in getter setter.

  • dhina.techno
  • Newbie
  • Newbie
  • dhina.techno
  • Posts: 8

Post 3+ Months Ago

Hi,
I am a newbie in actionscript 3.0. I just created a property and the code goes like this..

private var _lastname:String;
private var _firstname:String;

// create a "lastname" property
public function get lastname():String {
return this._lastname;
}
public function set lastname(value:String):void {
this._lastname = value;
}

// create a "lastname" property
public function get firstname():String {
return this._firstname;
}
public function set firstname(value:String):void {
this._firstname = value;
}

When i tried to build this, i got the compile time error
"The private attribute may be used only on class property definitions".
your help is highly appreciated
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

Are the variables and methods part of a class? You cannot declare a variable to be class private unless it is in a class. You probably want to do something like the following:

Code: [ Select ]
class Person {
  private var _lastname:String;
  private var _firstname:String;

  public function get lastname() : String
  {
    return this._lastname;
  }
  
  public function set lastname(value:String) : void
  {
    this._lastname = value;
  }
  
  public function get firstname() : String
  {
    return this._firstname;
  }
  
  public function set firstname(value:String) : void
  {
    this._firstname = value;
  }
  
}
  1. class Person {
  2.   private var _lastname:String;
  3.   private var _firstname:String;
  4.   public function get lastname() : String
  5.   {
  6.     return this._lastname;
  7.   }
  8.   
  9.   public function set lastname(value:String) : void
  10.   {
  11.     this._lastname = value;
  12.   }
  13.   
  14.   public function get firstname() : String
  15.   {
  16.     return this._firstname;
  17.   }
  18.   
  19.   public function set firstname(value:String) : void
  20.   {
  21.     this._firstname = value;
  22.   }
  23.   
  24. }
  • dhina.techno
  • Newbie
  • Newbie
  • dhina.techno
  • Posts: 8

Post 3+ Months Ago

Hi Spork,
Thanks very much for the reply. it was not inside the class. that was the problem.. thanks very much once again.
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6252
  • Loc: Seattle, WA

Post 3+ Months Ago

Glad to help. Welcome to Ozzu :)

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 16 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.