Regresar   Foros del Web > Diseño de Sitios web > Flash y Actionscript > Flex

El registro es Gratis en Foros del Web
Respuesta
 
Herramientas Buscar en Tema Desplegado
Antiguo 02/05/08, 09:13:25   #1 (permalink)
raikkonen83 ha deshabilitado el Karma
 
Registrado: ago 2007
Mensajes: 19
raikkonen83 is offline  
Donde pongo mi xml?

hola a todos

estoy intentando recoger información de un fichero xml con flex para que me lo muestre en un datagrid por ejemplo.

He conseguido despues de muchas horas de busqueda encontrar un ejemplo que hace esto pero de una manera poco practica ya que el xml esta incluido en el mxml.

aqui os adjunto el codigo:



Código:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    width="500" height="470"
    creationComplete="myDataGrid.selectedIndex=0;"
>

    <mx:Script>
        <![CDATA[        
            // Model: XML structure describing 
            // some of the books in my collection.    
            [Bindable]

            private var myBooks:XML = 
                <books>
                    <book ISBN="1590595181">

                        <title>Foundation ActionScript Animation: Making Things Move</title>
                        <author>Keith Peters</author>
                        <amazonUrl>http://tinyurl.com/npuxt</amazonUrl>

                    </book>
                    <book ISBN="1582346194">
                        <title>Send in the Idiots: Stories from the Other Side of Autism</title>

                        <author>Kamran Nazeer</author>
                        <amazonUrl>http://tinyurl.com/lo5ts</amazonUrl>
                    </book>
              ]]>
    </mx:Script>
    
    <!-- Keep track of the currently selected book -->
    <mx:Number id="selectedBookIndex">{myDataGrid.selectedIndex}</mx:Number>

    
    <!-- User interface -->
    <mx:Panel 
        title="Assigning XML data"
        paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"
    >

        <!-- Master view: Display all books -->
        <mx:DataGrid id="myDataGrid" dataProvider="{myBooks.book}">

            <mx:columns>
                <mx:DataGridColumn dataField="@ISBN" headerText="ISBN" width="85"/>
                <mx:DataGridColumn dataField="title" headerText="Title"/>

                <mx:DataGridColumn dataField="author" headerText="Author"/>
                <mx:DataGridColumn dataField="amazonUrl" headerText="Web site">

                    <mx:itemRenderer>
                        <mx:Component>
                            <mx:LinkButton
                                label="Visit"
                                click="navigateToURL(new URLRequest(data.amazonUrl), 'blank');"
                            />                                    
                        </mx:Component>

                    </mx:itemRenderer>                        
                </mx:DataGridColumn>
            </mx:columns>
        </mx:DataGrid>
        
        <!-- Detail view: Display currently selected book for editing -->

        <mx:Form width="100%" autoLayout="false">
            <mx:FormHeading label="Edit book details"/>

            <mx:FormItem label="ISBN:" width="100%">
                <mx:TextInput 
                    id="isbnInput" 
                    width="100%"
                    text="{myBooks.book[selectedBookIndex].@ISBN}"
                    change="{myBooks.book[selectedBookIndex].@ISBN = isbnInput.text}"
                />

            </mx:FormItem>
            <mx:FormItem label="Title:" width="
			100%">
                <mx:TextInput 
                    id="titleInput" 
                    width="100%"
                    text="{myBooks.book[selectedBookIndex].title}"
                    change="{myBooks.book[selectedBookIndex].title = titleInput.text}"
                />

            </mx:FormItem>
            <mx:FormItem label="Author:" width="100%">
                <mx:TextInput 
                    id="authorInput"
                    width="100%"
                    text="{myBooks.book[selectedBookIndex].author}"
                    change="{myBooks.book[selectedBookIndex].author = authorInput.text}"
                />

            </mx:FormItem>
            <mx:FormItem label="Amazon Url" width="100%">
                <mx:TextInput 
                    id="amazonUrlInput"
                    width="100%"
                    text="{myBooks.book[selectedBookIndex].amazonUrl}"
                    change="{myBooks.book[selectedBookIndex].amazonUrl = amazonUrlInput.text}"
                />

            </mx:FormItem>        
        </mx:Form>
    </mx:Panel>
