A Flash Developer Resource Site

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

Thread: hyperlinks in XML

  1. #1
    Junior Member
    Join Date
    Jun 2006
    Posts
    5

    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>

  2. #2
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    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>
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  3. #3
    Junior Member
    Join Date
    Jun 2006
    Posts
    5
    Thank You

    How I enable html? is that right?

    newPiece.desc_txt.htmlText = true;

  4. #4
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    Yes, that's right. Or in authoring mode, when the textfield is selected, in the properties panel click the little button with pointy brackets "<> "
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  5. #5
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    err... sorry .. it is not right. correct is

    newPiece.desc_txt.html = true;
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  6. #6
    Junior Member
    Join Date
    Jun 2006
    Posts
    5
    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

  7. #7
    Junior Member
    Join Date
    Jun 2006
    Posts
    5
    can you help me out?

  8. #8
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    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.
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  9. #9
    Junior Member
    Join Date
    Jun 2006
    Posts
    5
    wow it's work Thank you! Thank you!

  10. #10
    Junior Member
    Join Date
    Oct 2006
    Posts
    17
    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

  11. #11
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    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.
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  12. #12
    Junior Member
    Join Date
    Oct 2006
    Posts
    17
    oops, sorry for the late answer,
    anyway thank you very much, now i found a way to make it work!

  13. #13
    Junior Member
    Join Date
    Oct 2006
    Posts
    17
    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

  14. #14
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    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.
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  15. #15
    Junior Member
    Join Date
    Oct 2006
    Posts
    17
    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?

  16. #16
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    post your fla + xml file so I can check if you like.
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  17. #17
    Junior Member
    Join Date
    Oct 2006
    Posts
    17
    ok, i zipped all together
    www.spazio.org/limited/v2.zip

    thank you

  18. #18
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    I dont know ... it looks perfectly ok on my comp. Do you want a screen capture?
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  19. #19
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    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.
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  20. #20
    Junior Member
    Join Date
    Oct 2006
    Posts
    17
    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

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