In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

multiplayer - Papervision3D

/**
 * Copyright Pelisalinet ( http://wonderfl.net/user/Pelisalinet )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/bCZq
 */

package {
    import flash.net.URLRequest;
    import com.bit101.components.*;
    import flash.system.*;
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.sensors.*;
    import flash.ui.*;
    import flash.text.*;
    import jiglib.physics.*;
    import jiglib.plugin.papervision3d.*;
    import net.hires.debug.Stats;
    import org.papervision3d.cameras.*;
    import org.papervision3d.core.math.*;
    import org.papervision3d.materials.*;
    import org.papervision3d.materials.utils.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.objects.parsers.Collada;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.view.*;
    import org.papervision3d.events.*;
    import net.user1.reactor.*;
    

    [SWF(width="465",height="465",frameRate="60",backgroundColor="0x0")]
    public class BasicDemo extends BasicView {

        public static const GROUND_SIZE:int = 85000;
        public static const GROUND_HEIGHT:int = 2000;
        public static const GROUND_SEGMENT:int = 25;

        private var physics:Papervision3DPhysics;
        private var spehres:Vector.<RigidBody>;
        private var cameraTarget:DisplayObject3D;
        private var accel:Accelerometer;
        private var gravityArr:Vector.<Number> = Vector.<Number>([0, 0]);
        private var mouseUse:Boolean = false;
        private var moveX:int = 0;
        private var moveY:int = 0;
        private var playersMovesX:Array = [];
        private var playersMovesY:Array = [];
        private var tank:RigidBody;
        private var colTank:Collada;
        private var _view:DisplayObjectContainer = new Sprite();
        private var _roomName:String;
        private var _reactor:Reactor;
        private var accountManager:AccountManager;
        private var _incoming:TextArea;
        private var _input:Text;
        private var _userList:TextArea;
        private var cristals_text:Text;
        private var score_text:Text;
        private var _room:Room;
        private var full_btn:PushButton;
        private var buy_btn:PushButton;
        private var register_panel:Panel;
        private var login_panel:Panel;
        private var pass_txt:InputText;
        private var user_txt:InputText;
        private var loginUser:String = "";
        private var isLoginB:Boolean = false;
        private var rigidBody:RigidBody;
        private var cristals:int = 1000;
        private var score:int = 0;
        private var rank:String = "Noob";
        private var loader:Loader;
        private var fi_room_btn:PushButton;
        private var en_room_btn:PushButton;
        private var isloader:Boolean = false;
        public var context:LoaderContext = new LoaderContext();
        private var backGround:MovieClip;
        private var scoreMultiplinerPass:Boolean = false;
        private var green:uint = 0x00025500;
        private var pmm1:Array = [];
        private var pmm2:Array = [];
        private var sernu:int = 0;
        
    public function BasicDemo(){
           _init("MMORGmultiballgame.fi", "tryunion.com", 9100);
            addEventListener(Event.ENTER_FRAME,function():void{
            _buildUI();
            });
            
             stage.quality = StageQuality.LOW;
            opaqueBackground = 0x0;
            
            Security.allowDomain('*');
            
            
            
            if(Security.sandboxType == Security.REMOTE)
            {context.securityDomain = SecurityDomain.currentDomain};
            
            changeBackgame("http://www.pelisali.net/email/client/images/bg_1.jpg");  
            
            
            
            super(465, 465, true, false, CameraType.SPRING);
            
            physics = new Papervision3DPhysics(scene, 10);

             var bmd:BitmapData = new BitmapData(100, 100, true, 0x0);
            bmd.lock();
            bmd.perlinNoise(20, 20, 1, 1, true, false, 7, true);
            bmd.applyFilter(bmd, bmd.rect, new Point(), new GlowFilter(0xFFFFFF, 1, 16, 16, 5, 3, true));
            bmd.unlock();
            
            
            var tree:BitmapData = image([5, 9, "01110,11222,12233,22332,23434,04440,00500,00500,00500", [0x70E000, 0x40B913, 0x009933, 0x506418, 0xCC6600]]);
            function image(data:Array):BitmapData {
             var bmd:BitmapData = new BitmapData(data[0], data[1], true, 0);
             var list:Array = String(data[2]).replace(/,/g, "").split("");
             for (var i:int = 0; i < list.length; i++) bmd.setPixel32(i % bmd.width, int(i / bmd.width), (list[i]=="0")? 0 : 0xFF << 24 | data[3][int(list[i]) - 1]);
              return bmd;
            }    
    
    
            var my_cMenu:ContextMenu = new ContextMenu();
            my_cMenu.hideBuiltInItems();
            contextMenu = my_cMenu;
               
             var  material:BitmapMaterial = new BitmapMaterial(tree, true);
              material.doubleSided = true;
            
            var ground:RigidBody = physics.createTerrain(bmd, new WireframeMaterial(0x669933), GROUND_SIZE, GROUND_SIZE, GROUND_HEIGHT, GROUND_SEGMENT, GROUND_SEGMENT);
            ground.friction = 10;
            ground.restitution = 10;
            ground.y = -GROUND_HEIGHT; 
            
           this.addEventListener(Event.ENTER_FRAME,_updatePos);
            
            /*material.addEventListener(FileLoadEvent.LOAD_COMPLETE, function():void {
            
            ground = physics.createTerrain(bmd, material, GROUND_SIZE, GROUND_SIZE, GROUND_HEIGHT, GROUND_SEGMENT, GROUND_SEGMENT);
            
            });*/  
            
            addEventListener(Event.ENTER_FRAME,function():void {
              if(score < 0)
                  score = 0;
              if(score >= 0 && score < 1000)
                  rank = "NoobBall";
              if(score >= 1000 && score < 10000)
                  rank = "ManBall";
              if(score >= 10000 && score < 50000)
                  rank = "SegBall";
              if(score >= 100000 && score < 500000)
                  rank = "VelBall";
              if(score >= 500000)
                  rank = "MarsBall";
                  
              score_text.text = String(score) + " (" + rank + ")";
               
              if(rand(0,100) == false)
                  addCube(rand(0,8000),rand(-1500,500),rand(0,8000),true); 
                  
           /*if(spehres[0].x >= (spehres[1].x-100)){ 
  if(spehres[0].x < spehres[1].x+100){
   if(spehres[0].z >= spehres[1].z-100){
    if(spehres[0].z < spehres[1].x+100){
     alert("You win!!!");   
    }
   }
  }
}
if(spehres[0].x >= spehres[2].x-100){ 
  if(spehres[0].x < spehres[2].x+100){
   if(spehres[0].z >= spehres[2].z-100){
    if(spehres[0].z < spehres[2].x+100){
     alert("You win2!!!");   
    }
   }
  }
  }*/

              
               
            });

            
            
            spehres = new Vector.<RigidBody>();
            for (var i:int = 0; i < 3; i++){
                var wire:ColorMaterial = new ColorMaterial(i == 0 ? 0xFF0000 : 0x808080);
                rigidBody = physics.createSphere(wire, 300, 6, 4);
                rigidBody.restitution = 1;
                rigidBody.friction = 1;
                rigidBody.moveTo(new Vector3D(0, 1000, 0));

                spehres[i] = rigidBody;
            }

            createWall(0, GROUND_SIZE / 2, 0);
            createWall(GROUND_SIZE / 2, 0, 90);
            createWall(0, -GROUND_SIZE / 2, 180);
            createWall( -GROUND_SIZE / 2, 0, 270);

            cameraTarget = new DisplayObject3D();
            scene.addChild(cameraTarget);
 
            SpringCamera3D(camera).target = cameraTarget;
            SpringCamera3D(camera).mass = 7;
            SpringCamera3D(camera).damping = 7;
            SpringCamera3D(camera).stiffness = 1;
            SpringCamera3D(camera).positionOffset = new Number3D(0, 2000, 2000);

          
            if (Accelerometer.isSupported){
                accel = new Accelerometer();
                accel.setRequestedUpdateInterval(100);
                accel.addEventListener(AccelerometerEvent.UPDATE, accelerometer_updateHandler);
            }
            
            else {
                mouseUse = true;
            }
            
            addEventListener(Event.ENTER_FRAME, enterFrameHandler);
            stage.addEventListener(KeyboardEvent.KEY_DOWN,onMoveSp);
            stage.addEventListener(KeyboardEvent.KEY_UP,onMoveSp2);
           
            
        }

        public function rand(low:Number=0, high:Number=1):Number
            {
                 return Math.floor(Math.random() * (1+high-low)) + low;
            }        
        
    public function changeBackgame(url:String="",pos:int=0):void {
        backGround = new MovieClip();
        addChildAt(backGround,pos);
    

        for(var i:int=0; i < 25; i++){
            for(var j:int=0; j < 20; j++){
                loader = new Loader();
            loader.load(new URLRequest(url));  
            loader.x = i*200;
            loader.y = j*200;
            backGround.addChild(loader);  
            }
         }
            var daycris:int = rand(10,2000);
            
            if(isloader)
             switch(rand(1,2)){
                case 1: alert("Congratulations!\rThe day bonus is "+daycris+" cristals!");       
                    cristals = daycris; break;
                case 2: alert("Congratulations!\rThe day bonus is ´Score multiplier pass`!"); 
                    scoreMultiplinerPass = true; break;
             }
              
            
            
            //isloader = true;
            
        
             isloader = true; 
            
        /*var loader2:Loader;

            loader2 = new Loader();
            loader2.load(new URLRequest(url));
            loader2.width = stage.stageWidth;
            loader2.height = stage.stageHeight;
            backGround.addChild(loader2);
        }*/

    }
    
    private function select_room_fi(m:MouseEvent):void {
      _roomName = "MMORGmultiballgame.fi";  
      _room = _reactor.getRoomManager().createRoom(_roomName);
      _room.join();
    }
    private function select_room_en(m:MouseEvent):void {
      _roomName = "MMORGmultiballgame.en";  
      _room = _reactor.getRoomManager().createRoom(_roomName);
      _room.join();
    }

    
    private function _init(roomName:String, server:String, port:Number):void{
        _reactor = new Reactor();
        accountManager = _reactor.getAccountManager();
        _roomName = roomName;
        _reactor.addEventListener(ReactorEvent.READY, onReady);
        _reactor.connect(server, port);
        register_panel = new Panel(this, stage.stageWidth / 2 - 150, stage.stageHeight / 2 - 135);
        register_panel.color = green;
        addEventListener(Event.ENTER_FRAME,function():void {
          register_panel.setSize(300, 250);  
          register_panel.x = stage.stageWidth / 2 - 150;
          register_panel.y = stage.stageHeight / 8;
        });
        
        full_btn = new PushButton(this, stage.stageWidth-125, 1, "F", clickHandler);
        new Label(register_panel,300/2-45,5,"Register or login");
        var reg_btn:PushButton = new PushButton(register_panel,210,220,"Register",onAccauntCreate);
        var log_btn:PushButton = new PushButton(register_panel,120,220,"Login",onAccauntLogin);
        var gue_btn:PushButton = new PushButton(register_panel,30,220,"Guest",onAccauntGuest);
        reg_btn.width = log_btn.width = gue_btn.width = 80;
        new Label(register_panel,20,100,"User");
        new Label(register_panel,20,130,"Pass");
        pass_txt = new InputText(register_panel,70,130);
        pass_txt.password = true;
        pass_txt.width = 180;
        pass_txt.height = 20;
        user_txt = new InputText(register_panel,70,100);
        user_txt.width = 180;
        user_txt.height = 20;
        
       /* _room.addMessageListener("moveX",
                                  moveXListener);
        _room.addMessageListener("moveY",
                                  moveYListener);*/
                                  
                              

    }
    private function addBallB(m:MouseEvent):void {
        addBall(0,0,0,false,false);
    }
     private function addCubeB(m:MouseEvent):void {
        addCube(0,0,0,false,true);
    }
    private function readBalls():void {
        var sp_len:String = _reactor.self().getAttribute("ob_sp_len");
        if(sp_len == null){
            sp_len = String(0);
        }

        for(var i:int=0; i < int(sp_len); i++){
            var _pos:String = _reactor.self().getAttribute("ob_sp"+i);
            var _x:int = int(_pos.split(",")[0]);
            var _y:int = int(_pos.split(",")[1]);
            var _z:int = int(_pos.split(",")[2]);
            addBall(_x,_y,_z);
        }

    }

    private function addBall(x:int=0,y:int=0,z:int=0,isc:Boolean=false,rep:Boolean=true):void {
        if(cristals > 0 || isc){
                var rigidBody2:RigidBody; 
                //if(rep){
                rigidBody2 = physics.createSphere(new WireframeMaterial(0x808080), 300, 6, 4);
                rigidBody2.restitution = 1;
                rigidBody2.friction = 1;
                
                if(x==0 && y==0 && z==0){
                 rigidBody2.moveTo(new Vector3D(spehres[0].x, spehres[0].y, spehres[0].z));
                 _input.text = "PUBLIC_addball ,"+spehres[0].x+","+spehres[0].y+","+spehres[0].z;
                 sendMSG();
                }else{
                 rigidBody2.moveTo(new Vector3D(x, y, z));   
                }
                var sp_len2:String = _reactor.self().getAttribute("ob_sp_len");
                var spheres_s:int = int(sp_len2+1);
                _reactor.self().setAttribute("ob_sp_len",String(spheres_s));
                _reactor.self().setAttribute("ob_sp"+spheres_s, spehres[0].x+","+spehres[0].y+","+spehres[0].z);
                
                if(!isc)
                    cristals--;
                
                }else{
                    alert("You dont have any cristals.");
                }
                

    }
    private function addCube(x:int=0,y:int=0,z:int=0,isc:Boolean=false,rep:Boolean=true):void {
        if(cristals > 0 || isc){
        var ml : MaterialsList = new MaterialsList();
        ml.addMaterial(new WireframeMaterial(0x808080), "left");
            ml.addMaterial(new WireframeMaterial(0x808080), "back");
            ml.addMaterial(new WireframeMaterial(0x808080), "top");
            ml.addMaterial(new WireframeMaterial(0x808080), "right");
            ml.addMaterial(new WireframeMaterial(0x808080), "bottom");
              ml.addMaterial(new WireframeMaterial(0x808080), "front");
              
                if(rep){
                var rigidBody2:RigidBody = physics.createCube(ml, 300, 300, 300);
                rigidBody2.restitution = 1;
                rigidBody2.friction = 1;
                }
                
                if(x==0 && y==0 && z==0){
                rigidBody2.moveTo(new Vector3D(spehres[0].x, spehres[0].y, spehres[0].z));
                }else{
                rigidBody2.moveTo(new Vector3D(x, y, z));    
                }
                
                if(!isc)
                    cristals--;
                    
                }else{
                    alert("You dont have any cristals.");
                }

    }
    private function acModelling():void {
        var ml : MaterialsList = new MaterialsList();
        ml.addMaterial(new WireframeMaterial(0x808080), "left");
            ml.addMaterial(new WireframeMaterial(0x808080), "back");
            ml.addMaterial(new WireframeMaterial(0x808080), "top");
            ml.addMaterial(new WireframeMaterial(0x808080), "right");
            ml.addMaterial(new WireframeMaterial(0x808080), "bottom");
            ml.addMaterial(new WireframeMaterial(0x808080), "front");
              
              addEventListener(Event.ENTER_FRAME,rota);
              
                var ob:RigidBody = st(false,1000,1200,1000,700,1200,700);
                
                function rota(e:Event):void {
                    
                    ob.rotationY += 1.5;
                }
              
                
                function st(m:Boolean=true,x:int=0,y:int=0,z:int=0,w:int=300,h:int=300,d:int=300):RigidBody  {
                var rigidBody2:RigidBody = physics.createCube(ml, w, h, d);
                rigidBody2.restitution = 1;
                rigidBody2.friction = 1;
                rigidBody2.x = x;
                rigidBody2.y = y;
                rigidBody2.z = z;
                rigidBody2.movable = m;
                
                return rigidBody2;
                
                
                }
    }

    private function alert(txt:String):void {
        var alert_panel:Panel = new Panel(this,stage.stageWidth/2-150,stage.stageHeight/2-100);
        alert_panel.setSize(300,200);
        var alert_txt:Label = new Label(alert_panel,300/2-100,200/2-20,txt);
        var close_btn:PushButton = new PushButton(alert_panel,280,0,"X",closeAlert);
        close_btn.width = close_btn.height = 20;
        function closeAlert():void {
            removeChild(alert_panel);
        }

    }

    private function updateCristals():void {
        var selfAccount:UserAccount = accountManager.selfAccount();
                Wonderfl.log(selfAccount + "...");
        if(selfAccount.getAttribute("cristals") != null){
        cristals_text.text = selfAccount.getAttribute("cristals");
        }else{
            cristals_text.text = "100";
            getCristals(100);
        }

    }
    private function getCristals(v:int):void {
        var selfAccount:UserAccount = accountManager.selfAccount();
        var sc:int = int(cristals_text.text+v);
        selfAccount.setAttribute("cristals", String(sc), 
                                   null, true, true);
    }
    private function moveXListener(from:IClient, msg:String):void {
        playersMovesX[0] = msg;

    }
    private function moveYListener(from:IClient, msg:String):void {
        playersMovesY[0] = msg;
    }
    private function createAccountResultListener (e:AccountManagerEvent):void {
     loginUser = e.getUserID();
    }
    private function onAccauntCreate(m:MouseEvent):void {
        if(user_txt.text != "" && pass_txt.text != ""){
        accountManager.createAccount(user_txt.text,pass_txt.text);
        isLogin();
        }else{
            if(user_txt.text == ""){
                 user_txt.text = "Write your username!";
                }
            if(pass_txt.text == ""){
                 pass_txt.text = "Write your password!";
                }
        }
    }
    private function onAccauntLogin(m:MouseEvent):void {
        if(user_txt.text != "" && pass_txt.text != ""){
        accountManager.login(user_txt.text,pass_txt.text);
        isLogin();
        }else{
            if(user_txt.text == ""){
                 user_txt.text = "Write your username!";
                }
            if(pass_txt.text == ""){
                 pass_txt.text = "Write your password!";
                }
        }
    }
    private function onAccauntGuest(m:MouseEvent):void {
        isLogin();
    }

    private function isLogin():void {
        removeChild(register_panel);
        var a:PushButton = new PushButton(this,0,200,"S",addBallB);
        var b:PushButton = new PushButton(this,0,220,"C",addCubeB);
        var c:PushButton = new PushButton(this,0,240,"E",sendMSGB);
        a.width = a.height = b.width = b.height = c.width = 20;
        isLoginB = true;
        _incoming = new TextArea(this);
        _input = new Text(this);
        _userList = new TextArea(this);
        cristals_text = new Text(this,stage.stageWidth/3-100,1,String(cristals));
        score_text = new Text(this,stage.stageWidth/3+50,1,String(score) + " (" + rank + ")");
        score_text.width = 100;
        score_text.height = 20;
        buy_btn = new PushButton(this, stage.stageWidth/3, 1, "B", clickHandler);
         fi_room_btn = new PushButton(this,0,0,"FI");
            en_room_btn = new PushButton(this,0,0,"EN");
            fi_room_btn.width = en_room_btn.width = 20;
            fi_room_btn.addEventListener(MouseEvent.CLICK,select_room_fi);
            en_room_btn.addEventListener(MouseEvent.CLICK,select_room_en);
        _buildUI();
        removeChild(backGround);
        backGround = new MovieClip();
        changeBackgame("http://www.imgup.ru/images_small/cr4x0818710.png");
        acModelling();
    }

    private function onReady(e:ReactorEvent):void{
        _room = _reactor.getRoomManager().createRoom(_roomName);
        accountManager = _reactor.getAccountManager();
        _room.addEventListener(RoomEvent.JOIN, onJoin);
        _room.addEventListener(RoomEvent.OCCUPANT_COUNT, onOccupantCount);
        _room.addEventListener(RoomEvent.UPDATE_CLIENT_ATTRIBUTE, onUpdateClientAttribute);
        _room.addMessageListener(UnionChatConst.CHAT_MESSAGE, onChatMessage);
        /*accountManager.addEventListener(AccountManagerEvent.CREATE_ACCOUNT_RESULT,
                                      createAccountResultListener);
        //accountManager.addEventListener(AccountEvent.LOGIN,
                                      loginListener);*/
        readBalls();
        _room.join();
        _input.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
    }
    private function onUpdateClientAttribute(e:RoomEvent):void{
        _updateUserList();
    }
    private function onOccupantCount(e:RoomEvent):void{
        _updateUserList();
    }
    private function _updateUserList():void{
        var users:String = "";
        var clients:Array = _room.getOccupants();
        var count:int = clients.length;
        for( var i:int = 0; i < count; i++ ){
            users += _getUserName(clients[i]) + "\n";
        }
        _userList.text = users;
    }
    private function onJoin(e:RoomEvent):void{
        _incoming.text+=("room join\n");
        _input.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
    }
    private function onKeyDown(e:KeyboardEvent):void{
        if( e.keyCode == Keyboard.ENTER ){
            sendMSG();
        }
    }
    private function sendMSGB(m:MouseEvent):void {
        sendMSG();
        _input.text = "";
    }

    private function sendMSG():void {
        if( _input.text.substr(0,1) == "/" ){
                var temp:Array = _input.text.split(" ");
                var command:String = temp[0].substr(1);
                switch( command ){
                    case "nick":
                        if( temp[1] != "" ){
                            _reactor.self().setAttribute("nickname", temp[1]);
                        }
                        break;
                    case "core":
                        if(temp[1] != ""){
                            cristals += int(temp[1]);
                            _reactor.self().setAttribute("core", String(cristals));
                        }
                        break;
                    case "norpos":
                        spehres[0].moveTo(new Vector3D(temp[1], temp[2], temp[3]));
                        break;
                    case "getpos":
                        if(temp[1] != ""){
                            _incoming.text+="\n x:" + spehres[0].x +" y:" + spehres[0].y + " z:" + spehres[0].z;
                        }
                        break;


                }

            } else {
                                if( _input.text != "" )
                            _room.sendMessage(UnionChatConst.CHAT_MESSAGE, true, null, _input.text);
            }
            _input.text = "";
    }

    private function onChatMessage(from:IClient, msg:String):void {
        //_incoming.appendText("Guest" + from.getClientID() + " : " + msg + "\n");
        //if(msg.split("PUBLICMSG")[1] == ""){
        
        //}else{
            if(msg.indexOf("PUBLIC_move") != -1){
            var pid:int = int(msg.split("::")[1]);
            pmm1[pid] = msg.split(" ")[1].split(",")[0];
            pmm1[pid] = msg.split(" ")[1].split(",")[1];
            }else{
            if(msg.indexOf("PUBLIC_addball") != -1){
            var ball_pos:Array = msg.split(",");
            addBall(ball_pos[1],ball_pos[2],int(ball_pos[3]),true,true);
            //_incoming.text += "Ballcreated " + ball_pos[1]+","+ball_pos[2]+","+ball_pos[3];
            }else{
            if(msg.indexOf("PUBLIC_adminmsg") != -1){
                alert(msg.split("msg:")[1]);
            }else{
            _incoming.text += _getUserName(from) + " : " + msg + "\n";    
                
            }
            }
            }


        //}

    }

    private function _buildUI():void {
        _incoming.width = stage.stageWidth/4.5;
        _incoming.height = 50;
        _incoming.x = 1;
        _incoming.y = stage.stageHeight-70;
        _input.width = stage.stageWidth/4.5;
        _input.height = 20;
        _input.y = stage.stageHeight - 20;
        _userList.width = 100;
        _userList.height = 110;
        _userList.x = stage.stageWidth-100;
        _userList.y = 0;
        cristals_text.width = 100;
        cristals_text.height = 20;
        cristals_text.text = String(cristals);
        full_btn.width = 20;
        full_btn.x = stage.stageWidth-125;
        buy_btn.width = 20;
        fi_room_btn.y = _incoming.y-20;
        en_room_btn.y = _incoming.y-20;
        en_room_btn.x = 30;
    }
    private function _updatePos():void {
        alert("ok");
        if(sernu <= _room.getOccupants().length){
        var core:String = String(_room.getOccupants()[sernu].getAttribute("x"));
        var core2:String = String(_room.getOccupants()[sernu].getAttribute("y"));
        spehres[sernu].x = int(core);
        spehres[sernu].y = int(core2);
        sernu++;
        }else{
            sernu = 0;
        }

    }

    private function _getUserName(client:IClient):String{
        var userName:String = client.getAttribute("nickname");
        
        
        if( userName ){
            return userName;
        } else {
            return "Guest" + client.getClientID();
        }
    }
        
      
        
        
        
        private function onMoveSp(e:KeyboardEvent):void {
            switch(e.keyCode){
                case Keyboard.LEFT: moveX=-100; _reactor.self().setAttribute("x", String(spehres[0].x)); break;
                case Keyboard.RIGHT: moveX=700; _reactor.self().setAttribute("x", String(spehres[0].x)); break;
                case Keyboard.UP: moveY=-100; _reactor.self().setAttribute("y", String(spehres[0].y)); break;
                case Keyboard.DOWN: moveY=500; _reactor.self().setAttribute("y", String(spehres[0].y)); break;
                case 49: addBall(0,0,0,false,false); break;
                case 50: addCube(0,0,0,false,true); break;
            }
            _room.sendMessage("moveX",true,null,moveX);
            _room.sendMessage("moveY",true,null,moveX);

        }
        private function onMoveSp2(e:KeyboardEvent):void {
            switch(e.keyCode){
                case Keyboard.LEFT: moveX=250; break;
                case Keyboard.RIGHT: moveX=250; break;
                case Keyboard.UP: moveY=250; break;
                case Keyboard.DOWN: moveY=250; break;
                
            }
            _room.sendMessage("moveX",true,null,moveX);
            _room.sendMessage("moveY",true,null,moveX);

        }


        private function enterFrameHandler(e:Event = null):void {
            if(isLoginB){
            cameraTarget.copyPosition(Pv3dMesh(spehres[0].skin).mesh);

            if (mouseUse){
                gravityArr[0] += (-7 * ((moveX / stage.stageWidth - 0.5)) - gravityArr[0]) * 0.4;
                gravityArr[1] += (7 * ((moveY / stage.stageHeight - 0.5)) - gravityArr[1]) * 0.4;
                updateGravity(new Vector3D(gravityArr[0], -10, gravityArr[1]));
                
            }

            physics.engine.integrate(0.75);

            singleRender();
            }
        }

        private function accelerometer_updateHandler(event:AccelerometerEvent):void {
            updateGravity(new Vector3D(event.accelerationX * 20, -10, event.accelerationY * 20));
        }

        private function updateGravity(vec:Vector3D):void {
            if(isLoginB){
            physics.engine.gravity.x = vec.x;
            physics.engine.gravity.y = vec.y;
            physics.engine.gravity.z = vec.z;

            for (var i:int = 0; i < spehres.length; i++){
                spehres[i].updateGravity(physics.engine.gravity, physics.engine.gravityAxis);
            }
            }
        }

        private function clickHandler(e:Event):void {
            stage.displayState = (stage.displayState == StageDisplayState.FULL_SCREEN) ? StageDisplayState.NORMAL : StageDisplayState.FULL_SCREEN;
        }

        private function createWall(tx:Number, tz:Number, rot:Number):void {
            var ml:MaterialsList = new MaterialsList({all: new ColorMaterial(0x0, 0)});
            var wall:RigidBody = physics.createCube(ml, GROUND_SIZE, 100, 10000);
            wall.x = tx;
            wall.y = 5000;
            wall.z = tz;
            wall.rotationY = rot;
            wall.movable = false;
        }
        
           
        
    }
}



class UnionChatConst
{
    public static const CHAT_MESSAGE:String = "chatMessage";
    
}