A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: simple question - link in xml

  1. #1
    Member
    Join Date
    Sep 2003
    Location
    canada
    Posts
    70

    simple question - link in xml

    I'm creating a website that calls xml text into a dynamic text field in flash. My problem is that I need to add links (eg to download pdf) to the xml text. I tried a href but when I check the page in flash the link doesn't show up. I've been searching online but my xml knowledge is limited and I haven't found the answer I need.

    Does anyone know how to code a link to a pdf or external site in xml? Is it possible? Please help.

    Thanks!

  2. #2
    Perverse Futurist villain2's Avatar
    Join Date
    Sep 2002
    Location
    Baltimore, MD
    Posts
    891
    The reason you're link doesn't show up is because xml reads <a href> as a new node of it's own. In order to do this, you can write the nodes as CDATA or substitute "<" and ">" with "&lt;" and "&gt;" - using both is actually suggested. Just make sure the text field on your Flash stage is htmlText and not text.

  3. #3
    Member
    Join Date
    Sep 2003
    Location
    canada
    Posts
    70
    Thanks for your help, Villain2, I'm halfway there now. The text now shows up in flash but not as a link: it looks like this:

    August 17, 2007
    Caché Press Release: Homecoming Premieres at Montreal World Film Festival. <http://www.cachefilmandtelevision.com/assets/news/homecoming_press_release.pdf>

    My text field has 'selectable' and 'render text as html' activated.

    my XML file contains this:

    PHP Code:
    <?xml version="1.0"?>

    <sections>
    <text><![CDATA[<span class="boldtext">August 17, 2007</span><br>Caché Press Release: <i>Homecoming</i> Premieres at Montreal World Film Festival. &lt;http://www.cachefilmandtelevision.com/assets/news/homecoming_press_release.pdf&gt;]]>></text>
    </sections>
    Do I have to write CDATA again for each link?

    Also, I'd like the link to just show up as 'Download' , not the long location written out.

    please help me again

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    you can make use of the asfunction method to simulate hyperlinks.

    this example loads an image into the player,
    i'm sure you can modify to download your pdf file
    PHP Code:
    this.createTextField("testField",1,100,100,200,30);
    testField.html = true;
    testField.autoSize = true;

    _xml = new XML();
    _xml.ignoreWhite = true;
    _xml.load("cdata_asfunction.xml");

    _xml.onLoad = function(){
    testField.htmlText = this.firstChild.firstChild.nodeValue;
    };

    function myFunc(param){
    trace(param);
    _root.attachMovie("clip","clip1",1000,{_x:250,_y:80});
    clip1.loadMovie(param);
    };

    /*--cdata_asfunction.xml--
    <?xml version="1.0" encoding="UTF-8"?>
    <node>
    <![CDATA[<P ALIGN='CENTER'><B><FONT color='#FF0000'><a href='asfunction:myFunc,img1.jpg'>RED ROCKET</a></FONT></P>]]>
    </node>
    */
    hth

  5. #5
    Member
    Join Date
    Sep 2003
    Location
    canada
    Posts
    70
    thanks for your suggestion!

    I'm not sure it will work for my needs. You can see the site here: http://cachefilmandtelevision.com and it is the news page.

    The link needs to be a word within the existing scrolling dynamic text field, which will grow over time. I've been doing more research and I think I may need to make an XSL file for the XML file to read, something like a style sheet that says "this word means open this url". The problem is that until today I had never even heard of XSL and I have no idea how to properly code it.

    my brain hurts. lol.

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    i had this very simple concept in mind

    the Flash file simply steps through the chilNodes and adds the
    nodeValue to the textfield
    PHP Code:
    _xml = new XML(); 
    _xml.ignoreWhite = true; 
    _xml.load("a1.xml"); 

    _xml.onLoad = function(){
    txt.html = true;
    sections = this.firstChild.firstChild.childNodes;
    len = sections.length;
    for(var n=0;n!=len;n++){
    trace(sections[n].nodeValue);
    txt.htmlText += sections[n].nodeValue;
    }
    }; 

    function DLFunc(param){ 
    trace(param);
     getURL(param); 
    }; 

    /*
    <?xml version="1.0" encoding="UTF-8" ?> 

    <sections> 
    <text>
    <![CDATA[
    <span class="boldtext">August 17, 2007</span><br>Caché Press Release: <i>Homecoming</i> Premieres at Montreal World Film Festival. <br><a href = 'asfunction:DLFunc,http://www.cachefilmandtelevision.com/assets/news/homecoming_press_release.pdf'>Download pdf</a><br>]]>
    <![CDATA[
    <span class="boldtext">July 2007</span><br>Caché Film & Television Launch!<br><a href = 'asfunction:DLFunc,http://www.cachefilmandtelevision.com/assets/news/homecoming_launch_release.pdf'>Download pdf</a><br>]]>

    </text>
    </sections> 
    */
    hth
    Last edited by a_modified_dog; 12-23-2007 at 09:41 AM.

  7. #7
    Perverse Futurist villain2's Avatar
    Join Date
    Sep 2002
    Location
    Baltimore, MD
    Posts
    891
    Quote Originally Posted by sea ryder
    Thanks for your help, Villain2, I'm halfway there now. The text now shows up in flash but not as a link: it looks like this:

    August 17, 2007
    Caché Press Release: Homecoming Premieres at Montreal World Film Festival. <http://www.cachefilmandtelevision.com/assets/news/homecoming_press_release.pdf>

    My text field has 'selectable' and 'render text as html' activated.

    my XML file contains this:

    PHP Code:
    <?xml version="1.0"?>

    <sections>
    <text><![CDATA[<span class="boldtext">August 17, 2007</span><br>Caché Press Release: <i>Homecoming</i> Premieres at Montreal World Film Festival. &lt;http://www.cachefilmandtelevision.com/assets/news/homecoming_press_release.pdf&gt;]]>></text>
    </sections>
    Do I have to write CDATA again for each link?

    Also, I'd like the link to just show up as 'Download' , not the long location written out.

    please help me again
    You could write your xml as a hyperlink and not just write the link itself.

    For example:
    Code:
    <text><![CDATA[<span class="boldtext">August 17, 2007</span><br>Caché Press Release: <i>Homecoming</i> Premieres at Montreal World Film Festival. &lt;a href="http://www.cachefilmandtelevision.com/assets/news/homecoming_press_release.pdf", target="_blank"&gt; Download the PDF &lt;/a&gt;]]>></text>

  8. #8
    Member
    Join Date
    Sep 2003
    Location
    canada
    Posts
    70
    A_Modified_Dog,

    You are a genuis!!! You have solved my problem completely, I have even tested to make sure that I can include multiple links and I can! Thanks for the code because my xml and complicated actionscripting are still around the cut and paste level but I am learning so much.

    Thank you! Thank you! Thank you! You're the best!

    sea ryder

  9. #9
    Quote Originally Posted by villain2 View Post
    You could write your xml as a hyperlink and not just write the link itself.

    For example:
    Code:
    <text><![CDATA[<span class="boldtext">August 17, 2007</span><br>Caché Press Release: <i>Homecoming</i> Premieres at Montreal World Film Festival. &lt;a href="http://www.cachefilmandtelevision.com/assets/news/homecoming_press_release.pdf", target="_blank"&gt; Download the PDF &lt;/a&gt;]]>></text>
    I tried this, but it appears as the line of code???

  10. #10
    Perverse Futurist villain2's Avatar
    Join Date
    Sep 2002
    Location
    Baltimore, MD
    Posts
    891
    Try replacing the &lt; and &gt; with actual "<" and ">" brackets

  11. #11
    Quote Originally Posted by villain2 View Post
    Try replacing the &lt; and &gt; with actual "<" and ">" brackets
    Thanks for the quick response. Very grateful.

    Here's my xml page. I'm trying to make the email links work. I won't include the code I've been experimenting with to see what you come up with and avoid confusion. Maybe there is a header or something missing from the xml page?:

    Code:
    <objects>
    <object image="img2.jpg" theText="Image 2" bigImage="img2.jpg">
    <text>In this Image a snowstorm occurs at an altitude of 4,000 ft.
    Email photoguy@photoguy123.com for more info.
    </text>
    </object>
    <object image="img3.jpg" theText="Image 3" bigImage="img3.jpg">
    <text>In this Image a rainstorm occurs in the tropical location.
    Email photoguy@photoguy123.com for more info.
    </objects>
    </text>
    </object>

  12. #12
    Quote Originally Posted by villain2 View Post
    Try replacing the &lt; and &gt; with actual "<" and ">" brackets
    I meant to add that I tried this and it still didn't work.

  13. #13
    Perverse Futurist villain2's Avatar
    Join Date
    Sep 2002
    Location
    Baltimore, MD
    Posts
    891
    Can you show me what the output looks like.

    If it's coming out as lines of code, you may want to double check that your text fields in flash are truly rendering as "htmlText" instead of "text".

    ie. Mytext_txt.htmlText = evt.target.data['nodeForText'];

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