View comments | RSS feed

get statement

function get property () { 
 // your statements here 
}

Permits implicit getting of properties associated with objects based on classes you have defined in external class files. Using implicit get methods lets you access properties of objects without accessing the property directly. Implicit get/set methods are syntactic shorthand for the Object.addProperty() method in ActionScript 1.0.

Availability: ActionScript 2.0; Flash Player 6

Parameters

property:String - The word you use to refer to the property that get accesses; this value must be the same as the value used in the corresponding set command.

Example

In the following example, you define a Team class. The Team class includes get/set methods that let you retrieve and set properties within the class:

class Team { 
 var teamName:String; 
 var teamCode:String; 
 var teamPlayers:Array = new Array(); 
 function Team(param_name:String, param_code:String) { 
 this.teamName = param_name; 
 this.teamCode = param_code; 
 } 
 function get name():String { 
 return this.teamName; 
 } 
 function set name(param_name:String):Void { 
 this.teamName = param_name; 
 } 
}

Enter the following ActionScript in a frame on the Timeline:

var giants:Team = new Team("San Fran", "SFO"); 
trace(giants.name); 
giants.name = "San Francisco"; 
trace(giants.name); 
/* output: 
San Fran San Francisco */

When you trace giants.name, you use the get method to return the value of the property.

See also

addProperty (Object.addProperty method)


Version 8

Comments


No screen name said on Feb 19, 2007 at 12:35 PM :
if an array of objects is passed in to a setter method the object data is discarded and the string "[object Object]" is passed instead.
it's not clear if this is a bug or a limitation of the setter method. either way it should be documented.
No screen name said on Feb 19, 2007 at 3:34 PM :
the feedback i sent earlier today on this should have gone under set instead of get. also i have since found out it only applies when setting from within a custom UI when dealing with custom components. still, very frustrating and not documented.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001874.html