Comunidad de diseño web y desarrollo en internet online

Flex 2.0 + AS 3.0

Citar            
MensajeEscrito el 30 Dic 2006 01:31 am
Hola!

He estado buscando y no encuentro nada de información sobre el envio de Variables en Flex (es decir, AS 3.0).
He generado un formulario en MXML (flex) con el siguiente código:

Código :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script> 
        <![CDATA[
           import flash.net.sendToURL;
           import mx.controls.Label;
            import flash.events.MouseEvent;
            import mx.controls.Alert;

            private function submitLogin(eventObj:MouseEvent):void {
                // Display an Alert to show the event happened.
                var error_text:String = "";
                var error_num:Number = 0;
                //Comprovació de -> Dades d'accès <-
                if(nick.length < 4) {
                   error_num++;
                   error_text += " - El teu nom d'usuari ha de tenir com a mínim 6 lletres.\n";
                }
                if(pass.length < 4) {
                   error_num++;
                   error_text += " - La teva clau d'accès ha de tenir com a mínim 6 lletres.\n";
                }
                if(pass.text != repass.text) {
                   error_num++;
                   error_text += " - Les dues claus d'accès intrduides no coincideixen.\n";
                }
                //Comprovació de -> Curs <-
                if(curso.selectedItem != "") {
                   error_num++;
                   error_text += " - No has seleccionat cap curs.\n";
                }
                //Comprovació de -> Dades personals <-
                if(nombre.length < 4) {
                   error_num++;
                   error_text += " - Si us plau introdueix el teu nom.\n";
                }
                if(apellidos.length < 9) {
                   error_num++;
                   error_text += " - Si us plau introdueix els teus cognoms.\n";
                }
                if(email.text.indexOf("@", 2) == -1) {
                   error_num++;
                   error_text += " - Si us plau introdueix un e-mail vàlid.\n";
                }
                if(email.text != email2.text) {
                   error_num++;
                   error_text += " - Els e-mails introduïts no coincideixen.\n";
                }
                if(telefono.text.length < 9) {
                   error_num++;
                   error_text += " - Si us plau introdueix un telèfon vàlid.\n";
                }
                if(direccion.text.length < 10) {
                   error_num++;
                   error_text += " - Si us plau introdueix la teva direcció.\n";
                }
                if(cp.text.length < 5) {
                   error_num++;
                   error_text += " - Si us plau introdueix el teu codi postal.\n";
                }
                if(poble.text.length < 3) {
                   error_num++;
                   error_text += " - Si us plau introdueix la teva població.\n";
                }
                if(dni_num.text.length < 8) {
                   error_num++;
                   error_text += " - El número de DNI introduït és massa curt.\n";
                }else{
                   var tira:String = 'TRWAGMYFPDXBNJZSQVHLCKET';
                   var num:Number = Number(dni_num.text);
                   var inicio:Number =  num%23;
                   if(dni_letra.text != tira.charAt(inicio)) {
                      error_num++;
                      error_text += " - La lletra del DNI introduït no és correcta.\n";
                      }
                }
                if (error_num > 0){
                   if (error_num == 1){
                      Alert.show("S'ha detectat el següent error:\n\n"+error_text, "Error");
                   }else{
                      Alert.show("S'han detectat "+error_num+" errors:\n\n"+error_text+"\nSol·luciona aquest errors per processar la teva sol·licitut", "Error");
                   }
                }else{
                      // Mensaje a mostrar si el envio es correcto
                   Alert.show("S'ha enviat l'informació correctament.", "Enviant informació...");
                }
            }    
        ]]>
    </mx:Script>
    <mx:Form x="19.5" y="10" id="nouAlumne" defaultButton="{envia}" enabled="true">
      <mx:Panel layout="absolute" title="Nou usuari de C.E.Dolmen" width="660" height="544">
         <mx:Panel x="10" y="10" width="300" height="408" layout="absolute" title="Dades personals">
                <mx:Label x="58" y="12" text="Nom :" />
                <mx:Label x="30" y="37" text="Cognoms :" />
                <mx:Label x="48" y="62" text="E-mail :" />
                <mx:Label x="3" y="87" text="Repetir e-mail :" />
                <mx:Label x="41" y="112" text="Telèfon :" />
                <mx:Label x="37" y="184" text="Població :" />
                <mx:Label x="63" y="234" text="DNI :" />
                <mx:Label x="237" y="234" text="-" />
                <mx:Label x="46" y="136" text="Adreça :" />
                <mx:Label x="20" y="209" text="Codi postal :" />
                <mx:TextInput x="105" y="10" id="nombre"/>
                <mx:TextInput x="105" y="35" id="apellidos"/>
                <mx:TextInput x="105" y="60" id="email"/>
                <mx:TextInput x="105" y="85" id="email2"/>
                <mx:TextInput x="105" y="110" id="telefono" maxChars="9"/>
                <mx:TextArea x="105" y="135" id="direccion"/>
                <mx:TextInput x="105" y="182" id="poble"/>
                <mx:TextInput x="105" y="207" id="cp" maxChars="5"/>
                <mx:TextInput x="105" y="232" width="132" id="dni_num" maxChars="8"/>
                <mx:TextInput x="245" y="232" width="20" id="dni_letra" maxChars="1"/>
         </mx:Panel>
         <mx:Panel x="330" y="10" width="300" height="200" layout="absolute" title="Dades d'accès">
               <mx:TextInput x="105" y="10" id="nick"/>
               <mx:TextInput x="105" y="35" id="pass" displayAsPassword="true"/>
               <mx:TextInput x="105" y="60" id="repass" displayAsPassword="true"/>
               <mx:Label x="14" y="37" text="Clau d'accès :" />
               <mx:Label x="17" y="62" text="Repetir clau :" />
               <mx:Label x="10" y="12" text="Nom d'usuari :" />
                <mx:Button x="81" y="88" label="Validar aquest nom d'usuari" id="validar"/>
                <mx:Text x="10" y="132" text="Nom d'usuari encara disponible." textAlign="center" width="255"/>
         </mx:Panel>
         <mx:Panel x="330" y="218" width="300" height="200" layout="absolute" title="Selecció de curs">
                <mx:Tree id="curso" labelField="@label" width="260" height="140" showRoot="true" x="10" y="10" selectedIndex="0">
                <mx:XMLListCollection id="mycursoselector">
                    <mx:XMLList>
                        <folder label="Batxillerat" selected="true">
                         <folder label="Primer curs">
                          <folder id="1BHLetras" label="Humanistic de lletres" />
                          <folder id="1BHEco" label="Humanistic d'economia" />
                          <folder id="1BCN" label="Científic" />
                          <folder id="1BT" label="Tecnològic" />
                         </folder>
                         <folder label="Segon curs">
                          <folder id="2BHLetras" label="Humanistic de lletres" />
                          <folder id="2BHEco" label="Humanistic d'economia" />
                          <folder id="2BCN" label="Científic" />
                          <folder id="2BT" label="Tecnològic" />
                         </folder>
                        </folder>
                        <folder label="CFGM">
                         <folder label="Primer curs">
                          <folder id="Curas" label="Cures auxiliars d'infermeria" />
                         </folder>
                        </folder>
                        <folder label="CFGS">
                         <folder label="Primer curs">
                          <folder id="1Admin" label="Administració i finances" />
                          <folder id="1Infantil" label="Educació infantil" />
                          <folder id="1Lab" label="Laboratori de Diagnòstic Clínic" />
                         </folder>
                         <folder label="Segon curs">
                          <folder id="2Admin" label="Administració i finances" />
                          <folder id="2Infantil" label="Educació infantil" />
                          <folder id="2Lab" label="Laboratori de Diagnòstic Clínic" />
                         </folder>
                        </folder>
                    </mx:XMLList>
                </mx:XMLListCollection>
                </mx:Tree>
         </mx:Panel>
         <mx:Button x="184.5" y="472" label="Enviar el formulari" click="submitLogin(event);" id="envia"/>
         <mx:Button x="323.5" y="472" label="Borrar el formulari" id="borrar"/>
      </mx:Panel>
    </mx:Form>
