Maybe don't do model = new ModelLocator() in the getInstance() function
since you'll assign ModelLocator.model in the constructor?
Matt
-----Original Message-----
From: cairngorm-devel@yahoogroups.com
[mailto:cairngorm-devel@yahoogroups.com] On Behalf Of gault17
Sent: Tuesday, January 17, 2006 9:29 AM
To: cairngorm-devel@yahoogroups.com
Subject: [cairngorm-devel] FlexPhoneBook ModelLocator problem
I'm trying to implement a ModelLocator similar to the one use in the
FlexPhoneBook example. However, whenever I try to compile the app, I
get
a java.lang.StackOverflowError in FlexXmlServlet (with no stack
trace). If I remove the getInstance function, it compiles fine. Can
someone explain what my problem is? Thanks for your assistance.
Gary
Code below:
import control.*;
import vo.*;
import model.*;
import de.richinternet.utils.Dumper;
class model.ModelLocator
{
private static var model : ModelLocator;
public static var statusMessage : String = "";
public static var users : Array;
public static var selectedUser : UserVO;
public static var trees : Array;
public static var selectedTree : TreeVO;
private var _tasks : Array;
public static var selectedTask : TaskVO;
public static function getInstance() : ModelLocator {
Dumper.dump("modellocator getInstance");
if( model == undefined ) {
model = new ModelLocator();
model.initialize();
}
return model;
}
public function ModelLocator() {
if( ModelLocator.model != undefined ) throw new Error( "Only one
Model instance should be instantiated" );
ModelLocator.model = this;
mx.events.EventDispatcher.initialize( this );
}
public function initialize() : Void {
selectedUser=new UserVO();
selectedTask=new TaskVO();
selectedTree=new TreeVO();
}
public function get tasks() : Array {
if (_tasks == undefined) {
EventBroadcaster.getInstance().broadcastEvent
("getTaskList");
}
return _tasks;
}
public function set tasks(data: Array): Void {
_tasks = data;
}
}
Yahoo! Groups Links