all groups > macromedia flash flashcom > february 2006 >
You're in the

macromedia flash flashcom

group:

Limiting access unless admin is available


Limiting access unless admin is available rbm2675
2/20/2006 3:02:57 PM
macromedia flash flashcom:
HI, I am building an app where I only want the person to access it unless
another user(admin) is already present. If not, I want it to go to a
particular frame in the movie that says "the person is not available".

I tried this using

application.onConnect = function(client ){
if (application.clients.length == 0){
var vError = new Object();
vError.message = false;
}

Then in the swf movie I put this

if (info.application.message == false){
gotoAndPlay("NotIn");
}

Now, of course I left the above 'if' statement out of the admin movie, but
this still connects the client to the movie even if the admin is not already
there. Any suggestions.
Re: Limiting access unless admin is available JayCharles
2/20/2006 7:54:42 PM
That's not really a great way to approach soemthing like this. You want to make
sure you have absolute control of who that admin is, so at very least you want
a password. Ideally, you'd want FMS to compare this to a database or secured
file on your https server, but for a quick and dirty job you can define the
password(s) in your ASC.

So, you might want something like this:

application.adminPwd = "somepassword";
application.adminIsIn = 0;
application.onConnect = function (client, clientType, pwd){
if (clientType == "admin" && pwd == application.adminPwd){
// It's the admin, set the adminIsIn variable
// IF the admin is already in, reject
if (application.adminIsIn == 1){
var err = new Object();err.message = "Admin Already In";
application.rejectConnection(client, err);
}else{
application.adminIsIn = 1;
client.clientType = "admin";
application.acceptConnection(client);
}
}else{
// It's not the admin. If the admin is in, accept the connection. If
not, reject.
if (application.adminIsIn == 1){
application.acceptConnection(client);
}else{
var err = new Object();err.message = "No Admin";
application.rejectConnection(client, err);
}
}
}

// When the admin leaves, we need to set that adminIsin var back to false
application.onDisconnect = function(client){
if (client.clienType == "admin"){
application.adminIsIn = 0;
}
}


Now, when you make your connection to FCS, you'll send some additional
parameters... like so

conn = new NetConnection();
conn.connect("rtmp://myserver/myapp/myinstance", "admin", "somepassword");

and

conn = new NetConnection();
conn.connect("rtmp://myserver/myapp/myinstance", "guest", "nopassword");

AddThis Social Bookmark Button