A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: link xml data to load into text box instead of browser

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    63

    link xml data to load into text box instead of browser

    I'm loading in xml data into my dynamic text box. Then I'm linking the loaded data which then opens in a web browser. Here is the code doing this:

    code:

    m_txt.htmlText += "<a href='" + surl +"'>" + allsub + "</a>\n\n";
    //allsub is loaded data. surl is the part of allsub that is being linked



    How do I make it so this data (surl) loads into a dynamic text box instead of opening up in a browser?

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

    You might need to elaborate a little.

    Do you mean the url(text only) appear in a text box, or the actual web page content that it leads to appear in a text box.
    As the latter is not really possible

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

    It will probably involve addEventListener(TextEvent.LINK, function);

    so swapping stuff around like so
    PHP Code:
            m_txt.htmlText += "<a href='event:" surl "'>" allsub "</a>\n\n";
        }
        
    m_txt.addEventListener(TextEvent.LINKlinkEvent,false,0,true);

    and the function for the textEvent like so
    PHP Code:
    function linkEvent(e:TextEvent):void
    {
        
    trace(e.text);
        
    //code to load new xml into data box here!!
        // or
        //navigateToURL(new URLRequest(e.text), "_blank");


  4. #4
    Member
    Join Date
    Apr 2014
    Posts
    63
    To clarify.

    The above loads in XML data into a dynamic text field.

    The command you gave me earlier m_txt.htmlText allows me to create this loaded xml data (in the dyanamic text box) into a link. Although when I click on this link it opens that content (aka link to xml feed) in a web browser.

    I want to click on this link in the dyanamic text box and have m_txt be assigned whatever I want it to be assigned. This is easy to do if I was clicking on a button for example and then having an action assigned to a dynamic text box to XYZ for example. But I don't know how to make a link in the dynamic text box load content into another dynamic text box (instead it opens the content in the web browser because of the <a href.... )

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

    I gave you the code to do it, post #3.

    you just need to assign another loader to the linkEvent function.

    from earlier posts you have made and from the code you have given in these posts, the links I have open up web pages and not new xml feeds.

    if you were to attach your current *.fla and any other necessary files, it would make things considerably easier for everybody helping, instead of having to try and make a probably not the same file of our own.

  6. #6
    Member
    Join Date
    Apr 2014
    Posts
    63
    Here's my code which works but just opens the loaded xml data that it links in a new browser.

    code:

    stop();
    var dataCenter:String = "us2";
    var apiKey:String = key;


    btn_camp.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler1);

    function fl_MouseClickHandler1(event:MouseEvent):void
    {
    var url = "http://" + dataCenter + ".api.mailchimp.com/1.2/?method=campaigns&output=xml&apikey=" + apiKey;
    var request:URLRequest = new URLRequest(url);
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.TEXT;
    loader.addEventListener(Event.COMPLETE, completeHandler);
    loader.load(request);
    }

    function completeHandler(e:Event)
    {

    var san = new XML(e.target.data);
    var NofCamp = san.*.subject.length();
    for(var i:Number = 0; i<NofCamp; i++) {
    var allsub:String = san.*.subject[i].text();
    var allid = san.*.id[i].text();
    var surl = "http://" + dataCenter + ".api.mailchimp.com/1.2/?method=campaignClickStats&output=xml&apikey=" + apiKey + "&cid=" + allid;
    m_txt.htmlText += "<a href='" + surl +"'>" + allsub + "</a>\n\n";
    m_txt.addEventListener(TextEvent.LINK, linkEvent,false,0,true);
    //m_txt.addEventListener(TextEvent.LINK, linkEvent);
    //function linkEvent(e:TextEvent):void
    //{
    // trace("works");
    //}
    }

    }


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

    Once a week replying is a pretty slow project, but nevermind.

    It seems that you have reverted to your original non working code, you have not used any of the code or files given.
    Apart from the last little bit of code (not even all of it) which you did put in the wrong place.

    I feel that I am unable to help you any more unless you give us the full code(file is better) and associated parts to work with.
    Like the correct numbers to work with instead of allid and key.


    Good luck
    Last edited by fruitbeard; 10-07-2014 at 01:11 AM.

  8. #8
    Member
    Join Date
    Apr 2014
    Posts
    63
    key is entered by the user on the login screen which is from their mailchimp account so it's different every time

    AllID is pulling the stats numbers from the xml file (parsed)

    The code you see works and does everything required thus far. Just the linking opens in in new browser due to <a href .... when I would like that to open up in a dynamic text box.

    I will PM you the file because it has info for my account which I cannot post to an open forum.

    Although keep in mind that the above is the full code minus one frame before which stores what the user enters into an input text field into the variable Key.

    I greatly appreciate all your help thus far. I cannot thank you enough.

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

    PHP Code:
    stop();

    var 
    dataCenter:String "us2";
    var 
    apiKey:String KEY;

    var 
    loader:URLLoader;
    var 
    requester:URLRequest;
    var 
    url:String;

    var 
    san:XML;
    var 
    nOfCamp:Number;
    var 
    i:Number;
    var 
    allsub:String;
    var 
    allid:String;
    var 
    surl:String;

    var 
    linkLoader:URLLoader;
    var 
    linkTarget:URLRequest;
    var 
    linkImport:XML;

    btn_camp.addEventListener(MouseEvent.CLICKfl_MouseClickHandler1);

    function 
    fl_MouseClickHandler1(event:MouseEvent):void
    {
        
    url "http://" dataCenter ".api.mailchimp.com/1.2/?method=campaigns&output=xml&apikey=" apiKey;
        
    requester = new URLRequest(url);
        
    loader = new URLLoader();
        
    loader.addEventListener(IOErrorEvent.IO_ERROR,xmlError,false,0,true);
        
    loader.addEventListener(Event.COMPLETEcompleteHandler,false,0,true);
        
    loader.load(requester);
    }

    // *** Initial xml load complete
    function completeHandler(e:Event)
    {
        
    loader.removeEventListener(Event.COMPLETEcompleteHandler);
        
    loader.removeEventListener(IOErrorEvent.IO_ERROR,xmlError);
        
        
    san = new XML(e.target.data);
        
    nOfCamp san.*.subject.length();
        
        for (
    0inOfCampi++)
        {
            
    allsub san.*.subject[i].text();
            
    allid san.*.id[i].text();
            
    trace(allid);
            
    surl "http://" dataCenter ".api.mailchimp.com/1.2/?method=campaignClickStats&output=xml&apikey=" apiKey "&cid=" allid;
            
    m_txt.htmlText +=  "<a href='event:" surl "'>" allsub "</a>\n\n";
            
    m_txt.addEventListener(TextEvent.LINKlinkEvent,false,0,true);
        }
    }

    // *** Link text from xml - to other text box
    function linkEvent(e:TextEvent):void
    {
        
    trace(e.text);
        
        
    linkLoader = new URLLoader();
        
    linkTarget = new URLRequest(e.text);
        
    linkLoader.addEventListener(IOErrorEvent.IO_ERROR,xmlError,false,0,true);
        
    linkLoader.addEventListener(Event.COMPLETElinkComplete,false,0,true);
        
    linkLoader.load(linkTarget);
        
    //navigateToURL(new URLRequest(e.text), "_blank");
    }

    // *** Link text load complete;
    function linkComplete(e:Event):void
    {
        
    mstat.text "";
        
    linkLoader.removeEventListener(IOErrorEvent.IO_ERROR,xmlError);
        
    linkLoader.removeEventListener(Event.COMPLETElinkComplete);

        
    linkImport = new XML(e.target.data);
        
    mstat.text linkImport;
        
    //mstat.htmlText = linkImport;
    }

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

    Last edited by fruitbeard; 10-08-2014 at 11:10 AM.

  10. #10
    Member
    Join Date
    Apr 2014
    Posts
    63
    on a quick glance that looks great. Thank you once again! I see how you defined all the variables above. I will make a habit of doing that from the start moving forward.

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