</mx:Application>


El cual aparentemente es correcto. El problema me surge cuando intento enviar el formulario, no es que tenga algun error, es que simplemente no tengo ni la menor idea de como hacerlo.

El flash usaria loadVars, o algo así, pero como envio con AS 3.0 un conjunto de variables por POST¿? a mi archivo PHP¿?

He leido en la ayuda algo sobre los URLRequest, etc...

ActionScript 3.0 has replaced the LoadVars class with URLLoader and URLVariables classes. The URLLoader class downloads data from a URL as text, binary data, or URL-encoded variables. The URLLoader class is useful for downloading text files, XML, or other information to use in dynamic, data-driven ActionScript applications. The URLLoader class takes advantage of the ActionScript 3.0 advanced event handling model, which allows you to listen for such events as complete, httpStatus, ioError, open, progress, and securityError. The new event handling model is a significant improvement over the ActionScript 2.0 support for the LoadVars.onData, LoadVars.onHTTPStatus, and LoadVars.onLoad event handlers because it allows you to handle errors and events more efficiently. For more information on handling events, see Event Handling.

Much like the XML and LoadVars classes in earlier versions of ActionScript, the data of the URLLoader URL is not available until the download has completed. You can monitor the progress of the download (bytes loaded and bytes total) by listening for the flash.events.ProgressEvent.PROGRESS event to be dispatched, although if a file loads too quickly a ProgressEvent.PROGRESS event may not be dispatched. When a file has successfully downloaded, the flash.events.Event.COMPLETE event will be dispatched. The loaded data is decoded from UTF-8 or UTF-16 encoding into a string.


E incluso este código:

Código :

var secondsUTC:Number = new Date().time;
var dataXML:XML = <login><time>{secondsUTC}</time><username>Ernie</username><password>guru</password></login>;
var request:URLRequest = new URLRequest("http://www.yourdomain.com/login.cfm");
request.contentType = "text/xml";
request.data = dataXML.toXMLString();
request.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
try {
    loader.load(request);
} catch (error:ArgumentError) {
    trace("An ArgumentError has occurred.");
} catch (error:SecurityError) {
    trace("A SecurityError has occurred.");
}



Pero, si os soy sincero no entiendo nada de nada, y no por el idiona.... :(

Espero que me podais ayudar!!

Saludos,

Netcyberas

Por netcyberas

25 de clabLevel



Genero:Masculino  

[ Barcelona | Spain ]

firefox
Citar            
MensajeEscrito el 30 Dic 2006 02:29 am
Utiliza RemoteObject con WebOrb
http://www.cristalab.com/tutoriales/204/tutorial-de-flex-2-con-weborb-php-y-acceso-a-base-de-datos

saludos

Por Maikel

BOFH

5575 de clabLevel

22 tutoriales
5 articulos

Genero:Masculino   Team Cristalab

Claber de baja indefinida

firefox
Citar            
MensajeEscrito el 30 Dic 2006 10:11 am
Gracias Maikel, lo probaré esta tarde y ya postearé que tal me ha ido!!

Por netcyberas

25 de clabLevel



Genero:Masculino  

[ Barcelona | Spain ]

firefox

 

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