PDA

View Full Version : Constructors and properties which get set first?


CDHBookingEdge
12-01-2006, 08:17 PM
Given a component which comes first the the constructor or the properties?

What I mean by this is that if you made a component, and that component had properties..kind of like this (more pseudocode than strict AS/Flex):

package me
{
class myComponent extends Object
{

// Properties
private var m_prop1: int = 0; // note that a default initialization value is set
public function set prop1(value:int)
{
m_prop1 = value;
}
private var m_prop2: Boolean = true;
public function set prop1(value:Boolean)
{
m_prop2 = value;
}

// Constructor
public function myComponent()
{
// This guy will construct the component ;-)
}
}
}


and then an MXML file that uses it something like this:


<me:myComponent prop1="1" prop2="false" />


would the values of m_prop1 and m_prop2 be recognized as 1 and false respectively if they were referenced in the constructor?

My (quite possibly feable) attempts at testing this out have shown that the values would be set by the time the constructor code is executed, but I just wanted to make sure that others have found this to be true as well and that I'm not making false assumptions.

Thanks in advance,
Christopher

senocular
12-01-2006, 08:40 PM
yes, the class variables are defined when the class itself is defined. Any calls to the constructor happen after that class definition (and after the variables have been defined) - even if called within the definition itself.

CDHBookingEdge
12-01-2006, 10:10 PM
Ok it makes sense..pretty much standard OOP. Sorry I must be tired ;-)