elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


+  Foro de elhacker.net
|-+  Media
| |-+  Diseño Gráfico
| | |-+  Creacion dinamica de botones (FLASH)
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Creacion dinamica de botones (FLASH)  (Leído 2,898 veces)
DownRate

Desconectado Desconectado

Mensajes: 44



Ver Perfil
Creacion dinamica de botones (FLASH)
« en: 24 Julio 2006, 23:16 pm »

Hola que tal,

Estoy haciendo un script que lee un archivo xml y por cada nodo crea un boton con las caracteristicas de sus atributos.

Hasta ahorita el script crea los botones, pero no logro hacer que cada boton tenga un link a cierta pagina dependiendo del valor de su nodo...

el codigo es sencillo, solo es de pegarlo en un frame:
Código:
myxml = new XML();
myxml.load("file.xml");
myxml.ignoreWhite = true;
// posicion de los botones en _y:
var ypos = 10;
// nivel en que se cargan:
var ins = 0;

// se crea una pelicula madre:
var container:MovieClip = this.createEmptyMovieClip("container", this.getNextHighestDepth());
// funcion que corre al cargar el archivo xml:
myxml.onLoad = function() {
// for que recorre la cantidad de nodos del archivo xml:
for (n=0; n<this.firstChild.childNodes.length; n++) {
ins += 1;
ypos += 25;
// por cada nodo se crea un boton:
var boton_:MovieClip = container.createEmptyMovieClip("boton_"+n, ins);
// dentro de cada boton se crea un textfield:
var texto:TextField = boton_.createTextField("texto"+n, 1, 100, ypos, 100, 20);
// cata textfield tiene el valor del atributo "id" de cada nodo:
texto.text = this.firstChild.childNodes[n].attributes.id;
// Estilos visuales de cada textfield:
texto.background = true;
texto.backgroundColor = 0x000000;
texto.textColor = 0xFFFFFF;
}
};

y el archivo xml es el sig:
Código:
<?xml version="1.0" standalone="yes" encoding="utf-8" ?>
<lotes>
<lote nombre="lote00" id="0" estatus="1"/>
<lote nombre="lote01" id="1" estatus="1"/>
<lote nombre="lote02" id="2" estatus="3"/>
<lote nombre="lote03" id="3" estatus="4"/>
</lotes>

Espero me puedan ayudar, se los agradecere mucho.

Gracias y Saludos!


En línea

Revenge is a Dish Best Served Cold
DownRate

Desconectado Desconectado

Mensajes: 44



Ver Perfil
Re: Creacion dinamica de botones (FLASH)
« Respuesta #1 en: 25 Julio 2006, 18:28 pm »

Bueno, ya encontre la solucion, espero que a alguien mas le sirva.

creacion de botones dinamicos mediante un xml.

1)crea un movieclip en el escenario llamado "MyBtn", exportalo para actionscript con el mismo nombre de identificador; Dentro de el, crea un Textfield dinamico con nombre de instancia "buttonTitle_txt".

Suponiendo que este sea el archivo xml:
file.xml
Código:
<?xml version="1.0"?>
<root>   
    <item id="1" buttonTitle="1" buttonLink="http://www.flash-genie.de" xpos="362.6" ypos="447.6" ancho="21.6" alto="48.2"/>
    <item id="2" buttonTitle="2" buttonLink="http://www.flashmxfiles.com" xpos="344.1" ypos="447.6" ancho="18.4" alto="48.2" />
    <item id="3" buttonTitle="3" buttonLink="http://www.actionscript.org" xpos="325.2" ypos="447.6" ancho="18.8" alto="48.2" />
    <item id="4" buttonTitle="4" buttonLink="http://www.mambers.com" xpos="306.7" ypos="447.6" ancho="18.6" alto="48.2" />
</root>

