Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/02/2010, 11:51
AnakinX
 
Fecha de Ingreso: marzo-2009
Mensajes: 4
Antigüedad: 15 años, 1 mes
Puntos: 0
Novato en Flash B 4 - Cargar datos en un control List

Hola, soy un inexperto todavía en el tema de Flex. Estoy desarrollando una pequeña aplicación que me sirva de aprendizaje y me encuentro con el siguiente problema:

Se trata de cargar en un control List los datos de los campos de un registro que existe en una tabla de MySQL pero con un componente 'RepeatedItem'. La aplicación la he ido creando desde Photoshop, pasando por Catalyst y terminando finalmente en Flash Builder 4. Todo bien hasta que quiero cargar los datos. Si pongo otro control List en el Main.mxml funciona bien pero necesito que sea mediante el 'RepeatedItem'. Uso servicios PHP pero no consigo manejar correctamente, creo, la propiedad 'lastResult' para poder ir cargándolos. No se si me explico correctamente, os adjunto código:

Mi Main.mxml es:

<?xml version='1.0' encoding='UTF-8'?>
<s:Application
xmlns:ATE="http://ns.adobe.com/ate/2009"
xmlns:ai="http://ns.adobe.com/ai/2009"
xmlns:fc="http://ns.adobe.com/flashcatalyst/2009"
xmlns:lib="assets.graphics.MHoroscopo.*"
xmlns:d="http://ns.adobe.com/fxg/2008/dt"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:flm="http://ns.adobe.com/flame/2008" height="600" width="800" backgroundColor="#ffffff" preloaderBaseColor="#ffffff" xmlns:abmdatos="services.abmdatos.*">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.controls.Alert;
protected function textInput_enterHandler():void
{
const state:String = currentState;
if ( state == 'expandido' ) {
currentState='verHoroscopo';
}
}


protected function button_clickHandler():void
{
const state:String = currentState;
if ( state == 'expandido' ) {
currentState='cerrado';
}
if ( state == 'cerrado' ) {
currentState='expandido';
}
}

protected function button_clickHandler_3():void
{
currentState='expandido';
}


protected function button_clickHandler_4():void
{
currentState='expandido';
}


protected function button_clickHandler_1():void
{
currentState='expandido';
}


protected function list_creationCompleteHandler(event:FlexEvent):void
{
getAllItemsResult.token = aBMDatos.getAllItems();
}

]]>

</fx:Script>
<s:states>
<s:State name="expandido" fc:color="0xcc0000"/>
<s:State name="cerrado" fc:color="0x0081cc"/>
<s:State name="verHoroscopo"/>
</s:states>
<fx:Declarations>
<s:CallResponder id="getAllItemsResult"/>
<abmdatos:ABMDatos id="aBMDatos" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
</fx:Declarations>
<fx:DesignLayer d:id="2" ai:objID="391d9e00" d:userLabel="Capa 1">
<s:Rect height="62" ai:objID="3917a180" width="650" x="80.5" y="35.5" y.cerrado="96.5" id="rect1">
<s:fill>
<s:SolidColor color="0xCCCCCC"/>
</s:fill>
<s:stroke>
<s:SolidColorStroke caps="none" color="0x808080" joints="miter" miterLimit="4" scaleMode="normal" weight="1"/>
</s:stroke>
</s:Rect>
<s:Button skinClass="components.Button1" x="80" y="18" y.cerrado="79" id="button1" d:userLabel="Button" click="button_clickHandler()"/>
<s:RichText color="0x000000" fontFamily="Myriad Pro" d:id="6" kerning="on" lineHeight="120%" ai:objID="391d6900" whiteSpaceCollapse="preserve" x="145" y="55" d:userLabel="Introducir día y mes en formato (ddmm):" width="386" height="22" fontSize="20" visible.cerrado="false" id="richtext1" visible.verHoroscopo="false">
<s:content><s:p d:id="7" whiteSpaceCollapse="collapse"><s:span d:id="8">Introducir día y mes en formato (ddmm):</s:span></s:p></s:content>
</s:RichText>
<s:TextInput skinClass="components.TextInput1" text="" x="536" y="54" visible.cerrado="false" id="textinput1" visible.verHoroscopo="false" enter="textInput_enterHandler()"/>
<s:List skinClass="components.DataList1" x="80" y="97" id="list" creationComplete="list_creationCompleteHandler(eve nt)" dataProvider="{getAllItemsResult.lastResult}">
</s:List>
<s:RichText includeIn="verHoroscopo" x="127" y="60" color="#2b4381" fontFamily="Arial" fontSize="12" tabStops="S0 S50 S100 S150" text="Horóscopo del día: " id="richtext2"/>
<s:RichText includeIn="verHoroscopo" x="244" y="57" color="#2b4381" fontFamily="Arial" fontSize="18" tabStops="S0 S50 S100" text="DIA, MES Y AÑO" id="richtext3" width="202" height="18"/>
<s:Button skinClass="components.Button4" label=" GRABAR" x="114" y="565" id="button3" includeIn="verHoroscopo" click="button_clickHandler_3()"/>
<s:Button skinClass="components.Button4" label=" CANCELAR" x="603" y="565" id="button4" includeIn="verHoroscopo" click="button_clickHandler_4()"/>
<s:Button skinClass="components.Button4" label=" BORRAR" x="348" y="565" id="button0" includeIn="verHoroscopo" click="button_clickHandler_1()"/>
</fx:DesignLayer>

