PDA

Click to See Complete Forum and Search --> : Components and setUsername()



vanegas
10-07-2002, 10:56 AM
Has anyone successfully integrated their own ActionScripting with the FlashCom Components? Either I'm making a very simple mistake or the components code is buggy. In particular, I cannot get FCPeopleList.setUsername() to do anything. Meanwhile, I *am* able to set the username with FCCursor.setUsername(), even though it has no effect on the PeopleList instance.

I'm beginning to suspect that the FlashCom components are best used only without additional scripting and that should anyone want to script their own apps, they should do so from scratch.

Rodrigo <Vanegas@yahoo.com>

psychlonex
10-07-2002, 10:00 PM
Hey - This is what I was thinking as well. But you can get it to work. There's an additional bit of code you need to add to your main.asc file if you haven't already.

main.asc:


load( "components.asc" );

application.onConnect = function(client, username) {
gFrameworkFC.getClientGlobals(client).username = username;
application.acceptConnection(client)
}


Psx

vanegas
10-08-2002, 10:47 AM
Originally posted by psychlonex
Hey - This is what I was thinking as well. But you can get it to work. There's an additional bit of code you need to add to your main.asc file if you haven't already.


I already had that in the server script. This code correctly sets the name at connection time, but what I want to do is *change* the username *after* connection has already set the username a first time.

The client code should look something like this:



connect("Joseph");
setUsername("Joe");

psychlonex
10-08-2002, 11:52 AM
Hmmmm..
Very strange. I just tested it out a bit, and can't seem to get it working either!

I have mine loading into another movie where I have a _global.username existing. It seems to pick that up and use that, but even if I change the _global first, and then try setUsername(username); I get nothing.

I'm still messing around with it, I'll post up any success/failures as soon as I can.

Psx

psychlonex
10-08-2002, 02:24 PM
Here we go:


server-side:
============
load( "components.asc" );

application.onConnect = function(client, username)
{
gFrameworkFC.getClientGlobals(client).username = username;
application.acceptConnection(client);
}

Client.prototype.changeName = function(newName) {
trace("changeName "+newName);
gFrameworkFC.getClientGlobals(this).username = newName;
this.call("nameChanged",null,newName);
}
============



client-side:
============
this.init = function() {
nc = new NetConnection();
nc._parent = this;
username = "bob";
nc.onStatus = function(info) {
this._parent.connect(this);
};

nc.nameChanged = function(newName)
{
_root.chat.setUserName(newName);
_root.people.setUserName(newName);
}

nc.connect("rtmp:/test/app", username);
};
//
connect = function (nc) {
this.chat.connect(nc);
this.people.connect(nc);
};
//
function click() {
username = "dave";
nc.call("changeName", null, username);
}
init();
===========


Ok. The deal is that setUsername is really just client side. If you tear into the simpleConnect component, you'll see that it calls changeName on the server, and then when the server responds it calls setUsername to update the client display.

Psx

vanegas
10-08-2002, 03:20 PM
Thanks... I'll try it.

vanegas
10-09-2002, 03:47 PM
Ok. The deal is that setUsername is really just client side. If you tear into the simpleConnect component, you'll see that it calls changeName on the server, and then when the server responds it calls setUsername to update the client display.


I don't know what to tell ya...

I cut and pasted the code into a .fla and .asc respectively and still, calling "click()" does nothing.

The instance "people" just says "bob" and "nc.nameChanged()" is never called.

psychlonex
10-09-2002, 04:28 PM
Hmmm.. after playing with it a while, I managed to get it working. I didn't change anything server-side, but I changed a few things in the fla:



this.init = function() {
nc = new NetConnection();
nc._parent = this;
username = "bob";
nc.onStatus = function(info) {
trace(info.code);
this._parent.connectage(this);
};
nc.nameChanged = function(newName) {
//chat.setUserName(newName);
peeps.setUserName(newName);
};
nc.connect("rtmp://test/my_app", username);
};
//
connectage = function (nc) {
this.chat.connect(nc);
this.peeps.connect(nc);
};
//
function click() {
username = "dave";
nc.call("changeName", null, "dave");
}
init();




BAsically, I changed the name of my connect funtion to connectage, so that it wasn't using a reserved name, though I don't really think that did anything. I have a chat component on stage and a peopleList. Chat is called "chat", and peopleList = "peeps".

One other thing, the line:
nc.connect("rtmp://test/my_app", username);

Obviously has to point to your server and app directory, but what I did was add a new instance, so I was sure that the main.asc was fully reloaded (some issues with this and components I guess)

so:
nc.connect("rtmp://test/my_app/booga", username)

Let me know if you still can't get it working!

Psx

vanegas
10-09-2002, 04:40 PM
My bad. I didn't reload the app after changing the "main.asc". It works now.

So, what was I missing in the documentation? I don't really understand why you had to add "nameChanged()" to the client and "changeName()" to the server. And why do you have to call "people.setUsername()" from "nameChanged()" and pass the username? Isn't the PeopleList object supposed to update by itself whenever the server side syncs?

I still feel that coding with FCS components is more trouble than it's worth.

psychlonex
10-09-2002, 04:48 PM
I guess it depends on what you want to do. Once you start recreating stuff that the simpleConnect already does, it might make more sense to just use it and modify it to do what you want.

What is it that you want it to do that the simpleConnect doesn't?

Psx

vanegas
10-09-2002, 04:59 PM
Well, I might want to use SimpleConnect after all. I want to be able to change the username programmatically. An instance of SimpleConnect allows the user to choose his username, but I want to have the username chosen in the code exclusively. You follow?

Btw, I noticed that you called trace() from the server side. Where do you read the output from?

psychlonex
10-09-2002, 05:29 PM
Cool. I'm guessing you could just make up the name (or generate however you see fit) and call the sc's connect method with your code generated username.

The trace shows up in the communications app inspector. It's in the flashcom/admin/ directory. The trace shows in the "live log" tab.


Psx