-
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.
-
OOP is one letter from OOPS
<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
-
FK'n_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 i = 0; i<aNode.length; i++) {
trace(aNode[i].attributes.mytext);
trace(aNode[i].attributes.links);
}
};
hth
-
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!
-
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 i = 0; i<aNode.length; i++) {
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?
-
OOP is one letter from OOPS
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.
-
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>
-
FK'n_dog
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.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)
}
}
};
// --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.
-
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);
-
FK'n_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 ?
-
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!
-
FK'n_dog
cannot open Flash 9 files here.
-
Originally Posted by a_modified_dog
cannot open Flash 9 files here.
Sorry about that. Try it now.
-
FK'n_dog
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 ?
-
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!
-
FK'n_dog
-
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.
-
FK'n_dog
try clearing the setInterval within the refreshXML function,
when the onLoad completes, restart the setInterval call.
-
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...
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|