Estoy intentando hacer un pequeño editor de texto, y el primer paso que quiero conseguir es que guarde el tamaño del texto en un nodo llamado "size" de un xml llamado "datos.xml" para que al cargar el texto lo muestre con ese tamaño.
Lo que me ocurre hasta ahora es que cuando interviene el php lo que hace es borrar todo el contenido del archivo datos.xml y como mis conocimientos son tan limitados no sé si es por el flash, por el php, o por ambos...
Os presento todo el código:
Código ActionScript :
import fl.text.TLFTextField; import fl.controls.UIScrollBar; //Creo campo de texto y formato var t:TLFTextField = new TLFTextField(); var tf:TextFormat = new TextFormat(); t.width = stage.stageWidth; t.height = stage.stageHeight; t.background = true; t.paddingTop = 20; t.paddingLeft = 20; t.paddingRight = 20; t.selectable=true; addChild(t); //Cargo Xml y lo muestro en el campo de texto var textLoad:URLLoader = new URLLoader(); textLoad.addEventListener(Event.COMPLETE, textLoaded); textLoad.load(new URLRequest("datos.xml")); function textLoaded(e:Event):void { var Xml=new XML(textLoad.data); t.htmlText = Xml.inicio.texto; tf.color = Xml.inicio.color; tf.font = Xml.inicio.font; tf.size = Xml.inicio.size; t.setTextFormat(tf); } //-------------Caja de edición de formatos var formatClip:Formatter = new Formatter(); var showFormat:Boolean = true; stage.addEventListener(KeyboardEvent.KEY_DOWN, showFormatter); function showFormatter(e:KeyboardEvent):void { if (e.keyCode == 70) { if (showFormat) { addChild(formatClip); formatClip.guardar.addEventListener(MouseEvent.CLICK, guardarXml); formatClip.addEventListener(MouseEvent.MOUSE_DOWN, drag); showFormat = false; } else { formatClip.removeEventListener(MouseEvent.MOUSE_DOWN, drag); removeChild(formatClip); showFormat = true; } } } function drag(e:Event):void { formatClip.startDrag(); formatClip.addEventListener(MouseEvent.MOUSE_UP, noDrag); } function noDrag(e:Event):void { formatClip.stopDrag(); } formatClip.fontSizer.addEventListener(Event.CHANGE, setFontSize); function setFontSize(e:Event):void { tf.size = e.target.value; t.setTextFormat(tf); } //grabar en XML (AQUÍ ESTÁ LO CHUNGO PORQUE NO TENGO NI IDEA...) function guardarXml(MouseEvent):void{ var tamaño:String=new String(tf.size); //Proceso de grabación con el PHP Esto ha sido copiar/pegar porque no lo entiendo. var miGrabador:URLRequest = new URLRequest("save.php"); miGrabador.method = URLRequestMethod.POST; miGrabador.contentType = "text/xml"; miGrabador.data = tamaño; var loader:URLLoader = new URLLoader(); loader.dataFormat = URLLoaderDataFormat.VARIABLES; loader.load(miGrabador); } // Creo que falta alguna variable tipo "loadVars", no sé... //Esto no sé ni para qué es... try { } catch (err:TypeError) { t.text = "An error occured when communicating with server:\n" + err.message; }
A continuación os pongo el PHP sacado de este foro y cuyo contenido es chino para mí.
Código PHP :
<?php $archivo = "datos.xml"; $texto = get_magic_quotes_gpc() ? stripslashes($_POST['tamaño']) : $_POST['tamaño']; file_put_contents($archivo, $size); // if PHP5 echo "estado=ok"; ?>
Muchas gracias de antemano chicos.
