-
hyperlinks in XML
Hi,
I was reading this post http://board.flashkit.com/board/show...=671551&page=1
I had the same question, and it's hard for me to solve my problem with my gallery. It works fine, all I need is someone to help me out to include links in my XML file. I want the link to be at the <desc>text</desc>. The link should be the word "text".
The gallery is built in Flash and loading XML with the photos.
I would really appreciate any help.
here are my files:
1. FLASH script:
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(ok) {
if (ok) {
//process data
allGalleryData = this.firstChild.childNodes;
for (i=0; i<allGalleryData.length; i++) {
newPiece = sliderHolder_mc.slider_mc.attachMovie('template', 'piece'+i, i);
newPiece._x = i*newPiece._width;
newPiece.heading_txt.text = allGalleryData[i].firstChild.firstChild;
newPiece.desc_txt.text = allGalleryData[i].firstChild.nextSibling.firstChild;
newPiece.load_btn.imageName = allGalleryData[i].firstChild.nextSibling.nextSibling.firstChild;
newPiece.holder_mc.loadMovie('portfolio/print/'+newPiece.load_btn.imageName);
newPiece.load_btn.onRelease=function(){
bigImage_mc.loadMovie('images/'+this.imageName)
}
//trace(allGalleryData[i].firstChild.firstChild);
newBut = _root.attachMovie('numTemplate', 'num'+i, i);
newBut._y = sliderHolder_mc._y+sliderHolder_mc._height-15;
newBut._x = (i*newBut._width)+sliderHolder_mc._x+15;
newBut.myNum = i;
newBut.num_txt.text = i+1;
newBut.onRelease = function() {
targX = 0-(this.myNum*360);
};
}
targX = 0;
sliderHolder_mc.slider_mc.onEnterFrame = function() {
this._x -= (this._x-targX)/2;
};
} else {
trace('what file?');
}
};
myXML.load('xml/print.xml');
---------------------------------------------------------------------
and the
2. XML file:
<?xml version="1.0" encoding="iso-8859-1"?>
<gallery heading="Photography">
<piece>
<heading>Piece 1</heading>
<desc>text</desc>
<image>1.jpg</image>
</piece>
<piece>
<heading>Piece 2</heading>
<desc>text</desc>
<image>2.jpg</image>
</piece>
</gallery>
-
You've got the answer in the thread you point out ...anway try this.
newPiece.desc_txt.htmlText = allGalleryData[i].firstChild.nextSibling.firstChild; // do not forget to enable the textfield to render the text as html
then in the xml file :
<?xml version="1.0" encoding="iso-8859-1"?>
<gallery heading="Photography">
<piece>
<heading>Piece 1</heading>
<desc><![CDATA[<a href='http://www.yourUrlGoesHere.com' target='_blank'>text</a>]]></desc>
<image>1.jpg</image>
</piece>
<piece>
<heading>Piece 2</heading>
<desc><![CDATA[<a href='http://www.yourUrlGoesHere.com' target='_blank'>text</a>]]></desc>
<image>2.jpg</image>
</piece>
</gallery>
-
Thank You
How I enable html? is that right?
newPiece.desc_txt.htmlText = true;
-
Yes, that's right. Or in authoring mode, when the textfield is selected, in the properties panel click the little button with pointy brackets "<> "
-
err... sorry .. it is not right. correct is
newPiece.desc_txt.html = true;
-
Thank's but still it's not working:
here is what I included in flash:
I enabled the text field as html <> in flash.
and this is the script:
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(ok) {
if (ok) {
//process data
allGalleryData = this.firstChild.childNodes;
for (i=0; i<allGalleryData.length; i++) {
newPiece = sliderHolder_mc.slider_mc.attachMovie('template', 'piece'+i, i);
newPiece._x = i*newPiece._width;
newPiece.heading_txt.text = allGalleryData[i].firstChild.firstChild;
newPiece.desc_txt.htmlText = allGalleryData[i].firstChild.nextSibling.firstChild;
newPiece.load_btn.imageName = allGalleryData[i].firstChild.nextSibling.nextSibling.firstChild;
newPiece.holder_mc.loadMovie('portfolio/Identity/'+newPiece.load_btn.imageName);
newPiece.load_btn.onRelease=function(){
bigImage_mc.loadMovie('images/'+this.imageName)
}
//trace(allGalleryData[i].firstChild.firstChild);
newBut = _root.attachMovie('numTemplate', 'num'+i, i);
newBut._y = sliderHolder_mc._y+sliderHolder_mc._height-15;
newBut._x = (i*newBut._width)+sliderHolder_mc._x+15;
newBut.myNum = i;
newBut.num_txt.text = i+1;
newBut.onRelease = function() {
targX = 0-(this.myNum*360);
};
}
targX = 0;
sliderHolder_mc.slider_mc.onEnterFrame = function() {
this._x -= (this._x-targX)/2;
};
} else {
trace('what file?');
}
};
myXML.load('xml/identity.xml');
__________________________________________________ ___________
I also added your script to the xml file as you point out (copy paste it)
<?xml version="1.0" encoding="iso-8859-1"?>
<gallery heading="Photography">
<piece>
<heading>Piece 1</heading>
<desc><![CDATA[<a href='http://www.yourUrlGoesHere.com' target='_blank'>text</a>]]></desc>
<image>1.jpg</image>
</piece>
<piece>
<heading>Piece 2</heading>
<desc><![CDATA[<a href='http://www.yourUrlGoesHere.com' target='_blank'>text</a>]]></desc>
<image>2.jpg</image>
</piece>
</gallery>
I need help again...Thank's
-
-
Hmm .. this xml worked for me
....
<piece>
<heading>Piece 1</heading>
<desc><a href="http://www.yourUrlGoesHere.com" target="_blank">text</a></desc>
<image>1.jpg</image>
</piece>
....
the AS is fine.
-
wow it's work Thank you! Thank you! :thumbsup:
-
hello!
i got to the same point and everything works fine.
now i have a question:
would it be possible to have more than one link in between the same <desc></desc>?
i tried to have a short text with some links in it, like the following:
<desc>hello, I'd like to <a href="http://www.somewhere.com target="_blank">"have</a> more than <a href="http://www.somewherelse.com target="_blank">one</a> link</desc>
like that it stops readin when the first tag begins,... why??
could you help me?
thank you so much
-
Because the xml parser doesnt see text between the <desc></desc> tags like a Text node but as an Element node (see nodeType in Flash Help)
So you should walk the child nodes of the desc node to get the whole text then concate it and assign it to variable or text field.
-
oops, sorry for the late answer,
anyway thank you very much, now i found a way to make it work!
-
Hello Smilev,
sorry if i'm bothering you again
but now i have this issue:
even if i encode my xml file as UTF-8
when i want to display unusual characters (italians) such รจ or others
the browser substitures them with weird stuff as you can see at
www.spazio.org/limited/indexx.html
and the xml file is
www.spazio.org/limited/xml/home.xml
here i paste the actioscript
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(ok) {
if (ok) {
//process data
allGalleryData = this.firstChild.childNodes;
for (i=0; i<allGalleryData.length; i++) {
newPiece = sliderHolder_mc.slider_mc.attachMovie('template', 'piece'+i, i);
newPiece._y = i*newPiece._height;
newPiece.title_txt.htmlText = allGalleryData[i].firstChild.firstChild.nodeValue;
newPiece.it_txt.htmlText = allGalleryData[i].firstChild.nextSibling.firstChild.nodeValue;
newPiece.en_txt.htmlText = allGalleryData[i].firstChild.nextSibling.nextSibling.firstChild.nod eValue;
newPiece.load_btn.imageName = allGalleryData[i].firstChild.nextSibling.nextSibling.nextSibling.fi rstChild;
newPiece.holder_mc.loadMovie('images/'+newPiece.load_btn.imageName);
newPiece.load_btn.onRelease=function(){
bigImage_mc.loadMovie('images/'+this.imageName)
}
//trace(allGalleryData[i].firstChild.firstChild);
newBut = _root.toglieresevuoiilnumero.home.attachMovie('num Template', 'num'+i, i);
newBut._y = (i*newBut._height)+sliderHolder_mc._y;
newBut._x = +300;
newBut.myNum = i;
newBut.num_txt.text = i+1;
newBut.onRelease = function() {
targy = 0-(this.myNum*122);
};
}
targy = 0;
sliderHolder_mc.slider_mc.onEnterFrame = function() {
this._y -= (this._y-targy)/5;
};
} else {
trace('what file?');
}
};
myXML.load('xml/home.xml');
could you help me? this is driving me mad
thank you!
a
-
You have to not just put the encoding=utf-8 but also save the file in utf-8. Open it in Notepad. Choose File/Save As and choose utf-8 for the encoding. Then edit it and save it again.
-
i did it, i saved it with simple text in the way you told me (encoding option=utf-8)
but is still wrong. do you know something else i can try?
-
post your fla + xml file so I can check if you like.
-
ok, i zipped all together
www.spazio.org/limited/v2.zip
thank you
-
I dont know ... it looks perfectly ok on my comp. Do you want a screen capture?
-
Ohh, but you haven't embeded all characters! The unusual characters are not included in the basic latin charset. You have to include any of the extended Latin versions (scroll futher down). Also make sure, the font you are using is unicode. Not all fonts are unicode or have all the characters.
-
yes it looks perfect also on my computer, but once i put it online
it mess with those special characters.
now i embedded extended latin set (500 characters), and i also opened the font in
one font software in order to exporte it as unicode:
nothing, it still doesn't work
(in the link i sent you it is working, but just because i placed not dynamic txt in there)
if you want to give up i 'd understand you, it is really annoyng
i don't know what to do
-
did you find any solution?
i think if i ca't find a way to fix it i need to change it into not dynamic.
that would be a pity, cause il looks like a little detail..
all this work for nothing, i can't believe!
-
HI, sorry .. I cant think of anything that could cause this. Maybe try to load the text from a text file, or from php script? See if thats going to work?
Stan
-