Hi, thanks for you help!
OK..here is the code(just a bit):
About CHAT: main.as
Code:
package
{
import flash.events.EventDispatcher;
import flash.events.Event;
import flash.text.*;
import flash.net.*;
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import com.firstpixel.multiuser.*
import com.firstpixel.utils.*
import com.firstpixel.*;
import com.firstpixel.multiuser.soccergame.*;
import fl.controls.TextArea;
import fl.controls.DataGrid;
public class Chat extends MovieClip
{
private var lobbyRoomConnection:ServerConnection;
private var lobby:Lobby;
private var room:Room;
private var connecting:Boolean = false;
private var connected:Boolean = false;
private var username:String;
private var password:String;
//private var loginRoom:LoginRoom;
public function Chat():void
{
//listen for load event
addEventListener("loadComplete",loadCompleteHandler);
addEventListener("startLobbyEvent",onStartLobbyHandler);
addEventListener("startGameEventChat",onStartGameHandler);
addEventListener("onReadyToLoginGameEvent",onReadyToLoginGameHandler);
}
private function loadCompleteHandler(evt:Event):void
{
lobbyRoomConnection = new ServerConnection("lobby");
lobbyRoomConnection.addEventListener("onLoginSuccessEvent",onLoginSuccessHandler);
lobbyRoomConnection.addEventListener("onLoginFailedEvent",onLoginFailedHandler);
lobbyRoomConnection.addEventListener("onLoginRejectedEvent",onLoginRejectedHandler);
lobbyRoomConnection.addEventListener("onLoginClosedEvent",onLoginClosedLobbyHandler);
login_mc.addEventListener("onReadyToLoginLobbyEvent",onReadyToLoginLobbyHandler);
login_mc.addEventListener("onPasswordLobbyErrorEvent",onPasswordErrorHandler);
login_mc.addEventListener("onUsernameLobbyErrorEvent",onUsernameErrorHandler);
}
private function onUsernameErrorHandler(evt:Event):void
{
trace("username error")
}
private function onPasswordErrorHandler(evt:Event):void
{
trace("password error")
}
public function onLogoutLobbyHandler(evt:Event):void{
lobbyRoomConnection.close();
gotoAndPlay("login")
}
public function onCloseLobbyToGameHandler(evt:Event):void{
lobbyRoomConnection.close();
dispatchEvent(new Event("onReadyToLoginGameEvent"))
}
public function onCloseGameToLobbyHandler(evt:Event):void{
dispatchEvent(new Event("onReadyToLoginLobbyHandler"));
}
public function onReadyToLoginLobbyHandler(evt:Event):void
{
trace("READY TO LOGIN LOBBY")
if(!connecting){
if(evt.target is Login){
username = Login.username;
password = Login.password;
}
/*if(evt.target is Guest){
username = Guest.username;
password = null;
}*/
connecting = true;
connected = false;
lobbyRoomConnection.type = "lobby";
lobbyRoomConnection.removeEventListener("onLoginClosedEvent",onReadyToLoginLobbyHandler);
lobbyRoomConnection.addEventListener("onLoginClosedEvent",onLoginClosedLobbyHandler);
//Change the host when put the app to final server
//lobbyRoomConnection.connect("rtmp://localhost/lobby_rooms/lobby", undefined, username, password, "lobby");
lobbyRoomConnection.connect("rtmp://10.100.160.130/Game/lobby_rooms/lobby", undefined, username, password, "lobby");
}
}
public function onReadyToLoginGameHandler(evt:Event):void
{
trace("READY TO LOGIN LOBBY")
if(!connecting){
lobbyRoomConnection.removeEventListener("onLoginClosedEvent",onLoginClosedLobbyHandler);
lobbyRoomConnection.addEventListener("onLoginClosedEvent",onReadyToLoginLobbyHandler);
connecting = true;
connected = false;
lobbyRoomConnection.type = "room";
//Change the host when put the app to final server
lobbyRoomConnection.connect("rtmp://10.100.160.130/Game/lobby_rooms/"+lobby.selectedRoom.rtmp, undefined, username, password, lobby.selectedRoom.rtmp);
}
}
private function onLoginSuccessHandler(evt:Event):void
{
gotoAndStop(evt.currentTarget.type);
connecting = false;
connected = true;
}
private function onStartLobbyHandler(evt:Event):void
{
lobby = new Lobby(lobbyRoomConnection.netConnection);
addChild(lobby);
lobby.addEventListener("netConnectionMissing",onNetConnectionMissing);
lobby.addEventListener("onCloseLobbyToGameEvent",onCloseLobbyToGameHandler);
lobby.addEventListener("onLogoutLobbyEvent",onLogoutLobbyHandler);
}
private function onStartGameHandler(evt:Event):void
{
lobby.removeEventListener("netConnectionMissing",onNetConnectionMissing);
lobby.removeEventListener("onCloseLobbyToGameEvent",onCloseGameToLobbyHandler);
lobby.removeEventListener("onLogoutLobbyEvent",onLogoutLobbyHandler);
removeChild(lobby);
lobby = null;
room = new Room(lobbyRoomConnection.netConnection);
addChild(room);
room.addEventListener("netConnectionMissing",onNetConnectionMissing);
room.addEventListener("onCloseGameEvent",onCloseGameToLobbyHandler);
room.addEventListener("onLogoutGameEvent",onLogoutLobbyHandler);
}
private function onNetConnectionMissing(evt:Event):void
{
connecting = false;
connected = false
gotoAndPlay("loaded");
}
private function onLoginFailedHandler(evt:Event):void
{
connecting = false;
connected = false;
}
private function onLoginRejectedHandler(evt:Event):void
{
connecting = false;
connected = false
}
private function onLoginClosedHandler(evt:Event):void
{
trace("ROOM CLOSED")
if(lobbyRoomConnection.type=="room"){
dispatchEvent(new Event("onReadyToLoginLobbyHandler"))
gotoAndStop("lobby");
}
//connecting = false;
//connected = false
//gotoAndPlay("loaded");
}
private function onLoginClosedLobbyHandler(evt:Event):void
{
trace("LOGIN CLOSED EVENT")
connecting = false;
connected = false;
}
}
}
about Game: Main.as
Code:
package{
import flash.events.*;
import flash.display.*;
import caurina.transitions.*;
import flash.text.*;
import flash.net.*;
import flash.utils.*;
import flash.events.*;
/*import com.firstpixel.multiuser.*
import com.firstpixel.utils.*;
import com.firstpixel.*;
import com.firstpixel.multiuser.soccergame.*;*/
import fl.controls.TextArea;
import fl.controls.DataGrid;
import fl.events.*;
import fl.controls.*;
//import es.isdefe.game.Callback;
public class Main2 extends MovieClip
{
// Conexion
public static var ncx:NetConnection;
public function Main():void
{
addEventListener("startMyGame",onStartMyGame);
}
public function onStartMyGame(evt:Event):void{
ncx = new NetConnection();
ncx.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
ncx.connect("rtmp://10.100.160.130/Game");
ncx.client = new Object();
ncx.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
}
function asyncErrorHandler(event:AsyncErrorEvent):void {
trace(event.text);
}
public function netStatusHandler(event:NetStatusEvent):void
{
trace("connected is: " + ncx.connected );
trace("event.info.level: " + event.info.level);
trace("event.info.code: " + event.info.code);
.......etc etce etc
later i've another code..it doesn' matter..
about FLASH movie:
Code:
var url1:URLRequest = new URLRequest("chat.swf");
chatLoader.contentLoaderInfo.addEventListener(Event.INIT, initChatAU1);
chatLoader.load(url1);
}
function initChatAU1(e:Event) {
addChild(chatLoader);
chatLoader.content.x = 500;
chatLoader.content.y = 100;
}
Previously i declares the var charLoader... And just test whit Complete Event...and it's the same problem..
Thanks for your help!