</mx:Application>

Estoy desesperado porque no encuentro la manera de "importar" los datos de un fichero xml de manera externa.

Es decir, trabajando en local donde pongo mi fichero xml???
Qué he de modificar en el código para que lo importe????


Gracias por la ayuda y perdon por las molestias
  Responder Con Cita
Antiguo 02/05/08, 13:11:07   #2 (permalink)
SinguerInc tiene un saldo positivo de karma
 
Registrado: oct 2007
Ubicación: Barcelona, España
Mensajes: 505
SinguerInc is offline  
Re: Donde pongo mi xml?

hola shumy, paso a explicarte, haz una function de este tipo:

Código:
private function cargaXML():void
{
var ur:URLRequest = new URLRequest("myXML.xml");
var ul:URLLoader = new URLLoader();
ul.addEventListener(Event.COMPLETE, onXMLComplete); //agregas un listener para saber cuando esta cargado el file
ul.load(ur); //cargas el file
}

private function onXMLComplete(event:Event):void
{
var unXML:XML = XML(event.target.data); //convierte los datos cargados en un XML
trace(unXML); //tu xml
}
en este caso tu xml debe encontrarse en el mismo lugar donde estas exportando tu swf, por lo general, flex, lo hace en una carpeta llamada BIN.

obviamente...recuerda llamar la funcion....
sa-lu-2
__________________
SinguerInc - Ningún derecho reservado / PanQueso (beta) by Nahuel Scotti
  Responder Con Cita
Antiguo 02/05/08, 16:06:37   #3 (permalink)
raikkonen83 ha deshabilitado el Karma
 
Registrado: ago 2007
Mensajes: 19
raikkonen83 is offline  
Re: Donde pongo mi xml?

Muchas gracias SinguerInc pero olvide decir que soy novato novato.

Como quedaría con el código que he puesto en el anterior post el codigo que dices que necesito?

Por cierto, estoy usando Flex Builder 3 y en la carpeta del proyecto estan las siguientes subcarpetas: .settings, bin-debug, html-template, libs y src. Donde deberia ponerlo??

Gracias y perdon por pedirlo todo tan claro pero es que no me sale :(
  Responder Con Cita
Antiguo 05/05/08, 12:35:33   #4 (permalink)
Sergestux no ha recibido karma de otros usuarios
 
Registrado: ago 2007
Ubicación: Tijuas
Mensajes: 260
Contactar con Sergestux a través de Yahoo
Sergestux is offline  
Re: Donde pongo mi xml?

Bueno que te te parece este otro ejemplo:

Codigo mxml
Código:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
        creationComplete="PlatillosXml.send();">
<mx:HTTPService id="PlatillosXml" url="http://localhost/Platillos.xml" showBusyCursor="true" resultFormat="e4x"/>    
    <mx:DataGrid x="10" y="10" dataProvider="{PlatillosXml.lastResult.Platillo}">
        <mx:columns>
            <mx:DataGridColumn headerText="Id" dataField="@id"/>
            <mx:DataGridColumn headerText="Platillo" dataField="@descripcion"/>
        </mx:columns>
    </mx:DataGrid>
</mx:Application>
Archivo xml Platillos.xml localizado en la carpeta raiz de tu servidor web, en mi caso C:\AppServ\www
Código:
<Platillos>
    <Platillo id="1" descripcion="Platillo Uno Texto de varias lineas"/>
    <Platillo id="2" descripcion="Platillo Dos Texto de varias lineas"/>
    <Platillo id="3" descripcion="Platillo Tres Texto de varias lineas"/>
</Platillos>
Por cierto ese archivo pudo (en mi caso asi es) haber sido generado por un archivo php, solo es cuestion de programar el codigo php para que te genere el codigo xml que deseas
__________________
You'll be free, hackers, you'll be free
  Responder Con Cita
Respuesta


Califica este Tema - Donde pongo mi xml?.

Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado Califica este Tema
Califica este Tema:

Reglas del foro
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está activado
Las caritas están activado
Código [IMG] está activado
Código HTML está desactivado


Todas las horas son GMT -6. La hora es 00:22:21.

Message Board Statistics

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96