Loading external xml

I read this tutorial, and it’s beautiful:

http://www.kirupa.com/developer/flashcs3/using_xml_as3_pg1.htm

It has everything I need but does anybody know how to add images to this? Ability of having little image, next to text. Like a book cover, in this particulary example.
How to alter both for xml and as code. Would xml be something like this:

<Books>
<Book ISBN=“xxxx”>
<title> Title of book 1</title>
<author> Author 1</author>

     &lt; image &gt;
     &lt;title&gt;Title1&lt; /title &gt;
     &lt;width&gt; width1 &lt; /width &gt;
     &lt;height&gt;height1&lt; /height &gt;
     &lt;link&gt;link1&lt; /link &gt;
     &lt;url&gt;url_to_image1&lt; /url &gt;
     &lt; /image &gt;
    &lt;/Book&gt;

&lt;Book ISBN="xxxx"&gt;
&lt;title&gt; Title of book 2&lt;/title&gt;
    &lt;author&gt; Author 2&lt;/author&gt;

     &lt;image&gt;
     &lt;title&gt;Title2&lt; /title &gt;
     &lt;width&gt; width2 &lt; /width &gt;
     &lt;height&gt;height2&lt; /height &gt;
     &lt;link&gt;link2&lt; /link &gt;
     &lt;url&gt;url_to_image2&lt; /url &gt;
     &lt;/image&gt;
    &lt;/Book&gt;

</Books>

Anyone? Thanks

http://dnadillo.dn.ua/fla/XML/img-xml.swf

I haven’t looked into the tutorial much but as long as your tag is inside the <book> tag then you should be able to access it from flash for example for your code I would you use a for loop


//if you use an array to capture the imageUrl for example
var urlArray:Array = new Array();
xmContent = XML(xmLoader.data);
//then the for loop to look into each <book>
for (var pic:String in xmContent.book){
  
   urlArray[pic] = xmContent.book[pic].image.url;

}


and then use that as a URLRequest… I hope this helped

Adding to what mjg08 wrote:

After accessing your XML data, store your url in an XMLList.


var xmlContent:XML;
var imageList:XMLList;

imageList = xmlContent.Book[0].image.url;

Then from your XMLList create a URLRequest to store that url, use the Loader class to load it, and finally add it to the stage.


var imageLocation:URLRequest =  new URLRequest();
var imageLoader:Loader = new Loader();

imageLoader.load(imageLocation);

addChild(imageLoader);

Thank you all for replying! I took a look at Alex Lexcuk’s fla and xml. And it has a lot of usefull data. Thank you Alex!

I have last youestion (I hope so).

This is code of altered alex’s xml (shortened for my needs):

<Books>
<Story>
<h1>

     &lt;br/&gt;
     &lt;font color="#0099FF"size="9"&gt;GJURO 2&lt;/font&gt;
     &lt;font color="#FFFFFF" size="9"&gt;Lorem ipsum dolor sit amet, consectetuer               adipiscing elit. Phasellus justo eros, molestie a, porttitor id, blandit ut, tellus.      &lt;a   href="http://www.gjuro2.hr/"&gt;Check it&lt;/a&gt; &lt;/font&gt;
    
       &lt;br/&gt;

     &lt;br&gt;
 &lt;img src="magna_carta_131.JPG" width="35" height="35" hspace="100"               vspace="10"&gt;&lt;/img&gt;
       &lt;/br&gt;

     &lt;/h1&gt;
&lt;/Story&gt;

</Books>

and when I load it into my flash, it shows this:

which is great! But is it possible to make something like this (sorry for low q):

The difference is about alingment. First comes the picture, then text besides it! And I don’t understand why it’s so much space between Gjuro2 text and rest of text

I would be thankfull for some help.

and this is as code:

function xmlLoaded(event:Event):void {
myXML = XML(myLoader.data);
ParseStory(myXML);
}
// prolazak kroz fju
function ParseStory(bookInput:XML):void {
var my_string:String;

my_string=bookInput.Story;
remove_enter(my_string);
my_txt.htmlText=remove_enter(my_string);

}

var style:StyleSheet = new StyleSheet();
var styleA:Object = new Object();
var styleA_linc:Object = new Object();
var style_div:Object = new Object();
style_div.color=“#220000”;
style_div.textAlign=“left”;
styleA_linc.color=“#220000”;
styleA.color = “#CCCCCC”;
//styleA_linc.fontWeight = “bold”;
//styleA.fontStyle = “italic”;
style.setStyle(“h1”, style_div);
//styleA.textDecoration=“underline”;
style.setStyle(“a”, styleA);
style.setStyle(“a:hover”, styleA_linc);

my_txt.styleSheet=style;

function remove_enter(str_line:String):String {
var my_array:Array = new Array();
var my_array_more_null:Array = new Array();
var my_enter:String;
var j:int=0;
my_array = str_line.split("
");//split on symbol

for (var i = 0; i&lt;my_array.length; i++) {
    my_enter=my_array*;
    //my_array*=my_enter.substring(0,my_enter.length);//remove enter form end line
    //trace(my_array*+" "+my_enter.length);//look at result
    if (my_enter.length&gt;1) {
        my_array_more_null[j]= my_enter;
        j++;
    }
}    
my_enter=my_array_more_null.join("");//symbol for upper plus line(default ",")
return my_enter;

}

Just a quick hint for XML:

If you have something like this:

<Book>
<title>asdfsdfdsf</title>
<img>ashfsadfjsadf.jpg</img>
<alt>alt</alt>
</Book>

You should using double dot syntax and cast to those expected value types such as


var xml:XML = //the above XML

var b:Book = new Book();
b.title = String(xml..title[0]);
b.img = String(xml..img[0]);
b.alt = String(xml..alt[0]);

Now for my shameless plug.  There is a class in AppCoreLib called ClassUtil that has translation methods so that you can pass a class and an XML object and it will spit out a new instance filled in.  Of course it requires that you map the XML to the public vars on the class.  Check it out:

http://appcorelib.googlecode.com/svn/trunk/asdoc/index.html
http://code.google.com/p/appcorelib/source/browse/trunk/src/appCoreLib/utils/ClassUtil.as

[quote=jwopitz;2334925]
Now for my shameless plug. There is a class in AppCoreLib called ClassUtil that has translation methods so that you can pass a class and an XML object and it will spit out a new instance filled in. Of course it requires that you map the XML to the public vars on the class. Check it out:

http://appcorelib.googlecode.com/svn/trunk/asdoc/index.html
http://code.google.com/p/appcorelib/source/browse/trunk/src/appCoreLib/utils/ClassUtil.as[/quote]

Thanx for reply, but I’m not very good in as and xml so ClassUtil means little to me…:jail:

Is there way that I can do what I said in my prevoius post? The problem is that I don’t know how many of this paragraphs will be in my xml, so it has to be in one dynamic text box…Otherwise I would separate different text boxes for different data (images, text etc.). Anyone?

Thanks

Edit:

[quote=jwopitz;2334925]Just a quick hint for XML:

If you have something like this:

<Book>
<title>asdfsdfdsf</title>
<img>ashfsadfjsadf.jpg</img>
<alt>alt</alt>
</Book>

You should using double dot syntax and cast to those expected value types such as


var xml:XML = //the above XML

var b:Book = new Book();
b.title = String(xml..title[0]);
b.img = String(xml..img[0]);
b.alt = String(xml..alt[0]);[/quote]

I could use this part but I don't know how many books there will be, so I have to load them dinamically..Any way of using this but be able to load them dinamically? Probably for loop?