Comunidad de diseño web y desarrollo en internet online

Ayuda.AS3. como asignar un moviclip a un jugador segun sexo?

Citar            
MensajeEscrito el 04 Sep 2009 07:53 am
Hola a todos, espero que me puedan alludar.
soy nuevo en esto de AS3 y no soy programista pero me manejo un poco en codigo.

les explico el problema, estoy tratando de hacer un juego en flash con 2 moviclips (un hombre y una mujer).
en el cual pueden jugar 2 personas, anterior mente registradas en una lista.

como asignar a un moviclips , a un jugador segun su sexo (hombre o mujer)?
y en el caso que juegen dos hombres, como puedo asginar atravez de mi sprip dar filtros al mismo moviclip?

Nota. el juego funciona, con dos moviclip y con dos personajes y me muestra los nombres de las personas que juegan.
el pero lo que necesito es asignar un moviclip a un usuario segun su sexo... mmm.... hay ideas????

los moviclips, se llaman rabbidOne (que es el hombre) y rabbidTwo (que es la mujer)
aca les dejo el codigo de mi Script.

----------------

package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
import flash.net.XMLSocket;
import flash.system.Security;
import com.adobe.serialization.json.*;


public class Fight extends MovieClip {

private var gamerId:int = 0;
private var fightId:int = 0;
private var gamerTimer:Timer;
private var socket:XMLSocket;



public function Fight() : void {
Security.loadPolicyFile("xmlsocket");

this.socket = new XMLSocket();
this.socket.connect(0000);
this.socket.addEventListener(Event.CONNECT, OnConnect);
this.socket.addEventListener(Event.CLOSE, OnClose);
this.socket.addEventListener(DataEvent.DATA, OnData);
this.socket.addEventListener(IOErrorEvent.IO_ERROR, OnError);
this.socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, OnError);

this.gamerTimer = new Timer(5000, 1);
this.gamerTimer.addEventListener(TimerEvent.TIMER_COMPLETE, OnGamerTimerComplete);
}


public function sendBlowCommand(event:MouseEvent) : void {
if (this.gamerTimer.running == false) {
this.gamerTimer.start();
indicator.gotoAndStop('disable');

this.sendCommand('blow', this.loaderInfo.parameters);
}
}


private function OnGamerTimerComplete(event:TimerEvent) : void {
indicator.gotoAndStop('enable');
}


public function sendCommand(command:String, commandData:*) : void {
if (this.socket.connected == true) {
var data:Object = new Object();
data[command] = commandData;
this.socket.send(JSON.encode(data) + '\n');
}
}


public function OnConnect(event:Event) : void {
this.gamerId = this.loaderInfo.parameters.gamerId;
this.fightId = this.loaderInfo.parameters.fightId;
this.sendCommand('connectToFight', this.loaderInfo.parameters);
fightText.text = 'Connected. Waiting for the second player...';
}


public function OnClose(event:Event) : void {
}


// received the command from the server
private function OnData(event:DataEvent):void {
try {
var id:String;
var data:Object = JSON.decode(event.data);
for (var command:String in data) {
switch (command) {
case 'begin':
fightText.text = 'Fight!';
indicator.gotoAndStop('enable');
rabbidTwo.addEventListener(MouseEvent.CLICK, sendBlowCommand);
break;

case 'health':
for (id in data.health) {
if (Number(id) == this.gamerId) {
rabbidOneHealth.text = data.health[id];
} else {
rabbidTwoHealth.text = data.health[id];
}
}
break;


case 'name':
for (id in data.name) {
if (Number(id) == this.gamerId) {
rabbidOneName.text = data.name[id];
} else {
rabbidTwoName.text = data.name[id];
}
}
break;

case 'animate':
var randomNum:Number = Math.floor(Math.random() * 2) + 1;
for (id in data.animate) {
if (Number(id) == this.gamerId) {
if (data.animate[id] == 'strike-blow' || data.animate[id] == 'receive-blow') {
data.animate[id] += randomNum.toString();
}
rabbidOne.gotoAndPlay(data.animate[id]);
} else {
if (data.animate[id] == 'strike-blow' || data.animate[id] == 'receive-blow') {
data.animate[id] += randomNum.toString();
}
rabbidTwo.gotoAndPlay(data.animate[id]);
}
}
break;

case 'error':
fightText.text = data.error;
break;

case 'end':
fightText.text = 'Game Over';
rabbidTwo.removeEventListener(MouseEvent.CLICK, sendBlowCommand);
break;

default:
break;
}
}

} catch (error:Error) {
trace('bad');
}
}


private function OnError(event:ErrorEvent):void {
fightText.text = event.text;
fightText.textColor = 0xFF0000;
}
}

Por Gero4

5 de clabLevel



 

chile

chrome
Citar            
MensajeEscrito el 04 Sep 2009 08:54 am
puff, es largo de explicar pero a ver si lo consigo
Tienes dos VARIABLES "rabbidOne" y "rabbidTwo". Digo que tienes dos variables porque lo que tienes es, en el escenario dos MCs cuyo "nombre de instancia" son rabbidOne y rabbidTwo. Sí, en AS3 los nombres de instancia son "variables".
Lo primero que vamos a hacer es sacarlos del escenario, y meterlos manualmente. Para ello deberás seleccionar el símbolo en la bibliotece, exportar para ActionScript y dales como nombre de Clase "Hombre" y "Mujer" respectivamente -sí, la primera con mayúsculas) -como Clase Base, la Clase Base MovieClip-

Añadiremos los MCs manualmente.

Código ActionScript :

//al principio de tu película
var rabbidOne:Hombre=new Hombre();
addChild(rabbidOne);
var rabbidTwo:Mujer=new Mujer();
addChild(rabbidTwo);

Vemos que tienes lo mismo que tenías anteriormente pero con una ventaja. si quisiéramos tener a dos mujeres, podríamos escribir

Código ActionScript :

//al principio de tu película
var rabbidOne:RabidOne=new Mujer();//<--la "variable" rabbidOne ahora es de la Clase Mujer
addChild(rabbidOne);
var rabbidTwo:RabidOne=new Mujer(); 
addChild(rabbidTwo);


Vale, ahora lo que hace falta es poder elegir que las variables rabidOne y rabidTwo puedan ser de tipo Hombre o Mujer según lo que elijamos. Para ello existe getDefinitionByName, te cuento cómo funciona

Código ActionScript :

//si elegimos hombre para "rabbidOne"
var ClassReference:Class = getDefinitionByName("Hombre") as Class;  //<--en una variable ClassReference apuntamos a hombre
var rabbidOne:Object = new ClassReference();  //<--le decimos que rabbidOne es de esa Clase

//si elegimos mujer para "rabbidOne"
var ClassReference:Class = getDefinitionByName("Mujer") as Class;
var rabbidOne:Object = new ClassReference();

Lo que no sé es en qué momento eliges lo del hombre o mujer
slds.

Por Eliseo2

710 de clabLevel



 

firefox
Citar            
MensajeEscrito el 07 Sep 2009 06:49 am
hola, muchas gracias por tu respuesta.
los datos los tomo atraves del servidor, en el cual esta la lista , que contiene los datos.
sexo : 1 = mujer y 2 = hombre
usuario.

el usuario no puede elegir el personaje, me explico si la persona que se conecta es hombre por defecto , apararece el conejo hombre y si es mujer la coneja...

Por Gero4

5 de clabLevel



 

chile

chrome

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.