Results 1 to 6 of 6

Thread: Use XML to load .jpg

  1. #1
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default Use XML to load .jpg

    With this code I am retrieving text from an XML node and placing it in a textbox

    Code:

    var myxml:XML;
    var data:String;
    var loader:URLLoader= new URLLoader();


    loader.addEventListener(Event.COMPLETE,OnComplete);

    loader.load(new URLRequest("myxml.xml"));
    function OnComplete(evt:Event):void
    {

    myxml = new XML(evt.target.data);
    loader.removeEventListener(Event.COMPLETE,OnComplete);
    //trace(myxml.Content);
    data=myxml.Content;
    //trace (textdata)

    textbox.text=textdata;

    }

    I also figured out how to use a loader to place images.

    Can I use xml to load images? I'm not sure how to do it.

    if my xml file has <picture>mypicture.jpg</picture>
    I tried this in my code but it didn't work:
    data=myxml.picture.mypicture.jpg

  2. #2
    Join Date
    Oct 2008
    Posts
    15
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    This helped me, but I can't get it to display .png files, only jpeg.

    http://www.gotoandlearn.com/play?id=22

    It's a great tutorial and you can download the files.

    Robert

  3. The Following User Says Thank You to rd42 For This Useful Post:

    evan (10-24-2008)

  4. #3
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default Is there an As3 version?

    This was a good toturial -I think I remember watching it, so I think I want to redirect my question to how this is done in Actionscript 3:

    Namely in this example, you can access the nodes by decaring variables:
    As2 version:
    var urls:Array=new Array();
    var captions:Array=new Array();
    next he does this:

    var photos:Array= this.firstChild.Childnodes;
    //then a loop

    for (1=0;<photos.legnth;i++)
    {
    urls.push(photos[i].attributes.url
    captions.push(photos[i].attributes.url
    }

    is there an easy explanation for how this works in As3?

  5. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Since he can do a much better a explaining AS than I can, I'll let Lee finish the explanation:

    http://www.gotoandlearn.com/play?id=64
    http://www.gotoandlearn.com/play?id=65

    The XML parsing structrue is a lot easier in AS3.

  6. The Following User Says Thank You to Medyman For This Useful Post:

    evan (10-24-2008)

  7. #5
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    I have also seen those and played with them a bit

    those show how to work with an rss feed and how to get style settings from a remote source.

    but what I am trying to do on my own is a simple call to an xml node from an actual xml file to get the jpeg and place it

    then push them into an array and place them on the stage just like the as2 version does.

  8. #6
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    The methodology is the same. If you post your XML structure, I can give you some tips.

Bookmarks

Posting Permissions

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