Hi,
I’m doing a navigation system in which two panels are deployed from the left of the main window (1024x768) of the application. The first panel shows the Sections and clicking on each Section item in this panel, the subsections appear in the second panel. The second panel folds out from underneath the first one and from the left. For each Section item, there are different subsection entries.
So far I’ve gotten that the Section items from the XML file appear in the first panel, and if I write by hand the xml “path” in my ActionScript file, the list of subsection entries appear in the second panel.
What I’m trying to do is that the subsection items appear when the user clicks in any Section item. I guess it’s best to use variables, but I’m not sure if there are any commands in ActionScript you can do that function. I’m totally new to programming in ActionScript.
I attach the application code as I have it now for you to understand better what I mean. I also attach a fragment of the XML file for you to see the structure of this file.
I would greatly appreciate if any of you could give me a help on this.
package
{
import flash.events.*;
import flash.net.*;
import flash.text.*;
import flash.display.MovieClip;
import gs.TweenLite;
public class Interfaz4 extends MovieClip
{
var campoTextoCortina:TextField;
var txtFormatCortina:TextFormat;
var campoTextoVisillo:TextField;
var txtFormatVisillo:TextFormat;
var visillo1:visillo = new visillo();
var cortina1:cortina = new cortina();
var subapartado:String;
public function Interfaz4 ()
{
visillo1.x = -230;
addChild (visillo1);
visillo1.addEventListener (MouseEvent.MOUSE_DOWN, clickHandler2, false, 0, true);
cortina1.x = -230;
addChild (cortina1);
cortina1.addEventListener (MouseEvent.MOUSE_DOWN, clickHandler1, false, 0, true);
var xmlURL:URLRequest = new URLRequest("sumario.xml");
var xmlLoader:URLLoader = new URLLoader(xmlURL);
xmlLoader.addEventListener (Event.COMPLETE, xmlLoaded);
function xmlLoaded (event:Event)
{
var dataXML = XML(event.target.data);
for (var i:uint = 0; i < dataXML.APARTADO.length(); i++)
{
var campoTextoCortina:TextField = new TextField();
var txtFormatCortina:TextFormat = new TextFormat();
txtFormatCortina.font = "Arial";
txtFormatCortina.color = 0x000099;
txtFormatCortina.size = 14;
txtFormatCortina.leading = 8;
txtFormatCortina.leftMargin = 15;
campoTextoCortina.defaultTextFormat = txtFormatCortina;
campoTextoCortina.x = 20;
campoTextoCortina.y = 30 * i + 40;
campoTextoCortina.width = 200;
campoTextoCortina.height = 24;
campoTextoCortina.background = true;
campoTextoCortina.backgroundColor = 0xCC9900;
campoTextoCortina.multiline = true;
campoTextoCortina.name = "APARTADO" + *;
campoTextoCortina.wordWrap = true;
campoTextoCortina.selectable = false;
cortina1.addChild (campoTextoCortina);
campoTextoCortina.text = dataXML.APARTADO.text()*;
campoTextoCortina.addEventListener (MouseEvent.MOUSE_OVER, onMouseOver1);
campoTextoCortina.addEventListener (MouseEvent.MOUSE_OUT, onMouseOut1);
campoTextoCortina.addEventListener (MouseEvent.MOUSE_DOWN, onMouseClick);
campoTextoCortina.addEventListener (MouseEvent.MOUSE_UP, onMouseDeClick);
}
}
}
function clickHandler1 (event:MouseEvent):void
{
if (event.eventPhase == EventPhase.AT_TARGET)
{
if (cortina1.x == 0)
{
TweenLite.to (cortina1, 1.2, {x:-230});
TweenLite.to (visillo1, 1.2, {x:-210});
}
else
{
TweenLite.to (cortina1, 1.2, {x:0});
TweenLite.to (visillo1, 1.2, {x:25});
}
}
}
function clickHandler2 (event:MouseEvent):void
{
if (event.eventPhase == EventPhase.AT_TARGET)
{
if (visillo1.x == -210)
{
TweenLite.to (cortina1, 1.2, {x:0});
TweenLite.to (visillo1, 1.2, {x:250});
}
else if (visillo1.x == 25)
{
TweenLite.to (cortina1, 1.2, {x:0});
TweenLite.to (visillo1, 1.2, {x:250});
}
else
{
TweenLite.to (cortina1, 1.2, {x:0});
TweenLite.to (visillo1, 1.2, {x:25});
}
}
}
function onMouseOver1 (event:MouseEvent):void
{
event.target.backgroundColor = 0xCC6600;
}
function onMouseOut1 (event:MouseEvent):void
{
event.target.backgroundColor = 0xCC9900;
}
function onMouseOver2 (event:MouseEvent):void
{
event.target.backgroundColor = 0xCC9900;
}
function onMouseOut2 (event:MouseEvent):void
{
event.target.backgroundColor = 0xCC6600;
}
function onMouseClick (event:MouseEvent):void
{
subapartado = event.target.name;
var xmlURL:URLRequest = new URLRequest("sumario.xml");
var xmlLoader:URLLoader = new URLLoader(xmlURL);
xmlLoader.addEventListener (Event.COMPLETE, xmlLoaded);
function xmlLoaded (event:Event)
{
var dataXML = XML(event.target.data);
for (var j:uint = 0; j < dataXML.APARTADO.APARTADO1.length(); j++)
{
var campoTextoVisillo:TextField = new TextField();
var txtFormatVisillo:TextFormat = new TextFormat();
txtFormatVisillo.font = "Arial";
txtFormatVisillo.color = 0x000099;
txtFormatVisillo.size = 14;
txtFormatVisillo.leading = 8;
txtFormatVisillo.leftMargin = 15;
campoTextoVisillo.defaultTextFormat = txtFormatVisillo;
campoTextoVisillo.x = 20;
campoTextoVisillo.y = 30 * j + 40;
campoTextoVisillo.width = 200;
campoTextoVisillo.height = 24;
campoTextoVisillo.background = true;
campoTextoVisillo.backgroundColor = 0xCC6600;
campoTextoVisillo.multiline = true;
campoTextoVisillo.wordWrap = true;
campoTextoVisillo.selectable = false;
campoTextoVisillo.name = "subapartado" + [j];
visillo1.addChild (campoTextoVisillo);
campoTextoVisillo.text = dataXML.APARTADO.APARTADO1.text()[j];
campoTextoVisillo.addEventListener (MouseEvent.MOUSE_OVER, onMouseOver2);
campoTextoVisillo.addEventListener (MouseEvent.MOUSE_OUT, onMouseOut2);
//campoTextoVisillo.addEventListener (MouseEvent.MOUSE_DOWN, onMouseClick);
//campoTextoVisillo.addEventListener (MouseEvent.MOUSE_UP, onMouseDeClick);
}
trace ("data ", dataXML.APARTADO.APARTADO1);
}
}
function onMouseDeClick (event:MouseEvent):void
{
event.target.x = 20;
}
}
}
This is the line of code I write by hand on the second for to populate the second panel. And it works:
dataXML.APARTADO.APARTADO1.length(); j++)
I think I need to substitute the APARTADO1 for a variable in function of theuser click on the Section items.
This is a fragment of the XML file:
<?xml version="1.0" encoding="utf-8"?>
<SUMARIO>
<APARTADO TITULO="Inicio y configuración">Inicio y configuración
<APARTADO0>Iniciar AutoCAD 2011 (Pantalla de bienvenida)</APARTADO0>
<APARTADO0>Conocer la interfaz de AutoCAD 2011</APARTADO0>
<APARTADO0>Espacios de trabajo</APARTADO0>
<APARTADO0>Crear, abrir y configurar documentos</APARTADO0>
</APARTADO>
<APARTADO TITULO="Empezar a dibujar">Empezar a dibujar
<APARTADO1>Conocer el sistema de coordenadas</APARTADO1>
<APARTADO1>Trabajar con coordenadas relativas y polares</APARTADO1>
<APARTADO1>Dibujar combinando distintos tipos de coordenadas</APARTADO1>
<APARTADO1>Trazar líneas con el ratón</APARTADO1>
<APARTADO1>Crear rectángulos</APARTADO1>
<APARTADO1>Dibujar círculos y círculos concéntricos</APARTADO1>
<APARTADO1>Crear formas con la herramienta Polígono</APARTADO1>
<APARTADO1>Arcos y polilíneas</APARTADO1>
<APARTADO1>Trabajar con líneas spline</APARTADO1>
</APARTADO>
<APARTADO TITULO="Modificación de dibujos">Modificación de dibujos
<APARTADO2>Las herramientas de modificación Desfase y Empalme</APARTADO2>
<APARTADO2>Estirar y partir objetos</APARTADO2>
<APARTADO2>Suprimir y escalar objetos</APARTADO2>
<APARTADO2>Girar objetos</APARTADO2>
<APARTADO2>Mover y copiar objetos</APARTADO2>
<APARTADO2>Realizar copias con punto base</APARTADO2>
<APARTADO2>Creación de simetrías</APARTADO2>
<APARTADO2>Rellenar figuras con colores sólidos</APARTADO2>
<APARTADO2>Aplicar patrones de sombreados</APARTADO2>
<APARTADO2>Personalizar patrones de sombreado</APARTADO2>
<APARTADO2>La nueva herramienta de transparencia</APARTADO2>
<APARTADO2>Trabajar con degradados</APARTADO2>
<APARTADO2>Herencia de propiedades</APARTADO2>
</APARTADO>
</SUMARIO>
Thank you very much for your attention.