A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Help uploading an Array of XML's

  1. #1
    Member
    Join Date
    Feb 2007
    Posts
    34

    Help uploading an Array of XML's

    Hello there,

    I'm creating a flash site for my friend and I want him to be able to add to an XML that looks a little like this:
    Code:
    <xml>
     <link1>
      <movie_title>###</movie_title>
      <movie_URL>###</movie_URL>
      <movie_desc>###</movie_desc>
     </link1>
     <link2>
      <movie_title>###</movie_title>
      <movie_URL>###</movie_URL>
      <movie_desc>###</movie_desc>
     </link2>
    </xml>
    You get the idea.

    And i wanted to have flash import this xml but when it imports it i want it to upload the variables as an Array.

    My basic result is that i want it to provide clickable text links (thats the movie_title) that adds to the flash when he adds a new link to the XML and i've not really used Arrays that much, so if anybody can provide me with some help here id really appreshiate it

    (Sorry if my XML is rubbish it was just an example and i don't really know XML that well)

    Austinl

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    "Upload" means to send data to a server. I don't think that's what you mean.

    Do you mean that you want to have this xml file on a server and load it into flash? Then flash will parse the xml and make links from it?

    First, change your xml. Don't use unique tags for each link, use the same tag. That will let you get an XMLList of all the links easily.
    Code:
    <xml>
     <link>
      <movie_title>###</movie_title>
      <movie_URL>###</movie_URL>
      <movie_desc>###</movie_desc>
     </link>
     <link>
      <movie_title>###</movie_title>
      <movie_URL>###</movie_URL>
      <movie_desc>###</movie_desc>
     </link>
    </xml>
    Once you've got it loaded into an XML variable, you can get the list of links like this:
    Code:
    var linkNodes:XMLList = myXMLVariable.link;
    Then once you have those, you can make a function to build your clickable link objects.
    Code:
    function makeLinks(lnodes:XMLList):Array{
      var toreturn:Array = [];
      for (var i:int=0; i < lnodes.length(); i++){
        var linkData:XML = lnodes[i];
        var link:Link = new Link(linkData.movie_title.toString(), linkData.movie_url.toString(), linkData.movie_desc.toString());
        toreturn.push(link);
      }
      return toreturn;
    }
    Of course, you will need to make a Link class. Here's a very basic one that ignores the description part for now.
    Code:
    public class Link extends Sprite{
      private var tf:TextField;
      private var url:URLRequest;
      private var description:String;
    
      public function Link(title:String, url:String, desc:String){
        this.tf = new TextField();
        tf.autoSize = TextFieldAutoSize.LEFT;
        tf.text = title;
        addChild(tf);  //forgot this line initially
        this.url = new URLRequest(url);
        this.description = desc;
    
        tf.addEventListener(MouseEvent.CLICK, openURL);
      }
    
      private function openURL(e:MouseEvent):void{
        navigateToURL(url);
      }
    }
    Last edited by 5TonsOfFlax; 05-11-2011 at 12:04 PM.

  3. #3
    Member
    Join Date
    Feb 2007
    Posts
    34
    Thanks so much, this is exactly what i was looking for ;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