I have an application which has a ‘user.as’ class and I have a popup which displays products details. I want to add a ‘market’ property to this popup but it’s not working. here is the code:
User.as:
package com.brb.domain
{
[RemoteClass(alias="com.brb.user.userIBO")]
[Table(name="User")]
[Bindable]
public class User
{
/**
* Id of the user.
*/
[Id(strategy="assigned")]
public var UserID: Number;
public var market: String;
public var isAuthenticated: Boolean;
public function User()
{
super();
}
}
}
I then have an Product.mxml class which displays the product details in a popup:
import com.brb.domain.Product;
import com.brb.domain.User;
...
[Bindable]
private var _product: Product;
[Bindable]
private var _currentUser: User;
public function set product( value: Product ): void
{
this._product = value;
mySrc ="file:///C|/MultimediaSync/market_"+this.market.toString()+"/pictures/"+imageName;
trace(this._currentUser.market.toString());
...
}
The above is returning:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
My question is how can I access properties from User.as class in another function like above?
Flex is an Object Oriented language. What this means is that (in most cases, excluding things called ‘statics’) you need an instance of an object to access its characteristics.
In this case, ‘User’ is your object, as defined in User.as, and you need an instance of it, by calling
somewhere in your MXML, before you try to reference
_currentUser.market. Thisnew User()syntax is referred to as instantiating an object, or creating an instance. Afterwards,_currentUserholds a reference to that instance of the object, which has a_marketproperty you can access.