A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: XML URL Link help

  1. #1
    Junior Member
    Join Date
    Mar 2008
    Posts
    4

    XML URL Link help

    Hi,

    Sorry I had to create this thread, I have been searching this forum and others, and playing around with my script for most of today, and its fried my brain so Ive come here to ask for help.

    Ok, so basically I followed This Tutorial to create myself a news page xml.

    http://www.actionscript.org/resource...vie/Page2.html

    I will post the actionscript and xml data used in the tutorial, so its still basic and hopefully easier for people to help me.

    Action Script;

    PHP Code:
    /* initialize variables */

    var xmlObj:XML = new XML();

    var 
    featuresArray = new Array();

    var 
    counter:Number 0;

      

    /* stylize text areas */

    txtHeadline.html true;

    txtHeadline.wordWrap true;

    txtCopy.html true;

    txtCopy.wordWrap true;

      

    //load the xml into the Xml Object

    xmlObj.ignoreWhite true;

    xmlObj.load("xml/features.xml");

     

    /* parses the xml file and copies to array */

    xmlObj.onLoad = function(success) {

           var 
    temp = new Array();

           
    temp xmlObj.childNodes[0].childNodes;

           
    //remove any disabled items

           
    for (var 0p<temp.length; ++p) {

                  if (
    temp[p].attributes["enabled"].toString() == "false") {

                         
    temp.splice(p1);

                  }

           }

           
    //assign the temp array to our declared features array

           
    featuresArray temp;

           
    //call the bind method - this just adds the necessary

           
    bindFeatures(0);

    };

    /* bind the data to the controls */

    bindFeatures = function (index) {

           
    /* set up text fields */

           
    txtHeadline.text featuresArray[index].childNodes[0].firstChild.nodeValue.toString();

           
    txtCopy.text featuresArray[index].childNodes[1].firstChild.nodeValue.toString();

           
    this.image_mc.loadMovie(featuresArray[index].childNodes[2].firstChild.nodeValue.toString());

    };
     

    /* EVENT HANDLERS */

    /* Learn More Button Event */

    btnLearnMore.onRelease = function() {

           
    getURL(featuresArray[counter].childNodes[3].firstChild.nodeValue.toString(), "_blank");

    };

     

    /* Next Button Event*/

    btnNext.onRelease = function() {

           
    counter++;

           
    //this just makes sure we are not at the end of our list of items - if so it goes back to 0

           
    if (counter>=featuresArray.length) {

                  
    counter 0;

           }

           
    bindFeatures(counter);

    };

     

    /* Previous Button Event */

    btnPrevious.onRelease = function() {

           
    counter--;

           
    //this just makes sure we are not at the beginning of our list of items - if so it goes to the last feature

           
    if (counter<0) {

                  
    counter featuresArray.length-1;

           }

           
    bindFeatures(counter);

    }; 
    This is the XML file,

    PHP Code:
    <?xml version="1.0" encoding="utf-8"?>

    <features>

          <feature enabled="true">

                <headline>HEADLINE 1</headline>

                <copy>Here goes some copy you can probably put html text in here as long as its escaped</copy>

                <image>images/1.gif</image>         <link>http://www.sandboxcommunications.com</link>

          </feature>

          <feature enabled="false">

                <headline>Feature 2</headline>

                <copy>Lorem ipsumn dolomet sit</copy>

                <image>images/2.gif</image>

                <link>http://search.mustcodemore.com</link>

          </feature>

          <feature enabled="true">

                <headline>MustCodeMore</headline>

                <copy>More mustcodemore.com, more</copy>

                <image>images/3.gif</image>

                <link>http://www.mustcodemore.com</link>

          </feature>

          <feature enabled="true">

                <headline>Feature 4</headline>

                <copy> Lorem ipsumn dolomet sit amore dit amore.</copy>

                <image>images/4.gif</image>

                <link>http://www.google.ca</link>

          </feature>

          <feature enabled="true">

                <headline>Feature 5</headline>

                <copy>Borem Bpsumn Bolomet Bit Bmore Bit Bmore.</copy>

                <image>images/5.gif</image>

                <link>http://www.hp.ca</link>

          </feature>

          <feature enabled="true">

                <headline>Feature 6</headline>

                <copy>asdf j lakj. This is about feature six.  Man </copy>

                <image>images/6.gif</image>

                <link>http://www.yahoo.ca</link>

          </feature>

    </features>

    ^ SO That is the tutorial I did,

    Now this is my problem - In the <copy> tags I want to put in URL links, like I would in html like this for example. <a href="http://www.test.com/" target="_blank">link</a>

    So I can drop in URL links anywhere I need to put them, I know that tutorial gives an option for a link, but that isnt the kind of thing I was after, so I have removed it from my news page scripts.

    So if anyone could help me with providing some actionscipt so I can do the <a href="http://www.test.com/" target="_blank">link</a> I would be very grateful, because its bugging me to hell LOL.

    Thanks in Advance.


  2. #2
    Senior Member
    Join Date
    Jan 2001
    Location
    IT
    Posts
    213
    Hi,
    I suppose you should use cdata tag: <![CDATA[]]>

    So the xml will look like this:
    <copy><![CDATA[<a href="http://www.test.com/" target="_blank">link</a>]]></copy>

    In this case, however, you'll have to set your textfield to HTML and use .htmlText instead of .text

    like this:
    txtCopy.html = true;
    txtCopy.htmlText = featuresArray[index].childNodes[1].firstChild.nodeValue.toString();

    hope that helps
    giano

  3. #3
    Junior Member
    Join Date
    Mar 2008
    Posts
    4
    yes that works, thanks!!!

  4. #4
    Junior Member
    Join Date
    Oct 2005
    Posts
    22
    Hi, sorry to revive an old post, but maybe you guys can help.

    I'm trying to do the same kind of thing, but when I use that code, it puts the target="_blank" at the end of my url. So I get:

    http://www.link.com/%22%20target=%22_blank



    Charming, huh?
    I don't remember seeing this problem before, but I'm at a loss. I have everything in a CDATA and printing to an HTML textfield. But jimminy-freaking-cricket!

  5. #5
    Senior Member
    Join Date
    Jan 2001
    Location
    IT
    Posts
    213
    Hi there callie17

    could post your files (.fla & .xml) so maybe we could have a look to them!

    giano

  6. #6
    Junior Member
    Join Date
    Mar 2008
    Posts
    4
    I got mine to open in a new tab/window by using the _blank

    PHP Code:
    <a href="http://www.google.com" target="_blank">HERE</a
    Last edited by Call Me V; 05-02-2008 at 01:41 PM.

  7. #7
    Junior Member
    Join Date
    Sep 2008
    Posts
    1
    I've registered to say cheers Giano I've been trying to get the links to work in XML for quite a while. A lot of internet searches turned up quite a few tutorials that skirted the issue but didn't quite address it. After google searching a slightly different criteria I find the solution clearly presented here.


    Thanks!

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