El de la aplicacion:
Código :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
backgroundGradientColors="[#ffffff, #ffffff]"
backgroundGradientAlphas="[1, 1]"
verticalScrollPolicy="auto"
fontFamily="Verdana"
xmlns:view="view.*">
<mx:ViewStack width="100%" height="90%" id="vistaMain" selectedIndex="{ mySingleton.getInstance().VISTA }">
<view:login_user></view:login_user>
<view:encabezado></view:encabezado>
</mx:ViewStack>
</mx:Application>
El del componente "login_user" lo que hace es una consulta a un php para comprobar si existe el usuario y va bien. Desde este componente (dentro de un "if") es desde donde quiero cambiar la vista. Este es el codigo:
Código :
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" xmlns:vistas="vistas.*">
<!--Pantalla: Error de login de user-->
<mx:states>
<mx:State name="error_user" id="error_user">
<mx:RemoveChild target="{panel_id}"/>
<mx:AddChild position="lastChild">
<mx:Panel width="422" height="225" layout="absolute" horizontalCenter="20" verticalCenter="-78.5" title="Error de conexión" fontFamily="Verdana" fontWeight="bold" cornerRadius="10" color="#000000" backgroundColor="#ffffff" id="panel_error" backgroundAlpha="1.0" alpha="1.0">
<mx:Label y="90" text="e-mail:" horizontalCenter="-132.5"/>
<mx:TextInput y="88" width="249" fontFamily="Verdana" horizontalCenter="23.5" id="email_datos_acceso" text="[email protected]"/>
<mx:Button y="135" label="Aceptar" width="112" horizontalCenter="-126" id="button0" click="dame_datos_acceso(event)" />
<mx:Button x="282" y="135" label="Volver atrás" click="atras()"/>
<mx:TextArea borderColor="#ffffff" x="10" y="10" width="382" height="72" color="#ff0000">
<mx:text>Se ha producido un error al intentar conectar al usuario. El login o clave no son correctos. Puede ingresar su e-mail para recibir los datos de acceso por correo, o bien puede volver a intentar conectarse mediante el botón "Volver atrás"</mx:text>
</mx:TextArea>
</mx:Panel>
</mx:AddChild>
<mx:RemoveChild target="{estadotxt}"/>
<mx:AddChild position="lastChild">
<mx:Text x="400" y="422" width="391" id="estado_envio" height="20"/>
</mx:AddChild>
<mx:AddChild position="lastChild">
<mx:Image x="348" y="416" id="icono_estado_envio"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:Panel width="422" height="225" layout="absolute" horizontalCenter="20" verticalCenter="-78.5" title="Identificación de usuario" fontFamily="Verdana" fontWeight="bold" cornerRadius="10" color="#000000" backgroundColor="#ffffff" id="panel_id" alpha="1.0">
<mx:Label y="50" text="Login:" horizontalCenter="-113"/>
<mx:TextInput y="46" width="187" fontFamily="Verdana" horizontalCenter="13.5" id="login" text="admin"/>
<mx:Label y="93" text="Clave:" horizontalCenter="-113"/>
<mx:TextInput y="89" width="187" displayAsPassword="true" fontFamily="Verdana" horizontalCenter="13.5" id="clave" text="admin"/>
<mx:Button y="125" label="Aceptar" width="112" horizontalCenter="23.5" id="btnAceptar" click="onButtonPress(event);" />
<mx:Script>
<![CDATA[
//Enviar datos de acceso al usuario
private function enviar_datos_acceso_Result(event:ResultEvent):void{
if (event.result){
switch (event.result.toString()){
case "OK":
estado_envio.text="Se han enviado sus datos por correo";
icono_estado_envio.source="imagenes/icono_estado_info.png";
break;
case "no_existe_email":
Alert.show("El correo introducido no se encuentra en la base de datos.\n Puede escribir a [email protected] para pedir sus datos de acceso","Error");
break;
case "no_enviado_email":
Alert.show("No se ha podido enviar el correo. Por favor, vuelva a intentarlo mas tarde","Error");
}
}else{
Alert.show("Se ha producido un error de conexión", 'Error de conexión');
}
}
//
//Boton Aceptar para enviar datos de acceso al usuario
private function dame_datos_acceso(event:Event):void{
remoteObject.enviar_datos_acceso(escape(email_datos_acceso.text));
}
]]>
</mx:Script>
</mx:Panel>
<!--Objetos remotos & eventos-->
<mx:RemoteObject id="remoteObject" destination="funciones" showBusyCursor="true">
<!--Validar usuario-->
<mx:method name="validar_user" result="validar_user_Result(event)" fault="onFault(event)"/>
<!--Enviar datos de acceso por correo-->
<mx:method name="enviar_datos_acceso" result="enviar_datos_acceso_Result(event)" fault="onFault(event)"/>
</mx:RemoteObject>
<!--Funciones -->
<mx:Script>
<![CDATA[
//Importamos la clase ArrayCollection, que usaremos en el DataProvider.
import mx.collections.ArrayCollection;
//Importamos las clases para trabajar con los remoteObjects de WebOrb
import mx.rpc.remoting.*;
import mx.controls.*;
import mx.rpc.events.*
//Importamos los detectores de eventos
import flash.events.Event;
///////////////////////////////////////////////////////
import mx.controls.Alert; //Control "Alerta"
///////////////////////
[Bindable]
//Arrays para guardar los datos de las consultas a la BBDD
//
public var rUsuario:ArrayCollection; //Datos del usuario
//Función para validar usuario
private function validar_user_Result(event:ResultEvent):void{
//rellenamos la variable rUsuario con los datos obtenidos en la consulta,
rUsuario=new ArrayCollection(event.result as Array);
//Si todo salió bien...
if (event.result){
if(rUsuario.length>0){
mySingleton.getInstance().VISTA=1;
}else{
currentState="error_user";
}
}else{
Alert.show("Se ha producido un error de conexión", 'Error de conexión');
}
}
//
//Muestra el error al no poder ejecutarse alguna función
public static function onFault(event:FaultEvent):void
{
Alert.show(event.fault.faultString, 'Error de conexión');
}
//Botón "Aceptar" para validar user
private function onButtonPress(event:Event):void{
remoteObject.validar_user(escape(login.text),escape(clave.text));
estadotxt.text="Consultando...";
}
////////// Volver atras para reintentar identificarse
public function atras():void{
currentState="";
}
//Año actual para mostrar en el copyright
public var a:Date=new Date();
///////////////
]]>
</mx:Script>
<mx:Text text="Text" id="estadotxt" width="365" horizontalCenter="0.5" verticalCenter="98.5" color="#008000" fontWeight="bold" fontSize="12" fontFamily="Arial" height="20"/>
<!--Fin de las funciones-->
</mx:Canvas>
Como veras, dentro del
Código :
.........................................
if (event.result){
if(rUsuario.length>0){
mySingleton.getInstance().VISTA=1;
}else{
...............................................
es de donde quiero que me cambie la vista. Saludos, y gracias de nuevo.