Table of Contents

Table of Contents

Variant

Variant

Description

The Variant class defines an object that can represent many types of data. Each Variant stores what type of data it currently represents, as well as the data. The var type in FlexScript uses the Variant.

Types

The type of a Variant is determined when it is assigned a value. When it is assigned to a number, it becomes a VariantType::Number. When it is assigned a treenodearray, it becomes a VariantType::TreeNodeArray. If it is not assigned a value, it becomes a VariantType::Null. Note that the Null type is not equal to a Variant with number data of 0.

Type Description
VariantType::Null Stores no value
VariantType::Number Stores a double value
VariantType::String Stores a string value
VariantType::TreeNode Stores a NodeRef value
VariantType::IntArray Stores an intarray value
VariantType::DoubleArray Stores an doublearray value
VariantType::StringArray Stores an stringarray value
VariantType::TreeNodeArray Stores a treenodearray value

You can get the type of a variant by accessing its .type member.

Methods

  • size() If this variant is representing an array, this returns the size of the array. If it is a Null variant, size() returns 0. Otherwise, it returns 1.
  • operator[](int) If this variant is representing an array, you can use the [] operator to get elements by index (1-based). If it is not representing an array, it returns a copy of itself.
  • c_str() If this variant is representing a string, it returns a pointer to that string. Otherwise, it returns a pointer to an empty string.