Copy link to clipboard
Copied
how can i use getUserID method in my main.as ??
NetConnectionClient.as
package com {
import flash.events.EventDispatcher;
import flash.events.Event;
public class NetConnectionClient extends EventDispatcher {
public static const ONUSERID:String = "onUserID";
private var _uID :Number;
public function setUserID(uID:Number):void {
_uID : uID;
dispatchEvent(new Event(NetConnectionClient.ONUSERID));
}
public function getUserID():Number {
return _uID;
}
}
}
Thanks!
Copy link to clipboard
Copied
That depends... do you have a reference to the NetConnectionClient in your main.as? If so, you should be able to just listen for the event dispatch, or just invoke the getUserId mehod from main.as. Are those not working for you?
Might be helpful if you post the relevant code from your main.as, or explain the classes that stand between main.as and your NetConnectionClient instance
Copy link to clipboard
Copied
package{
import com.NetConnectionClient;
import com.NetConnectionClientEvent;
import com.NetConnectionManager;
import fl.data.DataProvider;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.events.SyncEvent;
import flash.net.SharedObject;
import fl.data.DataProvider;
import fl.video.FLVPlayback;
import flash.display.MovieClip;
public class MainAdm extends Sprite{
private var nc:NetConnectionManager;
private var so:SharedObject;
private var soEl:SharedObject;
private var selectedUser:Number = 0;
private var userID:String;
public function MainAdm(){
nc=new NetConnectionManager();
nc.addEventListener("onConnect",onConnect);
nc.client = new NetConnectionClient();
nc.client.addEventListener("onUserID",onUserId);
nc.client.addEventListener("onReceiveChatMsg",onReceiveChatMsg);
nc.client.addEventListener("onElKaldirMsg",onElKaldirMsg);
nc.client.addEventListener("ongetUserID",ongetUserID);
i want to trace it here
trace(?????.getUserID().toString());
sendButton.label = "Send Message";
sendButton.addEventListener(MouseEvent.CLICK,onSendButtonClicked);
deselectButton.label = "clear";
deselectButton.addEventListener(MouseEvent.CLICK,onDeselectButtonClicked);
/*chatInputText.addEventListener(Event.CHANGE,onEnterPressed);*/
usersList.addEventListener(Event.CHANGE,onUserSelected);
/*sendButton.enabled =
chatInputText.enabled = false;*/
elKaldir.label = "El Kaldir";
elKaldir.addEventListener(MouseEvent.CLICK,onElKaldir);
/*usersTList.columnWidth = 100;
usersTList.rowHeight = 100;
usersTList.columnCount = 1;
usersTList.rowCount = 2;
usersTList.move(30, 250);*/
nc.createNetConnection("rtmp://localhost/FMSTutorial22");
}
.
.
.
.
}
}
Copy link to clipboard
Copied
I'd need to see your NetConnectionClient class to know for sure that this would work.... but what I'd do is define the NetConnectionClient so it's a member of the main.as. That would make it easier to reference.
public class MainAdm extends Sprite{
private var nc:NetConnectionManager;
private var so:SharedObject;
private var soEl:SharedObject;
private var selectedUser:Number = 0;
private var userID:String;
public var ncc:NetConnectionClient;
public function MainAdm(){
nc=new NetConnectionManager();
nc.addEventListener("onConnect",onConnect);
ncc = new NetConnectionClient();
nc.client = ncc
ncc.addEventListener("onUserID",onUserId);
ncc.addEventListener("onReceiveChatMsg",onReceiveChatMsg);
ncc.addEventListener("onElKaldirMsg",onElKaldirMsg);
ncc.addEventListener("ongetUserID",ongetUserID);
i want to trace it here
trace(ncc.getUserID().toString());
}
}
Copy link to clipboard
Copied
package com{
import flash.events.EventDispatcher;
import flash.events.Event;
public class NetConnectionClient extends EventDispatcher{
public static const ONUSERID:String = "onUserID";
private var _uID :Number;
public function setUserID(uID:Number):void{
_uID : uID;
dispatchEvent(new Event(NetConnectionClient.ONUSERID));
}
/*public function getUserID(uID:Number):void{
dispatchEvent(new NetConnectionClientEvent("onGetUserId",_uID));
}*/
public function receiveChatMessage(msg:String):void{
var tempObj:Object = new Object();
tempObj.msg = msg;
dispatchEvent(new NetConnectionClientEvent("onReceiveChatMsg",tempObj));
}
public function getUserIDMessage(uID:String):void{
var tempObj:Object = new Object();
tempObj.msg = uID;
dispatchEvent(new NetConnectionClientEvent("ongetUserID",tempObj));
}
//**********************************************************************
public function getUserID():Number{
return _uID;
}
//**********************************************************************
}
}
Copy link to clipboard
Copied
I see no reason why you couldn't make the NetConnectionClient a member of your main.as, unless there's something else in your architecture that would make it a problem.
that said, it looks like you're going to have some runtime errors with that NetConnectionClient class when getUserIDMessage or receiveChatMessage is invoked ... I don't see an import statement for your NetConnectionClientEvent class.
Copy link to clipboard
Copied
JayCharles thanks, i ll check it again