views:

292

answers:

1

Im having a hard time putting in my head on how would i go at making flash read a xml file (this part I have it going smooth) and then fromt hat elements put on the stage a sprite or a movieclip that is interactive.

To make it clear I want to load and display an image that when you press it it just creates another square beneath it with some text.

I believe I have to interate the xml and then use each of the elements with a class and gettin that object onto the stage.

Im using flash builder and as3 and im looking just for pointing in the rigth direction, of course I apreciate any more elaborate though some head clearing is just as good.

Thank you.

A: 

You can iterate on the XML content using the methods as described at http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/XML.html

You would need something like:

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)
}
ron
Thank you for your example, just one more thing what should I look at to understand were to take it from there? I mean just general terms for me to research.
Marvy
What topic are you interested in? Kirupa forums and Senocular has articles about a wide range of topics (XML, Sprites, mouse listeners), worth looking at. Also, the Adobe Livedocs has nice API description and some examples.
ron
Im trying to improve my weak as3 code, I know the Kirupa forums and Senocular pages, they are aewsome but im rushing to trying to get this to work so I was aiming for more dead on help. I apreciate yours. Im more specifically interested in undestanding how to create and add a sprite or movieclip to the stage with a basic interaction. As an off topic do you do freelance? or have a Steam account?
Marvy
Well, the (updated) example has a Sprite called s, which is added to the root using root.addChild(s). Basically that is all you need (and adding the image and text as child of s), and maybe keep a reference to s for later use. You can set the s.x, s.y, etc. attributes to control the sprite. See also http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Sprite.html
ron
Thank you for taking time to guide me in this.
Marvy
YW. Please accept the answer if you find it helpful. Thanks!
ron