-
Components and setUsername()
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>
Rodrigo <Vanegas@yahoo.com>
-
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:
Code:
load( "components.asc" );
application.onConnect = function(client, username) {
gFrameworkFC.getClientGlobals(client).username = username;
application.acceptConnection(client)
}
Psx
-
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:
Code:
connect("Joseph");
setUsername("Joe");
Rodrigo <Vanegas@yahoo.com>
-
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
-
Here we go:
Code:
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);
}
============
Code:
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
-
Rodrigo <Vanegas@yahoo.com>
-
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.
Rodrigo <Vanegas@yahoo.com>
-
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:
Code:
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
-
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.
Rodrigo <Vanegas@yahoo.com>
-
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
-
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?
Rodrigo <Vanegas@yahoo.com>
-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|