Reputation: 105
I have this XML that shows some data from mysql database.
I need to pull some of those data (i.e. Name, Price, etc) from the xml and show them in the Flash application.
Now, I can pull the images and display them in the flash but I have problem displaying the texts from the xml into the flash.
This is the structure of my xml:
<Data>
<ID>127</ID>
<Name>Example 1</Name>
<Price>12!!</Price>
<Image>inventory_images/127.jpg</Image>
<Date>Mar 08, 2013</Date>
</Data>
and this the code (Flash AS3) that will display the image of the product in the flash.
stop();
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;
var xmlLoader:URLLoader;
var xml:XML;
var xmlList:XMLList;
var uRequest = new URLRequest("PATH-TO-MY-XML-FILE");
xmlLoader = new URLLoader(uRequest);
xmlLoader.addEventListener(Event.COMPLETE, onXMLLoad);
var imgLoader:Loader;
function onXMLLoad(e:Event) {
xml = new XML(e.target.data);
imgLoader = new Loader();
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImgLoaded);
imgLoader.load(new URLRequest(xml.Data.Image.text()[0]));
}
function onImgLoaded(e:Event) {
addChild(imgLoader);
imgLoader.height = 300;
imgLoader.width = 300;
}
could someone please help me out with this?
Thanks in advance.
Upvotes: 0
Views: 2405
Reputation: 1191
So if I understand your question correctly, the image loading and displaying part works. If you want to display your text you can simply use TextFields like this :
function onXMLLoad(e:Event) {
xml = new XML(e.target.data);
var tf:TextField = new TextField();
tf.text = xml.Name.text()[0];//or whatever part you want to display
addChild(tf);//you'll want to style and move tf, maybe.
}
flex labels would work too...
EDIT : also I see you are in the timeline, so you could simply use a dynamic textfield named 'myTextField' for example, and then your code :
var myString:String = 'loading';
function onXMLLoad(e:Event) {
xml = new XML(e.target.data);
myTextField.text = "" + xml.Name.text()[0];
}
Upvotes: 1
Reputation: 36
try imgLoader.load(new URLRequest(xml.Image.toString())); and you may need use full url like http://yoursite.com/inventory_images/127.jpg instead inventory_images/127.jpg in your xml, or add http://yoursite.com/ to url string.
Upvotes: 0