views:

170

answers:

0

Hey im running into some trouble with as3, Im still learning the ropes but I need to get this done with so lets see what can be made about that.

What Im trying to accomplish is to parse a xml file and with the info from it put an image on teh stage that can be clicked to reveal a text under it.

Im using flash builder and this is what I got:

package
{
import classes.Elemento;

import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;


public class ProjectoExp extends Sprite
{
    public var listaElementos:Array=new Array();
    public function ProjectoExp()
    {
        //--------------------Carregar o XML
        var loader:URLLoader = new URLLoader(); 
        loader.addEventListener(Event.COMPLETE, loadNodes);
        loader.load(new URLRequest("../resources/xml/nodes.xml"));
       // Iterar os objectos de XML 
        function loadNodes(e:Event):void
        {
            var NodesXml:XML = new XML(e.target.data);

                for each (var element:XML in NodesXml.elements()) {
                trace ("elements",element.NOME);
                var elemento:Elemento = new Elemento(element.NOME);
                this.addChild(elemento);
                listaElementos.push(elemento);
                    }
                }
            }
          }

Now I wanted to replace the 'loadNodes' fuction with the following code wich I think is better for my purpuoses:

 for (elem in xml.elements("NODULO")) {
var url: String = elem.IMGURL.text();
var text: String = elem.TEXT.text();

var s = new Sprite();
var ldr = new Loader();
ldr.load(new URLRequest(url));
s.addChild(ldr)
// create TextField, add as child, etc
root.addChild(s)
 }

and this is my xml:

<?xml version="1.0" encoding="utf-8"?>
<xml>
<NODULO>
    <NOME>Hypermedia</NOME>
    <IMGURL>../resources/images/hyper.jpg</IMGURL>
    <TEXT>Hypermedia is used as a logical.</TEXT>
    <TAGS>Hypermedia,Communication,Video</TAGS>
</NODULO>
    <NODULO>
    <NOME>Augmented Reality</NOME>
    <IMGURL>../resources/images/aug.jpg</IMGURL>
    <TEXT>Augmented Reality is used as a logical extension.</TEXT>
    <TAGS>Augmented,Communication,Video</TAGS>
</NODULO>
</xml>

Im just running into lots of errors and I cant make it work, also can someone please explain then how would I actually create a sprite or mc?

I think im really confused about this, thanks.