dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: XML Help

  1. #1
    Junior Member
    Join Date
    Oct 2008
    Posts
    21

    XML Help

    Let me start out by saying, I am TRYING to teach myself all about Flash and XML, but now I am running into some road blocks.

    I am going to be working with a auto-generated XML from another program. The blocks that I am running into is trying to display an image, lets say a blue bubble, when the word Buzz is XML or a red bubble when Event is seen in a new field. See the example of one entry from the XML.

    Next I am trying to show the timestamp in a new field. And for some reason I am having trouble with getting the URL to show.

    I am using code from another XML/Flash piece that I did, with help, that I would hope to edit to make this work.

    Thank you for the help. I am using Flash 8 pro & AS2.

    XML:
    Code:
    <?xml version="1.0" encoding="utf-8" ?> 
    - <ContentEntries>
    - <ContentEntry id="171" type="Buzz" commentsEnabled="true" timestamp="4/6/2009 9:33:08 PM">
      <Headline>Title</Headline> 
      <Kicker>Kicker/Grab/Subheadline Text</Kicker> 
      <Author id="0" name="Author Name" title="Author Title" /> 
      <EntryImages authorImageSrc="URL" entryIconSrc="URL" /> 
      <EventDetails /> 
      <MainContent>Duis mi. Etiam vulputate hendrerit felis. In fermentum, risus id vestibulum posuere, enim purus tempor magna, eget laoreet dui risus vel orci. Curabitur at sapien sit amet lacus tincidunt venenatis. Quisque blandit. Mauris consectetur laoreet mi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent sollicitudin augue quis nisl. Nunc faucibus lectus bibendum quam. Pellentesque suscipit, nisi sit amet facilisis mattis, elit diam sodales augue, at vulputate lorem turpis non urna.</MainContent> 
      <EventImages /> 
      <AssociatedMedia type="image" src="URL" previewSrc="URL" /> 
    - <Comments count="1" title="What do you think about this?">
      <Comment id="0" timestamp="128831890068281250" userName="Drewy5" iconSrc="URL">This is like the coolest thing ever.</Comment> 
      <ImportanceModifier>8</ImportanceModifier> 
      </ContentEntry>
      </ContentEntries>
    Code:
    function loadXML(loaded) {
    	if (loaded) {
    		xmlNode = this.firstChild;
    		url = [];
    		total = xmlNode.childNodes.length;
    		for (i = 0; i < total; i++) {
    			caption[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    			url[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    		}
    		first_item();
    	} else {
    		content = "file not loaded!";
    	}
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("BuzzNews.xml?blarg=" + new Date().getTime());
    //
    function first_item() {
    	delay = 6500;
    	p = 0;
    	display(p);
    	p++;
    }
    function timer() {
    	myInterval = setInterval(ticker, delay);
    	function ticker() {
    		clearInterval(myInterval);
    		if (p == total) {
    			p = 0;
    		}
    		fadeout();
    	}
    }
    function display(pos) {
    	newsMC.newsText._alpha = 100;
    	newsMC.newsText.text = caption[pos];
    	newsMC.newsText.setTextFormat(out);
    	newsMC.newsURL = url[pos]
    	newsMC.enabled = false;
    	if (newsMC.newsURL != undefined) {
    		newsMC.enabled = true;
    	}
    	timer();
    }
    over = new TextFormat();
    over.underline = true;
    //
    nextbutton.onRelease = function() { 
         clearInterval(myInterval);
    	 display(p); 
         p++; 
         if(p==total){ 
               p=0; 
         } 
         delete this.onEnterFrame; 
    };
    out = new TextFormat();
    out.underline = false;
    newsMC.onRelease = function() {
    	getURL(this.newsURL, "_blank");
    };
    newsMC.onRollOver = function() {
    	this.newsText.setTextFormat(over);
    };
    newsMC.onRollOut = function() {
    	this.newsText.setTextFormat(out);
    };
    function fadeout() {
    	this.onEnterFrame = function() {
    		if (newsMC.newsText._alpha >= 0) {
    			newsMC.newsText._alpha -= 5;
    		} else {
    			display(p);
    			p++;
    			delete this.onEnterFrame;
    		}
    	};
    }

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    to find the type and timestamp -
    PHP Code:
    .....
    xmlNode this.firstChild;
    trace(xmlNode.childNodes[0].attributes.type); // Buzz
    trace(xmlNode.childNodes[0].attributes.timestamp); // 4/6/2009 9:33:08 PM
    ..... 

  3. #3
    Junior Member
    Join Date
    Oct 2008
    Posts
    21
    Thanks for the reply... a couple of follow up questions.

    1. After I put in both "trace" lines, do I then need to put it into
    Code:
    for (i = 0; i < total; i++) {
    			caption[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
    			type[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    			time[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
    2. Then to display those two attributes would i then need to enter more lines to
    Code:
    function display(pos) {
    	newsMC.newsText._alpha = 100;
    	newsMC.newsText.text = caption[pos];
    	newsMC.newsText.setTextFormat(out);
    	newsMC.newsURL = url[pos]
    and the put news.MC.newsType.text = type[pos];

    Thanks for the help... I really appreciate it.

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    your code is not correct ..

    you are targetting - xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
    you should be targetting - xmlNode.childNodes[i].attributes.type;

    same goes for timestamp.
    time[i] = xmlNode.childNodes[i].attributes.timestamp;

    example of attributes (in red) -
    <ContentEntry id="171" type="Buzz" commentsEnabled="true" timestamp="4/6/2009 9:33:08 PM">

    example of nodeValue (in blue) -
    <Kicker>Kicker/Grab/Subheadline Text</Kicker>

    if you are unsure, just add traces to your file to show all results in the output window.

    don't forget to declare your arrays somewhere in your code or they will never be compiled -
    type = []; time = [];

Tags for this Thread

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