Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WHY DOES IT SAY IT CANT CALL setUserID??
- AsyncErrorEvent: ReferenceError: Error #1069: Property setUserID not found on flash.net.NetConnection and there is no default value.
- -------------------------------------------------------------------------------------
- test.fla:
- //import flash.net.NetConnection;
- import flash.net.SharedObject;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.events.NetStatusEvent;
- import flash.events.SecurityErrorEvent;
- import flash.events.SyncEvent;
- import flash.events.TimerEvent;
- import flash.utils.Timer;
- import flash.display.Sprite;
- import fl.data.DataProvider;
- var nc:NetConnection=new NetConnection();
- var userSO:SharedObject;
- var chatSO:SharedObject;
- var myID:Number;
- sendBtn.enabled=false;
- msgText.enabled=false;
- myConn_btn.addEventListener(MouseEvent.CLICK, myConnect);
- function myConnect(event:MouseEvent):void {
- switch (myConn_btn.label) {
- case "Connect" :
- if (userName.text!="") {
- if (userName.text!="Name") {
- debugWin.appendText("Connecting..."+"\n");
- userName.editable=false;
- myConn_btn.enabled=false;
- //sendBtn.addEventListener(MouseEvent.CLICK, onSendBtnClick);
- //deSelectBtn.addEventListener(MouseEvent.CLICK, onDeSelectBtnClick);
- //msgText.addEventListener("enter", onEnterPressed);
- //usersList.addEventListener(Event.CHANGE, onUserSelected);
- nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
- nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
- nc.connect("rtmpe://fms2.bongtvlive.com/test/v1", userName.text);
- nc.objectEncoding=ObjectEncoding.AMF3;
- } else {
- chatText.htmlText+="<b>Please enter a name</b><br>";
- }
- }
- break;
- case "Disconnect" :
- nc.close();
- chatText.htmlText+="<b>You have been disconnected</b><br>";
- myConn_btn.label="Connect";
- userName.editable=true;
- sendBtn.enabled=false;
- msgText.enabled=false;
- break;
- }
- }
- function onNetStatus(event:NetStatusEvent):void {
- trace(event.info.code);
- switch (event.info.code) {
- case "NetConnection.Connect.Success" :
- debugWin.appendText("Connected!"+"\n");
- myConn_btn.label="Disconnect";
- myConn_btn.enabled=true;
- break;
- case "NetConnection.Connect.Rejected" :
- debugWin.appendText("Connection rejected"+"\n");
- debugWin.appendText(event.info.application.msg+"\n");
- debugWin.appendText("Event: "+event.info.code+"\n");
- debugWin.appendText("Type: "+event.info.level+"\n");
- debugWin.appendText("Message:"+event.info.description+"\n");
- break;
- case "NetConnection.Connect.Failed" :
- debugWin.appendText("Connection failed."+"\n");
- break;
- case "NetConnection.Connect.Closed" :
- debugWin.appendText("Connection closed."+"\n");
- myConn_btn.label="Connect";
- break;
- }
- }
- function asyncErrorHandler(event:AsyncErrorEvent) {
- trace("AsyncErrorEvent: "+event.error);
- }
- //AS2 method...
- //nc.setUserID = function(/*userId:Number,clientId:String*/){
- //setUserId();
- //}
- //AS3 method...
- function setUserId():void {
- trace("setUserID> called from server..");
- //debugWin.appendText("userId/clientId received: "+userId+"/"+clientId+"\n");
- //myID=userId;
- //getUserListSO();
- //getChatSO();
- }
- -------------------------------------------------------------------------------------
- main.asc:
- /*
- Between the time an instance is created and destroyed, a number of things can happen.
- To simplify how things work, they are divided into three sections: startup, midlife,
- and shutdown.
- Each application object is a singleton object. Each instance gets it's own application
- object which is an instance of the Application class.
- These are all the standard event handler method of the application object
- */
- /***************************
- Startup
- ***************************/
- application.onAppStart = function() {
- //A. onAppStart is where to Initialize counters, variables, id's, etc
- trace("onAppStart> "+application.name+" is starting at "+new Date());
- this.users = new Object;
- //B. You can set up a Server-side shared object to synchronize clients
- this.usersSO = SharedObject.get("userList_so", false);
- this.chatSO = SharedObject.get("chat_so", false);
- // this.test_so = SharedObject.get("test_so", true);
- //C. This is the proper way to set default variables. It allows for expansion
- // if (this.test_so.getProperty("t" == undefined)) {
- // }
- // if (this.test_so.getProperty("foo" == undefined)) {
- // }
- //Always assign unique ID's on the Server-Side because it's single threaded
- this.nextUserId = 0;
- };
- application.onStatus = function(info) {
- trace("onStatus> info.level: "+info.level+", info.code: "+info.code);
- trace("onStatus> info.description: "+info.description);
- trace("onStatus> info.details: "+info.details);
- };
- application.onConnect = function(clientObj, userName, password) {
- //A. Assign a uniqueID for any user who logs in
- clientObj.userId = this.nextUserId++;
- //B. Decide if a client needs a userName
- clientObj.userName = userName;
- //C. Decide if you want to give a client user read/write access
- //clientObj.writeAccess = "/public";
- //clientObj.readAccess = "/";
- //D. Inform the user that they have made a success connection
- this.acceptConnection(clientObj);
- this.users["user_"+clientObj.userId] = clientObj;
- this.usersSO.setProperty("user_"+clientObj.userId,clientObj);
- clientObj.call("setUserID",null/*,clientObj.userId,clientObj.id*/);
- //trace info
- trace("onConnect> clientObj.ip: "+clientObj.ip);
- trace("onConnect> clientObj.agent: "+clientObj.agent);
- trace("onConnect> clientObj.referrer: "+clientObj.referrer);
- trace("onConnect> clientObj.protocol: "+clientObj.protocol);
- trace("onConnect> clientObj.id/userId/userName/password: "+clientObj.id+"/"+clientObj.userId+"/"+userName+"/"+password);
- };
- application.onDisconnect = function(clientObj) {
- //A. Clear any session variables that may pertain to a client user
- // (SharedObject variables)
- this.usersSO.setProperty("user_"+clientObj.userId,clientObj);
- delete this.users[clientObj.userId];
- //trace info
- trace("onDisconnect> clientObj.id/userId/userName: "+clientObj.id+"/"+clientObj.userId+"/"+clientObj.userName);
- trace("onDisconnect> disconnecting at: "+new Date());
- //this.nextUserId--;
- };
- /***************************
- Shutdown
- ***************************/
- application.onAppStop = function(info) {
- //A. For when the app stops
- trace("onAppStop> application.name: "+application.name);
- trace("onAppStop> stopping at "+new Date());
- trace("onAppStop> info.level: "+info.level);
- trace("onAppStop> info.code: "+info.code);
- trace("onAppStop> info.description: "+info.description);
- };
Add Comment
Please, Sign In to add comment