.......

<?php

class ABMDatos {

private $connection;

public function __construct() {
$this->connection = mysqli_connect("127.0.0.1", "root", "", "horoscopos") or die(mysqli_connect_error());
}

public function getAllItems() {
$sql = "SELECT * FROM horoscopo";
$result = mysqli_query($this->connection, $sql) or die('SQL Error (TSC)): ' . mysqli_error($this->connection));

$rows = array();
while ($row = mysqli_fetch_array($result)) {
//$rows[] = $row;
$rows[] = utf8_encode($row["CAPRICORNIO"]);
$rows[] = utf8_encode($row["ACUARIO"]);
$rows[] = utf8_encode($row["PISCIS"]);
$rows[] = utf8_encode($row["ARIES"]);
$rows[] = utf8_encode($row["TAURO"]);
$rows[] = utf8_encode($row["GEMINIS"]);
$rows[] = utf8_encode($row["CANCER"]);
$rows[] = utf8_encode($row["LEO"]);
$rows[] = utf8_encode($row["VIRGO"]);
$rows[] = utf8_encode($row["LIBRA"]);
$rows[] = utf8_encode($row["ESCORPIO"]);
$rows[] = utf8_encode($row["SAGITARIO"]);

}

mysqli_free_result($result);
mysqli_close($this->connection);

return $rows;
}
?>
---------------------------------------------------------------------------- y por último el RepeatedItem1.mxml: <?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:d="http://ns.adobe.com/fxg/2008/dt"
xmlns:ai="http://ns.adobe.com/ai/2009"
xmlns:mx="library://ns.adobe.com/flex/halo">
<s:states>
<s:State name="normal"/>
<s:State name="hovered"/>
<s:State name="selected"/>
</s:states>
<s:Rect d:userLabel="Item Highlight" width="611" height="118" alpha.normal="0" alpha.hovered="0.4" alpha.selected="0.8" id="rect1">
<s:fill>
<s:SolidColor color="0xCED7EE" color.hovered="#8fce9c"/>
</s:fill>
</s:Rect>
<s:RichText color="0x000000" fontFamily="Myriad Pro Light" d:id="9" kerning="on" lineHeight="120%" ai:objID="391d6800" whiteSpaceCollapse="preserve" x="2" y="0" d:userLabel="CAPRICORNIO" fontWeight="bold" text="{data.text1}" blendMode.normal="normal">
</s:RichText>
<s:RichText color="0x000000" fontFamily="Myriad Pro" height="102" d:id="12" kerning="on" lineHeight="120%" ai:objID="391d6700" whiteSpaceCollapse="preserve" width="532" x="79" y="16" d:userLabel="Es una prueba de texto" text="{}" blendMode.normal="normal">
</s:RichText>
<mx:Image ai:objID="391c1b00" source="{data.image1}" x="0" y="15" maintainAspectRatio="false" blendMode.normal="normal"/>
<s:transitions>
<s:Transition fromState="normal" toState="hovered" autoReverse="true">
<s:Parallel>
<s:Parallel target="{rect1}">
<s:Fade duration="0"/>
</s:Parallel>
</s:Parallel>
</s:Transition>
</s:transitions>
</s:ItemRenderer>

Los valores deben cargarse mediante los controles RichText d:id="12" y "9" del RepeatedItem pero no sé qué poner para que los tome.

Os quedaría infinitamente agradecidos por vuestra ayuda.

Gracias anticipadas.

Última edición por AnakinX; 15/02/2010 a las 11:58