Dentro del primer frame de la pelicula inserta el sig codigo:
Código:
//create a new XML object
myXML = new XML ();
//tell flash to ignore all the whitespace
//Ommiting this nearly always causes silly problems
myXML.ignoreWhite = true;
//when the xml has loaded
myXML.onLoad = function (success) {
//if we are successful, call our parse function (parseIt)
if (success) {
parseIt (this);
} else {
//Otherwise inform the user that an error has occured
//Probably our fault
trace ("Sorry, error loading XML files for the menu");
getURL ("javascript: alert('Sorry, error loading XML files!')");
}
};
//OK first bit done, its loaded (we will assume successfully..lets create objects from each bit now:
function parseIt (what) {
//Create an object for each "item"
_root.noOfKids = what.firstChild.childNodes.length;
//Note: We start at 0 with our loop
for (var i = 0; i < noOfKids; i++) {
_root["menuEntry" + i] = new Object ();
//Now we have them we need to create some properties of said items
//referring to the title and link of our button.
//The best way imo of doing this is to use attributes like such
_root["menuEntry" + i].buttonTitle = what.firstChild.childNodes[i].attributes["buttonTitle"];
_root["menuEntry" + i].buttonLink = what.firstChild.childNodes[i].attributes["buttonLink"];
_root["menuEntry" + i].xpos = what.firstChild.childNodes[i].attributes["xpos"];
_root["menuEntry" + i].ypos = what.firstChild.childNodes[i].attributes["ypos"];
_root["menuEntry" + i].ancho = what.firstChild.childNodes[i].attributes["ancho"];
_root["menuEntry" + i].alto = what.firstChild.childNodes[i].attributes["alto"];
//And thats it for that bit, normally we would attach our buttons and assign them their name and title here
//For ease of reading we will however call a function that does that like this:
assignBtnStuff ();
}
}
myXML.load ("file.xml");
/*
4)All thats left now is to make it all viewable by the user, we can check to see if all is good by using the debugger (Shift, ctrl + enter) after pressing the green arrow to commence we select _level0 and can see our objects under variables...All there? Good lets crack on, I'm getting hungry. As noted before we now need a function...so lets create one

*/
function assignBtnStuff () {
for (var i = 0; i < noOfKids; i++) {
_root.attachMovie("myBtn","XMLbtn"+i,i);
_root["XMLbtn" + i].buttonTitle_txt.text = _root["menuEntry" + i].buttonTitle;
//Lets position them vertically at 50px intervals starting at pixel 30
_root["XMLbtn" + i]._y = _root["menuEntry" + i].ypos;
_root["XMLbtn" + i]._x = _root["menuEntry" + i].xpos;
_root["XMLbtn" + i]._width = _root["menuEntry" + i].ancho;
_root["XMLbtn" + i]._height = _root["menuEntry" + i].alto;
//Our buttons need to link when pressed, to this end we need to make a note of their increment (i)
_root["XMLbtn" + i].incr = i;
_root["XMLbtn" + i].onRelease = function () {
//get _rootMenuEntry1 thru to the number of buttons we have...and check buttonLink
//which we assigned during parsing
getURL (_root["menuEntry" + this.incr].buttonLink, "_blank");
};
}
}

Y esto da como resultado diversos botones en el escenario, como veran desde el xml jala el ancho, alto, coordenadas en 'x' y 'y'. Esto es en caso de que sea necesario que cada boton sea diferente (como en mi caso).

Espero les sirva como ami...

Saludos!!!

Amed Rdz


En línea

Revenge is a Dish Best Served Cold
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Creación dinámica de jButtons/Buttons « 1 2 »
Java
NelxoN 11 14,344 Último mensaje 30 Abril 2013, 00:32 am
por JacobJankowski
Duda con Creación dinamica de PDF en entorno web JAVA con Itext
Desarrollo Web
h3ct0r 3 6,790 Último mensaje 22 Noviembre 2012, 02:12 am
por mikezero84
creacion y manipulacion dinamica de objetos
.NET (C#, VB.NET, ASP)
rulovive 7 3,806 Último mensaje 2 Febrero 2018, 11:56 am
por Tazmania40
Creación de tabla dinámica con ajax, javascript, php y mysql
Desarrollo Web
Connor2431 1 1,528 Último mensaje 19 Octubre 2018, 20:28 pm
por #!drvy
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines