A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 40

Thread: Problem Reading XML - Help!

  1. #1
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315

    Problem Reading XML - Help!

    I"m having issues defining values in my AS from the XML. For some reason my AS won't read my XML File. See below. Am I missing anything?

    I've been going through this for hours and can't figure out what I'm missing.

    AS:
    Code:
    
    var newsWidth=300;//news tricker width;
    var newsHeight=335;//news tricker height;
    var itemspace=15;//between two item space.
    var speed=40;//slide speed.
    
    system.useCodepage=true;
    Stage.scaleMode = "noscale";
    // -- draw rectangle
    MovieClip.prototype.drawrect = function(pos_x, pos_y, w, h) {
    	// --
    	this.px = pos_x;
    	this.py = pos_y;
    	this.an = w;
    	this.al = h;
    	// --
    	with (this) {
    		beginFill(0x000000, 30);
    		moveTo(px, py);
    		lineTo(px+an, py);
    		lineTo(px+an, py+al);
    		lineTo(px, py+al);
    		lineTo(px, py);
    		endFill();
    	}
    };
    // -- format text
    myFormat = new TextFormat();
    myFormat.font = "verdana";
    myFormat.size = 20;
    myFormat.color = 0x000000;
    
    
    // xml parsing.
    xmlParse = function (xmlObj) {
    	this = xmlObj;
    	var xpos = 0;
    	var ypos =0;
    	for (var i = 0; i<this.firstChild.childNodes.length; i++) {
    		item = newsTicker_mc.attachMovie("Ticker_mc", "Ticker"+i, 100+i);
    		//item.mytext.embedFonts = true;
    		item.main.mytext.autoSize = true;
    		item.main.mytext.text = this.firstChild.childNodes[i].attributes.mytext;
    		item.mylink = this.firstChild.childNodes[i].attributes.links;
    		item.main.mytext.setTextFormat(myFormat);
    		item._x = xpos;
    		item._y = ypos;
    		ypos += item.main.mytext.textHeight+itemspace;
    		// --
    		item.onRelease = function() {
    			this.main.mytext.textColor = 0x000000;
    			// -- open the link
    			getURL(this.mylink, target="_blank");
    		};
    		// --
    		item.onRollOver = function() {
    			this.news.mytext.textColor = 0x000000;
    			// --clear interval
    			clearInterval(idInterval);
    		};
    		// --
    		item.onRollOut=item.onReleaseOutside = function() {
    			this.main.mytext.textColor = 0x000000;
    			// -- re setInterval,go on move
    			idInterval = setInterval(scrollit, speed, this._parent);
    		};
    	}
    };
    
    // --load xml
    myXML = new XML();
    myXML.ignoreWhite = true;
    myXML.onLoad = function(succes) {
    	if (succes) {
    		xmlParse(this);
    	} else {
    		trace("Error al cargar datos");
    	}
    };
    
    myXML.load("http://tabletrac/tv/text/L.xml");
    
    // --define scroll
    scrollit = function (myclip) {
    	myclip._y -= 1;
    	updateAfterEvent();
    	// -- hitTest
    
    	if (!myclip.hitTest(maskTicker)) {
    		myclip._y = maskTicker._y+maskTicker._height+50;
    	}
    };
    
    // -- create mask
    this.createEmptyMovieClip("maskTicker", this.getNextHighestDepth());
    this.maskTicker.drawrect(newsTicker_mc._x, newsTicker_mc._y, newsWidth, newsHeight);
    newsTicker_mc.setMask(this.maskTicker);
    // -- setInterval
    
    idInterval = setInterval(scrollit, speed, newsTicker_mc);
    XML:
    Code:
    <main>
    <news>
    <new links="" mytext="Welcome to 7 Clans Casino | Thief River Falls"/>
    <new links="" mytext="                                                                                    "/>
    <new links="" mytext="...................................."/>
    <new links="" mytext="Our friendly Player Club Staff are here to guarantee that you experience the best of Northern Minnesota's celebrated hospitality each time you visit us. "/>
    
    
    <new links="" mytext="Don't forget to sign-up for our Players Club! Jackpot will be starting at 4:00pm"/>
    <new links="" mytext="                                                                                    "/>
    <new links="" mytext="...................................."/>
    <new links="" mytext="Check out the pool"/>
    <new links="" mytext="                                                                                    "/>
    <new links="" mytext="...................................."/>
    <new links="" mytext="Lunch and Dinner Buffets starting at $11.95"/>
    <new links="" mytext="                                                                                    "/>
    <new links="" mytext="...................................."/>
    
    </news>-->
    </main>
    Last edited by intromo; 05-07-2008 at 03:42 PM.

  2. #2
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    <new links is there actually a space there?

    XML Naming Rules

    XML elements must follow these naming rules:

    * Names can contain letters, numbers, and other characters
    * Names must not start with a number or punctuation character
    * Names must not start with the letters xml (or XML, or Xml, etc)
    * Names cannot contain spaces
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  3. #3
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    unless its a typo your xml is poorly formed at this line
    </news>-->

    in Flash, with the barest minimum of code, i can show
    each of the attributes within the nodes with -

    PHP Code:
    // xml parsing.
    xmlParse = function (xmlObj) {
    aNode xmlObj.firstChild.firstChild.childNodes;
    for (var 
    0i<aNode.lengthi++) {
    trace(aNode[i].attributes.mytext);
    trace(aNode[i].attributes.links);
    }
    }; 
    hth

  4. #4
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Quote Originally Posted by kortex
    <new links is there actually a space there?

    XML Naming Rules

    XML elements must follow these naming rules:

    * Names can contain letters, numbers, and other characters
    * Names must not start with a number or punctuation character
    * Names must not start with the letters xml (or XML, or Xml, etc)
    * Names cannot contain spaces
    Yes - I left a space in there because I'm not wanting to link anthing just yet. I am however stumped on why it's not loading the XML - specifically for a node like this:

    Code:
    :)item.main.mytext.setTextFormat(myFormat);
    when I load the line without "main" and remove "main" from the XML it work - but I want "main" in the XML, because I need to add an additional tag. So I guess the question is whe I add "main" to my xml - how can i make it work with the current code above?

    Again - thank you for the help. This is driving me insane!

  5. #5
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Quote Originally Posted by a_modified_dog
    unless its a typo your xml is poorly formed at this line
    </news>-->

    in Flash, with the barest minimum of code, i can show
    each of the attributes within the nodes with -

    PHP Code:
    // xml parsing.
    xmlParse = function (xmlObj) {
    aNode xmlObj.firstChild.firstChild.childNodes;
    for (var 
    0i<aNode.lengthi++) {
    trace(aNode[i].attributes.mytext);
    trace(aNode[i].attributes.links);
    }
    }; 
    hth

    I don't under stand what you gave me?

    Here's the AS code that works perfectly with the XML above:

    Code:
    var newsWidth=300;//news tricker width;
    var newsHeight=375;//news tricker height;
    var itemspace=15;//between two item space.
    var speed=40;//slide speed.
    
    system.useCodepage=true;
    Stage.scaleMode = "noscale";
    // -- draw rectangle
    MovieClip.prototype.drawrect = function(pos_x, pos_y, w, h) {
    	// --
    	this.px = pos_x;
    	this.py = pos_y;
    	this.an = w;
    	this.al = h;
    	// --
    	with (this) {
    		beginFill(0x000000, 30);
    		moveTo(px, py);
    		lineTo(px+an, py);
    		lineTo(px+an, py+al);
    		lineTo(px, py+al);
    		lineTo(px, py);
    		endFill();
    	}
    };
    // -- format text
    myFormat = new TextFormat();
    myFormat.font = "verdana";
    myFormat.size = 20;
    myFormat.color = 0x000000;
    
    
    // xml parsing.
    xmlParse = function (xmlObj) {
    	this = xmlObj;
    	var xpos = 0;
    	var ypos =0;
    	for (var i = 0; i<this.firstChild.childNodes.length; i++) {
    		item = newsTicker_mc.attachMovie("Ticker_mc", "Ticker"+i, 100+i);
    		
    		//item.mytext.embedFonts = true;
    		item.mytext.autoSize = true;
    		item.mytext.text = this.firstChild.childNodes[i].attributes.mytext;
    		item.mylink = this.firstChild.childNodes[i].attributes.links;
    		item.mytext.setTextFormat(myFormat);
    		item._x = xpos;
    		item._y = ypos;
    		ypos += item.mytext.textHeight+itemspace;
    		// --
    		item.onRelease = function() {
    			this.mytext.textColor = 0x000000;
    			// -- open the link
    			getURL(this.mylink, target="_blank");
    		};
    		// --
    		item.onRollOver = function() {
    			this.mytext.textColor = 0x000000;
    			// --clear interval
    			clearInterval(idInterval);
    		};
    		// --
    		item.onRollOut=item.onReleaseOutside = function() {
    			this.mytext.textColor = 0x000000;
    			// -- re setInterval,go on move
    			idInterval = setInterval(scrollit, speed, this._parent);
    		};
    	}
    };
    
    // --load xml
    myXML = new XML();
    myXML.ignoreWhite = true;
    myXML.onLoad = function(succes) {
    	if (succes) {
    		xmlParse(this);
    	} else {
    		trace("Error al cargar datos");
    	}
    };
    
    myXML.load("http://tabletrac/tv/text/L.xml");
    
    // --define scroll
    scrollit = function (myclip) {
    	myclip._y -= 1;
    	updateAfterEvent();
    	// -- hitTest
    
    	if (!myclip.hitTest(maskTicker)) {
    		myclip._y = maskTicker._y+maskTicker._height+50;
    	}
    };
    
    // -- create mask
    this.createEmptyMovieClip("maskTicker", this.getNextHighestDepth());
    this.maskTicker.drawrect(newsTicker_mc._x, newsTicker_mc._y, newsWidth, newsHeight);
    newsTicker_mc.setMask(this.maskTicker);
    // -- setInterval
    
    idInterval = setInterval(scrollit, speed, newsTicker_mc);
    What I need to do is add <main> </main> to my XML file - which renders my AS useless - how do I modify the myText to read with the addition of main?

  6. #6
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    Yes - I left a space in there because I'm not wanting to link anthing just yet. I am however stumped on why it's not loading the XML - specifically for a node like this:

    Ok, but if the XML is malformed, it probably wont load and even if it does, I am betting it wont parse correctly.
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  7. #7
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Quote Originally Posted by kortex
    Yes - I left a space in there because I'm not wanting to link anthing just yet. I am however stumped on why it's not loading the XML - specifically for a node like this:

    Ok, but if the XML is malformed, it probably wont load and even if it does, I am betting it wont parse correctly.
    It's parsing correctly. But I want to add a <main> at the top and an </main> at the bottom of the xml so i can add another xml call.

    Code:
    <news>
    
    <new links="" mytext="Welcome to 7 Clans Casino | Thief River Falls"/>
    <new links="" mytext="                                                                                    "/>
    <new links="" mytext="...................................."/>
    <new links="" mytext="Our friendly Player Club Staff are here to guarantee that you experience the best of Northern Minnesota's celebrated hospitality each time you visit us. "/>
    
    
    <new links="" mytext="Don't forget to sign-up for our Players Club! Jackpot will be starting at 4:00pm"/>
    <new links="" mytext="                                                                                    "/>
    <new links="" mytext="...................................."/>
    <new links="" mytext="Check out the pool"/>
    <new links="" mytext="                                                                                    "/>
    <new links="" mytext="...................................."/>
    <new links="" mytext="Lunch and Dinner Buffets starting at $11.95"/>
    <new links="" mytext="                                                                                    "/>
    <new links="" mytext="...................................."/>
    
    </news>

  8. #8
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    if your xml is heading towards -
    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <main>
    <news>
    <new links="link1" mytext="Welcome to 7 Clans Casino | Thief River Falls" />
    <new links="link2" mytext="Lunch and Dinner Buffets starting at $11.95" />
    </news>
    </main>

    <main>
    <news>
    <new links="link3" mytext="Thief River Falls" />
    <new links="link4" mytext="Lunch $110.95" />
    <new links="link5" mytext="Starting at 4:00pm" />
    </news>
    </main>
    you will need to loop thro' each <main></main> node counting the number of <new > nodes within each.
    you will need a nested loop to do this -
    PHP Code:
    // xml parsing.
    xmlParse = function (xmlObj) {
    aNode xmlObj.childNodes
    len1 aNode.lengthtrace(len1+" nodes - <main></main>");
        for (var 
    0i<len1i++) {
    len2 =  aNode[i].firstChild.childNodes.length; ;
        for (var 
    0j<len2j++) { trace("<main>"+i+" <new>"+j);
    trace(aNode[i].firstChild.childNodes[j].attributes.mytext);
    trace(aNode[i].firstChild.childNodes[j].attributes.links)
    }
    }
    };

    // --load xml
    myXML = new XML();
    myXML.ignoreWhite true;
    myXML.onLoad = function(){
    xmlParse(this);
    }
    myXML.load("test.xml"); 
    hth
    Last edited by a_modified_dog; 05-07-2008 at 05:39 PM.

  9. #9
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Again Mod Dog - Thank you for your help, however nothing comes up now... Did i post something wrong here? I'm trying to undersand how this works - as this is a test application - but I do have similar ones I'd like to do the same thing with....

    AS:

    Code:
    var newsWidth=300;//news tricker width;
    var newsHeight=375;//news tricker height;
    var itemspace=15;//between two item space.
    var speed=40;//slide speed.
    
    system.useCodepage=true;
    Stage.scaleMode = "noscale";
    // -- draw rectangle
    MovieClip.prototype.drawrect = function(pos_x, pos_y, w, h) {
    	// --
    	this.px = pos_x;
    	this.py = pos_y;
    	this.an = w;
    	this.al = h;
    	// --
    	with (this) {
    		beginFill(0x000000, 30);
    		moveTo(px, py);
    		lineTo(px+an, py);
    		lineTo(px+an, py+al);
    		lineTo(px, py+al);
    		lineTo(px, py);
    		endFill();
    	}
    };
    // -- format text
    myFormat = new TextFormat();
    myFormat.font = "verdana";
    myFormat.size = 20;
    myFormat.color = 0x000000;
    
    
    // xml parsing. 
    xmlParse = function (xmlObj) { 
    aNode = xmlObj.childNodes; 
    len1 = aNode.length; trace(len1+" nodes - <main></main>"); 
        for (var i = 0; i<len1; i++) { 
    len2 =  aNode[i].firstChild.childNodes.length; ; 
        for (var j = 0; j<len2; j++) { trace("<main>"+i+" <new>"+j); 
    trace(aNode[i].firstChild.childNodes[j].attributes.mytext); 
    trace(aNode[i].firstChild.childNodes[j].attributes.links) 
    } 
    } 
    };
    		
    		//item.mytext.embedFonts = true;
    		item.mytext.autoSize = true;
    		item.mytext.text = this.firstChild.childNodes[i].attributes.mytext;
    		item.mylink = this.firstChild.childNodes[i].attributes.links;
    		item.mytext.setTextFormat(myFormat);
    		item._x = xpos;
    		item._y = ypos;
    		ypos += item.mytext.textHeight+itemspace;
    		// --
    		item.onRelease = function() {
    			this.mytext.textColor = 0x000000;
    			// -- open the link
    			getURL(this.mylink, target="_blank");
    		};
    		// --
    		item.onRollOver = function() {
    			this.mytext.textColor = 0x000000;
    			// --clear interval
    			clearInterval(idInterval);
    		};
    		// --
    		item.onRollOut=item.onReleaseOutside = function() {
    			this.mytext.textColor = 0x000000;
    			// -- re setInterval,go on move
    			idInterval = setInterval(scrollit, speed, this._parent);
    		};
    	
    
    
    // --load xml 
    myXML = new XML(); 
    myXML.ignoreWhite = true; 
    myXML.onLoad = function(){ 
    xmlParse(this); 
    } 
    myXML.load("http://tabletrac/tv/text/L.xml"); 
    
    
    // --define scroll
    scrollit = function (myclip) {
    	myclip._y -= 1;
    	updateAfterEvent();
    	// -- hitTest
    
    	if (!myclip.hitTest(maskTicker)) {
    		myclip._y = maskTicker._y+maskTicker._height+50;
    	}
    };
    
    // -- create mask
    this.createEmptyMovieClip("maskTicker", this.getNextHighestDepth());
    this.maskTicker.drawrect(newsTicker_mc._x, newsTicker_mc._y, newsWidth, newsHeight);
    newsTicker_mc.setMask(this.maskTicker);
    // -- setInterval
    
    idInterval = setInterval(scrollit, speed, newsTicker_mc);

  10. #10
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    pasting the code in your last post to a new fla and testing, outputs an error -

    Error opening URL "http://tabletrac/tv/text/L.xml"

    can you fix this so we are both testing with the same xml file ?

  11. #11
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Quote Originally Posted by a_modified_dog
    pasting the code in your last post to a new fla and testing, outputs an error -

    Error opening URL "http://tabletrac/tv/text/L.xml"

    can you fix this so we are both testing with the same xml file ?
    Might be easier for you to just see my orignial code. Here's the link to the FLA document:

    http://www.intromotion.com/tv/promo/l_shape_OFFICE.fla

    I redirected the paths XML online. http://www.intromotion.com/tv/text/L.xml

    As you can see, what i"m trying to do is feed the ONE XML with 2 tags. The "L" file works well when i feed the XML's as 2 seperate files, however I'd like to try it with just one.

    On another note (and I've posted this in a new thread) when I change the XML file, nothing updates, unless I re-start the program.... This app outputs to EXE and runs on a desktop, but calls for the XML through http. Any suggestions?

    Thanks for the help!

  12. #12
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    cannot open Flash 9 files here.

  13. #13
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Quote Originally Posted by a_modified_dog
    cannot open Flash 9 files here.
    Sorry about that. Try it now.

  14. #14
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    before you can get any further, you need to simplify
    that xml file. I suggest you follow this format -
    PHP Code:
     <?xml version="1.0" encoding="ISO-8859-1" ?>

    <main>

         <newsticker>

      <item>
        <news>User BEEEEEEE was here! 1</news> 
        <url></url> 
      </item>

      <item>
        <news>User BEEEEEEE was here! 2</news> 
        <url></url> 
      </item>

         </newsticker>

         <news>

      <item>
        <news>Welcome to 7 Clans Casino | Thief River Falls</news> 
        <url></url> 
      </item>

      <item>
        <news></news>
        <url></url> 
      </item>

      <item>
        <news>....................................</news> 
        <url></url> 
      </item>

          </news>

    </main>
    is this a possibility ?

  15. #15
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Quote Originally Posted by a_modified_dog
    before you can get any further, you need to simplify
    that xml file. I suggest you follow this format -
    this a possibility ?
    No problem:

    http://www.intromotion.com/tv/text/L.xml

    Again - thanks for the help!

  16. #16
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    i've taken this fla about as far as i can for you
    hope it's where you're heading
    Attached Files Attached Files
    • File Type: zip L.zip (72.0 KB, 91 views)

  17. #17
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Yes! Not bad at all... when you test this (i.e. updating the XML) do you notice the ticker on the bottome starts to wig out? I'm wondering if a timeline might solve the issue? Any ideas?

    Agian - thanks much for the help on this.

  18. #18
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    try clearing the setInterval within the refreshXML function,
    when the onLoad completes, restart the setInterval call.

  19. #19
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Quote Originally Posted by a_modified_dog
    try clearing the setInterval within the refreshXML function,
    when the onLoad completes, restart the setInterval call.
    That didn't seem to work.... i just put the setinterval after the refreshXML right?

    Again - thanks for your help...

  20. #20
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    I've been playing around with the set interval. The text totally wigs out when I update the XML - although it is updating... This exactly same thing happened when I added a timeline. I'm wondering if I need to unload and reload the XML somehow? Do you see this on your end?

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