Tengo una aplicación que muestra los resultados de la BBDD, mediante AMFphp (cortesía de Jorge Solís ). Seleccionas la familia y te saca los productos en el scrollPane.
Quiero cambiar este scrollPane por un sistema de paginación, de modo que muestra por ejemplo los 5 primeros resultados y con un botón de siguiente y anterior para que vaya mostrando los siguientes.
--
Podéis ver la aplicación en la siguiente web
http://sorrymama.freehostia.com/
--
Posteo también el código
Código :
import mx.remoting.Service;
import mx.services.Log;
import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;
import mx.remoting.PendingCall;
import mx.remoting.debug.NetDebug;
//Initialize a Logger
mx.remoting.debug.NetDebug.initialize(); // initialize the NCD
var myLogger:Log = new Log( Log.DEBUG, "logger1" );
// override the default log handler
myLogger.onLog = function( message:String ):Void {
// trace( "myLogger-->>>"+message );
}
//IMPORTANT -> Change to the proper path
_global.svc = new Service(
/*"path to gateway.php",*/
"http://sorrymama.freehostia.com/gateway.php",
myLogger,
"shopping",
null,
null);
var pc:PendingCall = svc.getFamily(); //default method: show promotions
pc.responder = new RelayResponder(this, "getFamily_Result", "onError" );
z=0
//Hide the loading movie
sending_lc = new LocalConnection();
sending_lc.send("lc_name", "dissapear")
//The combobox is waiting for data
catList.addItem("Cargando...")
//disabled interface elements
enableInterface(false)
////////////////////////
// Catalog handlers //
////////////////////////
//Generic error handler
function onError(rs: FaultEvent){
mx.remoting.debug.NetDebug.trace({level:"None", message:"There was a problem: " + fault.fault.faultstring });
}
//Receive current category
getFamily_Result = function(re: ResultEvent){
var rs = re.result
//disable user interaction
enableInterface(true)
cant = rs.length
catList.removeAll()
//Pass to the combobox
for(var i=0; i<cant; i++)
catList.addItem(rs.getItemAt(i).Name, rs.getItemAt(i).PkFamily)
var pc: mx.remoting.PendingCall = svc.getProducts(1);
pc.responder = new RelayResponder(this, "getProducts_Result", "onError" );
//Main title
Title.text = rs.getItemAt(0).Name
pane.contentPath = "fotos"
}
getProducts_Result = function(re: ResultEvent){
var rs = re.result
//Clean the holder
for(i in pane.content) pane.content[i].removeMovieClip()
pane.hScrollPolicy = "on"
cant = rs.length
z = 0
//loop trough rows to load into pane
for(var i=0; i<cant; i++){
/*p = pane.content.attachMovie("holder", "holder"+(z++), z, {_x:12+(150*int(z/4)), _y:(150*(z%4))+5})*/
//set Pane content
p = pane.content.attachMovie("holder", "holder"+(z++), z, {_x:45+(150*int(z/122)), _y:(150*(z%122))+15})
//Textfield showing details
p.createTextField("datos", 2, -20, 105, 120, 40)
p.datos.multiline = true
p.datos.html = true
var txt = addBreak(rs.getItemAt(i).Name, 20)
p.datos.htmlText = "<p align=\"center\">"+txt+"<p>"
//external and internal holder where the image will be loaded
p.createEmptyMovieClip("foto"+i, 1)
p["foto"+i].createEmptyMovieClip("holder", 1)
//load the timage
p["foto"+i].holder.loadMovie("products/pics/"+rs.getItemAt(i).Image)
p["foto"+i].datos = rs.getItemAt(i)
//set the onPress handler
p["foto"+i].onPress = function(){
//que al pinchar parezca la ventana
ventana1._visible = true;
var target = this._parent._parent._parent._parent.ventana1.details
target.datos = this.datos //Copy data
target.holder.loadMovie("products/photos/"+this.datos.Image)
target.title.text = this.datos.Name
target.details.htmlText = "<b>Modelo:</b> "+this.datos.Content+"<br><b>Peso:</b> "+this.datos.Weigth+"<br><b>Precio:</b> "+this.datos.Price
target.cant.value = 1
}
//force scrollpane to show scrollBar with the new content
pane.vScrollPolicy = "on";
}
//Default content of the "Details window"
ventana1.details.holder.loadMovie("products/photos/"+rs.getItemAt(0).Image);
ventana1.details.title.text = rs.getItemAt(0).Name
ventana1.details.details.htmlText = "<b>Modelo:</b> "+rs.getItemAt(0).Content+"<br><b>Peso:</b> "+rs.getItemAt(0).Weigth+"<br><b>Precio:</b> "+rs.getItemAt(0).Price
ventana1.details.datos = rs.getItemAt(0)
}
//Esto es lo que hace que se refresque el contenido al cambiar de categoria
catChoice = {}
catChoice.ref = this
catChoice.change = function(evt){
var pc:PendingCall = svc.getProducts(evt.target.selectedItem.data)
pc.responder = new RelayResponder(this.ref, "getProducts_Result", "onError" );
Title.text = evt.target.selectedItem.label
}
catList.addEventListener("change", catChoice)
//Esto hace referencia a nombre de los productos que saca el scrollPane
function addBreak(texto, ancho){
texto += " ";
var temp = "", first = 0;
var linea = ancho;
while(temp.length<texto.length){
while (texto.charAt(linea)!=" ") linea--;
temp += texto.substring(first, linea)+"<br>";
first = linea+1;
linea += ancho
}
return temp;
}
stop()
Bueno a ver si alguín me echa una mano con esto.
Un saludo.
