A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: linking parsed text from xml data

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    63

    linking parsed text from xml data

    I have been searching the web with no success.

    I'm loading in content from an xml feed into my dynamic text box. How can I link parts of that xml data in the dynamic text box to a url?

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Take a look at this and learn from it, it's CS5 , I can not save any lower, you may need to get somebody to save it lower if needed, sorry.

    http://fruitbeard.net/uploaded/sand.zip

    It should get you through doing most of the xml things you require with the xml you are loading, plus the linking part.

    Please say when / if you obtain the file as I can then remove it, a weeks or so, whichever comes sooner.

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Me again, I forgot to show you how to incorporate css within the file, if you require the <a href>'s to stand out.
    If you have downloaded the file then simply swap all the code for the code below.

    PHP Code:
    // *** Imports;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.IOErrorEvent;

    import flash.net.URLLoader;
    import flash.net.URLRequest;

    import flash.text.StyleSheet;

    // *** Var creation/declarations;
    var urlPart:String "http://us2.api.mailchimp.com/1.2/?method=campaignClickStats&output=xml";
    var 
    apiKey:String "&apikey=d42ca0bbda36b2dce5e85bbf75841890";
    var 
    cid:String "&cid=2cc39ee165";

    var 
    xmlUrl:String;
    var 
    xmlLoader:URLLoader;
    var 
    xmlTarget:URLRequest;
    var 
    xmlLength:Number;
    var 
    xmlLinked:String;

    var 
    css:StyleSheet = new StyleSheet();

    // *** Css style;
    css.parseCSS('a:link {color:#59A188; textDecoration:none; fontSize:13;}');
    css.parseCSS('a:hover {color:#000000; textDecoration:underline; fontSize:13;}');

    // *** Load xml button
    btn.buttonMode true;
    btn.addEventListener(MouseEvent.CLICKfl_MouseClickHandler);

    // *** Button handler / load xml;
    function fl_MouseClickHandler(event:MouseEvent):void
    {
        
    // Clear fields
        
    cstat.text "";
        
    selectText.text "";

        
    xmlUrl String(urlPart) + String(apiKey) + String(cid);

        
    xmlLoader = new URLLoader();
        
    xmlTarget = new URLRequest(xmlUrl);
        
    xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,xmlError,false,0,true);
        
    xmlLoader.addEventListener(Event.COMPLETExmlComplete,false,0,true);
        
    xmlLoader.load(xmlTarget);
    }

    // *** Xml load complete, do traces etc etc;
    function xmlComplete(e:Event):void
    {
        
    xmlLoader.removeEventListener(IOErrorEvent.IO_ERROR,xmlError);
        
    xmlLoader.removeEventListener(Event.COMPLETExmlComplete);

        var 
    xmlImport = new XML(e.target.data);
        
    cstat.text xmlImport;

        
    xmlLength xmlImport.struct.length();
        
    trace("Structs: " xmlLength);

        for (var 
    i:Number 0xmlLengthi++)
        {
            
    trace("Struct: " String(1) + " -------- ");
            
    trace("Key:" xmlImport.struct[i].@key);
            
    trace("Type:" xmlImport.struct[i].@type);
            
    trace("Clicks:" xmlImport.struct[i].clicks);
            
    trace("Clicks type:" xmlImport.struct[i].clicks.@type);
            
    trace("Unique:" xmlImport.struct[i].unique);
            
    trace("Unique type:" xmlImport.struct[i].unique.@type);
            
    trace("***** End Struct *****");

            
    xmlLinked xmlImport.struct[i].@key;
            
    selectText.htmlText +=  "<a href='" xmlLinked "' target='_blank'>Struct Key: " " - Link Url</a>\n";
        }

        
    selectText.styleSheet css;

        
    scroller1.update();
        
    scroller2.update();
    }

    // *** Load error;
    function xmlError(e:IOErrorEvent):void
    {
        
    trace(e);


  4. #4
    Member
    Join Date
    Apr 2014
    Posts
    63
    wow you are really sharp. I've pulled the file and will exam that and the code above soon. Many thanks again.

  5. #5
    Member
    Join Date
    Apr 2014
    Posts
    63
    I got it working with:

    m_txt.htmlText += "<a href='" + surl +"'>" + allsub + "</a>\n\n";

    This outputs the xml data and links it.

    Although how do I make it so surl (containing my xml data) is displayed into m_txt instead of opening up in a web browser like it does now?

    Would I have to create a button that I assign surl to? Then use the button I created via AS OnClick > load this xml data?
    Last edited by sandman99; 10-02-2014 at 07:59 PM.

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