all groups > macromedia flash flash remoting > january 2004 >
You're in the

macromedia flash flash remoting

group:

using MVC methodology with forms and remoting


using MVC methodology with forms and remoting cwinston
1/31/2004 8:24:51 PM
macromedia flash flash remoting:

hi,

I am trying to develop an application in which I am attempting to implement MVC programming with Forms, but I have yet to be able to get it to work the right way with FLash remoting.

I created a custom class for my data model which should be able to handle all the data manipulation for the application, here is an example:
ActionScript:
class dataModel {
// declare all application variables
// declare recordset objects
private var getDeptRES:Object;

// declare public variables
var activeScreen:String;
var departments:RecordSet;

// class constructor method
function dataModel() {

// declare department objects
getDeptRES = new Object();

// declare data tracking variables
departments = new RecordSet();
}
function getDepts():RecordSet {
var depts:RecordSet;
_root.srv.getProducts(getDeptRES);

getDeptRES.onResult = function(result:Object):Void {
for(var i:Number=0; i < result.getLength(); i++) {
depts.addItem(result.getItemAt(i));
}
}
return depts;

}

}





after defining my class I create my presenter which is the main form of the application. Within this form, (which is basically the same as the mx.screens.Form except its been extended to handle the flow of screen transitions better within my app), I create an instance of my class:

ActionScript:
admin = new dataModel();




I also have the flash remoting set up in the FLA because that seems to be the only way people have been able to get it to work. This is why when I'm calling up the flash remoting service I set it up at _root.srv.

now the problem I'm having is when the data is to be returned from flash remoting. The repsonder object I created (getDeptRES) seems to be ignored. I recieve:


quote:
--------------------------------------------------------------------------------
NetServices warning 3: There is no defaultResponder, but no responder was given in call to getDepartments
--------------------------------------------------------------------------------



eventhough clearly I have a responder object in my code. Because of this, I cant seem to get the data into my model.

I then get:

quote:
--------------------------------------------------------------------------------
NetServices info 1: getDepartments_Result was received from server: [object Object]
--------------------------------------------------------------------------------



but I cant access or see when I debug where exactly that is going.
And the fact that it seems to be a timing issue when pulling data from remoting.
any suggestions?

chuck

Re: using MVC methodology with forms and remoting P.R. Newman
2/2/2004 11:42:24 AM
I wonder if it's a scoping issue. You've defined your service at the _root
level, but getDeptRES is private:

private var getDeptRES:Object;

Have you tried

_global.getDeptRES = new Object();

or changing private to public?

--
Paul
-------------------------
Team Macromedia Member for Central
http://www.macromedia.com/go/team/
Extending Knowledge, Daily
http://www.communitymx.com
-------------------------

Re: using MVC methodology with forms and remoting cwinston
2/2/2004 9:57:49 PM
i changed it from public to private and still get
NetServices warning 3: There is no defaultResponder, but no responder was given in call to getDepartments

shouldnt the object I created within the class be able to receive the result via the onResult function, or is there something different in the way classes are handled?

do i need to specify the exact path of the result object or can i not use this.getDeptsRES??

chuck

Re: using MVC methodology with forms and remoting P.R. Newman
2/3/2004 5:36:58 PM
You're welcome. Glad it worked out.

Tom Muck's book, "Flash Remoting: The Definitive Guide," has some examples
of using OOP with Flash Remoting. Have you picked that up?

--
Paul
-------------------------
Team Macromedia Member for Central
http://www.macromedia.com/go/team/
Extending Knowledge, Daily
http://www.communitymx.com
-------------------------

Re: using MVC methodology with forms and remoting cwinston
2/3/2004 7:01:43 PM
[quoted text, click to view]
hi,
I fixed the problem with a few modifications after your suggestion.
class datamodel {
var getDeptRES:Object;
var departments:RecordSet;


function datamodel() {
trace("init data Model");
_global.getDeptRES = new Object();
departments = new RecordSet(["name","departmentID","parentID"]);
loadData();
}

function loadData():Void {
var loc:Object;
loc = new Object();

loc = this;
_global.getDeptRES.onResult = function(result:Object):Void {
loc.setDepartments(result);
}
}

function setDepartments(results:RecordSet):Void {
departments = results;
}
}
I had to put the remoting call to the database in the fla. For some reason if I try to make the call from the class, it doesnt recognize the response object.
The call I used was:
_global.srv.admin(_global.getDeptRES);
I also had to make sure that I didnt use this.setDepartments(result) because that would try to call a method in _global.getDeptRES.
also, for some reason I cant set departments using a for loop:
for (var i:Number=0;i < results.getLength();i++) {
departments.addItem(results.getItemAt(i));
}
it wont add an item to the recordset.
thanx for the help... now I have a lot of work to do... :)
chuck

Re: using MVC methodology with forms and remoting gongati2k
2/4/2004 9:48:42 AM
Hi,

I am also trying to implement the MVC architecture using flash remoting....

can u pls send me the code or if you have nay examples of Flash remoting with java.

my mail ID is - vishnuvardhan.g@softprosys.com

Thanks in advance.
Vishnu.

AddThis Social Bookmark Button