A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: A question about xml

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    7

    A question about xml

    my flash website extracts data from an xml file.
    is there a way that i can somehow link to images in the xml file or embed some html code in it so that when the flash file extracts the content, it also follows the links and imports the images from the server onto itself?

    get what i mean?

    im stuck in a REAL bad situation and i cant find a way out of it =/
    its like as if the actionscript i put, into this one place where i want to, is completely ignored =S
    so im trying ways around it

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You can certainly look for image urls in your xml file and load each, but it's not an automatic process. If your image urls are in an <image> node for example, you can get all image nodes and create a Loader for each which loads the image associated.
    Code:
    			var xml:XML = <stuff>
    			                <image>http://example.com/image1.jpg</image>
    					<image>http://example.com/image2.jpg</image>
    					  </stuff>
    			var imageLoaders:Array = new Array();
    			for each( var i:XML in xml..image) {
    				var l:Loader = new Loader();
    				l.load(new URLRequest(i.toString()));
    				imageLoaders.push(l);
    				addChild(l);
    			}

  3. #3
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    for that, how do i place links within an xml file?
    i mean, any specific manner?

    and the bit of code that you provided, is that all that ill be needing? or is there more to it?
    im new to action scripting.

  4. #4
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    oh and on the xml file, the link extracts date from this:

    Code:
    <link linkType="readMoreLink">
    <item name="title"><![CDATA[
    Pictures - Album 1
    ]]></item></link>
    how will i add the <image> nodes into this?

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The xml and code I posted was just a minimal example. You definitely don't need to use that code.

    The basic principle is just to extract the urls from the xml with e4x, then use those extracted urls to load the actual images.
    If your xml does not already have the urls, then I have misunderstood your situation.

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    On rereading, I think I understand better. You can add an image node as a child of each of your link nodes. The node name is not special, you could call it "pic" or "foo" if you prefer. you could also put the url in an attribute of a node you already have, but then you'll have to change the e4x expression slightly.

  7. #7
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    ok im kinda noob to this
    could please help start off with some codes?

    thanks so much though

  8. #8
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    help

  9. #9
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You could update your xml like this:
    Code:
    <link linkType="readMoreLink">
    <item name="title"><![CDATA[
    Pictures - Album 1
    ]]></item>
    <image>http://example.com/image1.jpg</image>
    </link>
    Similarly inserting an image node into each link node.

    The code I posted above will still work to extract and load these images.
    Code:
    	var imageLoaders:Array = new Array();
    	for each( var i:XML in xml..image) {
    		var l:Loader = new Loader();
    		l.load(new URLRequest(i.toString()));
    		imageLoaders.push(l);
    		addChild(l);
    	}
    But if you're already parsing each link node, it would make more sense to look for and handle the image in that code. You will still need to place the loaders with the link titles manually, which is not shown in this code because you haven't shown your code which handles the existing link stuff.

  10. #10
    Junior Member
    Join Date
    Jul 2009
    Posts
    7
    i figured that i can just use html code in the xml file to import external images on the fly.
    great!

    Thanks so much for the help though =D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center