A Flash Developer Resource Site

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

Thread: store list id into variable from my xml feed

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    63

    store list id into variable from my xml feed

    I have a variable below called allid which has all the list id's for the generated campaigns. How can I detect which id is clicked below? I've tried many things but I'm stumped.

    code:


    btn_camp.addEventListener(MouseEvent.CLICK, fl_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,xmlE rror,false,0,true);
    loader.addEventListener(Event.COMPLETE, completeHandler,false,0,true);
    loader.load(requester);
    }

    // *** Initial xml load complete
    function completeHandler(e:Event)
    {
    loader.removeEventListener(Event.COMPLETE, completeHandler);
    loader.removeEventListener(IOErrorEvent.IO_ERROR,x mlError);

    san = new XML(e.target.data);
    nOfCamp = san.*.subject.length();

    for (i = 0; i< nOfCamp; i++)
    {
    allsub = san.*.subject[i].text();
    allid = san.*.id[i].text();
    ourl = "http://" + dataCenter + ".api.mailchimp.com/1.2/?method=campaignStats&output=xml&apikey=" + apiKey + "&cid=" + allid;
    m_txt.htmlText += "<a href='event:" + ourl + "'>" + allsub + "</a>\n\n";
    m_txt.addEventListener(TextEvent.LINK, linkEvent,false,0,true);
    }

    }

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

    }

    // *** Link text load complete;
    function linkComplete(e:Event):void
    {

    linkLoader.removeEventListener(IOErrorEvent.IO_ERR OR,xmlError);
    linkLoader.removeEventListener(Event.COMPLETE, linkComplete);
    linkImport = new XML(e.target.data);
    nOfO = linkImport.opens.text();
    m_txt.text = "Opens = " + nOfO + " \n";
    }

    function xmlError(e:IOErrorEvent):void
    {
    trace(e);
    }



    S

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

    This might put you in the right direction, as I'm not sure where or how you wish to show the id result.

    Code:
    btn_camp.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler1);
    
    // vars here
    
    function fl_MouseClickHandler1(event:MouseEvent):void
    {
    	m_txt.text = "";
    	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.COMPLETE, completeHandler,false,0,true);
    	loader.load(requester);
    }
    
    // *** Initial xml load complete
    function completeHandler(e:Event)
    {
    	loader.removeEventListener(Event.COMPLETE, completeHandler);
    	loader.removeEventListener(IOErrorEvent.IO_ERROR, xmlError);
    
    	san = new XML(e.target.data);
    
    	nOfCamp = san.*.subject.length();
    
    	for (i = 0; i < nOfCamp; i++)
    	{
    		allsub = san.*.subject[i].text();
    
    		allid = san.*.id[i].text();
    
    		ourl = "http://" + dataCenter + ".api.mailchimp.com/1.2/?method=campaignStats&output=xml&apikey=" + apiKey + "&cid=" + allid;
    
    		//m_txt.htmlText +=  "<a href='event:" + ourl + "'>" + allsub + "</a>\n\n";
    		m_txt.htmlText +=  "<a href='event:" + ourl + "|||" + allid + "'>" + allsub + "</a>\n\n";
    		m_txt.addEventListener(TextEvent.LINK, linkEvent,false,0,true);
    	}
    }
    
    var splitLinks:Array = new Array();
    
    // *** Link text from xml - to other text box
    function linkEvent(e:TextEvent):void
    {
    	splitLinks = e.text.split("|||");
    
    	linkLoader = new URLLoader();
    	//linkTarget = new URLRequest(e.text);
    	linkTarget = new URLRequest(splitLinks[0]);
    
    	linkLoader = new URLLoader();
    	linkLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlError,false,0,true);
    	linkLoader.addEventListener(Event.COMPLETE, linkComplete,false,0,true);
    	linkLoader.load(linkTarget);
    }
    
    // *** Link text load complete;
    function linkComplete(e:Event):void
    {
    	linkLoader.removeEventListener(IOErrorEvent.IO_ERROR, xmlError);
    	linkLoader.removeEventListener(Event.COMPLETE, linkComplete);
    
    	linkImport = new XML(e.target.data);
    
    	nOfO = linkImport.opens.text();
    
    	//m_txt.text = "Opens = " + nOfO + " \n";
    	m_txt.htmlText = "Opens = " + nOfO + " \n<font color='#ff5500'>id= " + splitLinks[1] + "</font>";
    }
    
    function xmlError(e:IOErrorEvent):void
    {
    	trace(e);
    }
    As you can see, I have added the red lines and swapped the blue lines for the purple lines.

    Good luck

  3. #3
    Member
    Join Date
    Apr 2014
    Posts
    63
    thank you fruitbeard

    I want to store the allid clicked into a variable and use it later with a different url. Therefore the above is either click a link with the allid or without. I will play around with what you've put and see if I can get it.

    What I'm trying to do is that the above allows the user to click on the ourl which outputs the data from it's corresponding url (http://" + dataCenter + ".api.mailchimp.com/1.2/?method=campaignStats&output=xml&apikey=" + apiKey + "&cid=" + allid

    Then I want to be able to click on that data output and output a different url say

    surl = http://" + dataCenter + ".api.mailchimp.com/1.2/?method=campaignUnsubscribes&output=xml&apikey=" + apiKey + "&cid=" + allid;

    Thank you again Fruitbeard

    S

  4. #4
    Member
    Join Date
    Apr 2014
    Posts
    63
    Also could you explain this one to me:

    linkTarget = new URLRequest(splitLinks[0]);

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

    I'm still not sure what you require, but I can explain the part you wanted me to.

    Code:
    // data that is to be split from previous function
    <a href='event:" + ourl + "|||" + allid + "'>" + allsub + "</a>
    
    // Create an Array to store split data
    var splitLinks:Array = new Array();
    
    // *** Link text from xml - to other text box
    function linkEvent(e:TextEvent):void
    {
    	// split the data using ||| as the splitter
    	splitLinks = e.text.split("|||");
    
    	linkLoader = new URLLoader();
    	// splitLinks[0] is the first part of splitLinks array - ourl
    	linkTarget = new URLRequest(splitLinks[0]);
    
    	linkLoader = new URLLoader();
    	linkLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlError,false,0,true);
    	linkLoader.addEventListener(Event.COMPLETE, linkComplete,false,0,true);
    	linkLoader.load(linkTarget);
    }
    
    //further down in the code
    // splitLinks[1] is the second part of splitLinks array - allid
    Opens = " + nOfO + " \n<font color='#ff5500'>id= " + splitLinks[1] + "</font>
    so basically the part that I think you require is splitLinks[1] (allid).
    Last edited by fruitbeard; 11-23-2014 at 04:22 AM.

  6. #6
    Member
    Join Date
    Apr 2014
    Posts
    63
    I think this will help.

    The above displays a list of items. Say there are 10 items displayed. Each displayed item has an ID (variable allid above). So when you click on the first item it knows which data to pull up based on the allid value and when you click on the second item it knows because of the allid value for the second item and so forth.

    What I can't figure out is how to trace the allid value of the item that's clicked. When I do a trace(allid) it displays the same allid value each time. If I do a trace(allid) in the for loop then it outputs all 10 allid values for all 10 items. But I want to know what the allid value is for the item the user clicks. It's all working correctly as each of the 10 items displays it's corresponding information. But no matter where I do a trace it won't tell me what the allid value is for that item clicked (keeps tracing the same one unless in the for loop in which case it spits out all 10)

    S

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

    Not sure how you end up with the trace you say you have as you never show the code.

    Have tried using a simple trace(splitLinks[1]); inside of function linkEvent

    or more suitably inside of function linkComplete

  8. #8
    Member
    Join Date
    Apr 2014
    Posts
    63
    I'm referring to the original script above in the first post (the split feature you've put is very useful but not needed for what I'm trying to get). By the time it's got to function linkComplete it's already selected a link containing one of the 10 allid in it. I want to find out from the script above how to trace the allid that is clicked. The script is working but I don't know how to trace which of the 10 links that gets clicked by the user.

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

    Right, I'm still not sure of what you mean, no matter how much you try to explain it.

    1: Press button to load all links into textfield.
    2: Press any link in texfield.
    3: Trace the allid of this link that is clicked, or, trace the allid of the link that it loads (if it has one).

  10. #10
    Member
    Join Date
    Apr 2014
    Posts
    63
    Hello

    1. is correct
    2. is correct
    3. When one of the 10 loaded links is clicked it has a unique ID (allid) different to the other 9 links. Therefore I'm trying to do a trace to figure out the id (allid) of the link that is clicked. For example, lets say link one has an allid of "aa" and link two has an allid of "bb" and link three has an allid of "cc" and etc. If I do a trace of allid in the for loop I get this:

    aa
    bb
    cc
    dd
    ee
    ff
    gg
    hh
    ii
    jj

    Now if I do a trace(allid) outside of the for loop it traces "aa" even though I'm clicking on link number 5 or link number 3 or etc. Therefore how do I get it to trace the actual allid of the link that is clicked.

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

    The code I gave you before does exactly what you are asking for, perhaps you have not implemented it correctly.

    Attach your *.fla so we can correct it.

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

    CS5, You will need to add the apiKey to the code before testing.

  13. #13
    Member
    Join Date
    Apr 2014
    Posts
    63
    Thank you for this. Although the problem with this is that the link url gets altered so it won't work but it does trace the allid.

    For example if i had something working like this:

    a variable named "Random" that will be assigned either ".com" or ".ca" or ".net" depending on which option the user clicks. Then

    var ending:String = Random;
    <a href='event:"http://www.google" + ending + "'>" + Google + "</a>

    This works but if I do the following which is what I see your latest code doing then it won't because it alters the url:

    <a href='event:"http://www.google" + "|||" + ending + "'>" + Google + "</a>

    Therefore I would like to trace the "ending" variable (or in the case of the code above "allid").

    you see in the code above the for loop creates say 10 random items each with their own unique url. I need to trace which URL (or allid) is associated with the link they clicked in the linkEvent function.

    Let me know if that makes sense.

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

    Look at the code again.

    m_txt.htmlText += "<a href='event:" + ourl + "|||" + allid + "'>" + allsub + "</a>\n\n";
    Code:
    function linkEvent(e:TextEvent):void
    {
    	splitLinks = e.text.split("|||");// splits link text into two using |||
    	trace(splitLinks[0]);// traces, first part of url - ourl
    	trace(splitLinks[1]);// traces, second part of url - allid
    	
    	linkLoader = new URLLoader();
    	linkTarget = new URLRequest(splitLinks[0]);// loads, first part of url
    	
    	linkLoader = new URLLoader();
    	linkLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlError,false,0,true);
    	linkLoader.addEventListener(Event.COMPLETE, linkComplete,false,0,true);
    	linkLoader.load(linkTarget);
    	
    	//navigateToURL(new URLRequest(splitLinks[0]), "_blank");// opens, first part of url - optional
    }

  15. #15
    Member
    Join Date
    Apr 2014
    Posts
    63
    Therefore if you get the link www.google.com and make it www.google ||| .com then how would that link work? ourl + allid equals a seemless url. Therefore if you break it up with ||| inbetween that link will not work.

    The link needs to be constant:

    www.google.com
    www.google.net
    www.google.ca

    Therefore I want to find out information on the link that they clicked. did they click the .net one or the .com one or etc

    Does that make sense?

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

    I have a feeling you have never tested the code or the files attached since the beginning.

    the splitText only uses ||| as a separation guide, it also removes it from the url and makes two from the long one.

    Also it actually has the full url in the first part and only uses the allid added on as extra, it is in no way part of the first url.

    please do traces and test more

    the code actually worls like so

    www.google.com ||| com
    www.google.net ||| net
    www.google.ca ||| ca

    you must be doing something awfully wrong

    This might clarify things for you,

    your original url forming code

    ourl = "http://" + dataCenter + ".api.mailchimp.com/1.2/?method=campaignStats&output=xml&apikey=" + apiKey + "&cid=" + allid;

    new split code for tracing the allid

    m_txt.htmlText += "<a href='event:" + ourl + "|||" + allid + "'>" + allsub + "</a>\n\n";
    Last edited by fruitbeard; 12-03-2014 at 02:14 PM.

  17. #17
    Member
    Join Date
    Apr 2014
    Posts
    63
    Thank you. I did download the file and test it. It traced but the link did not work. Although with your explanation I should be able to troubleshoot it. Will let you know. Thank you!

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

    Here is a file for you, last one ( I hope)

    I have sent you the password in PM

    http://fruitbeard.net/uploaded/sandfile.php

  19. #19
    Member
    Join Date
    Apr 2014
    Posts
    63
    Hello Fruitbeard

    With your great explanation above it's worked. Thank you very much for that once again.

    It's almost done now. Below is the script minus the variable definitions at the start of the script. I've added a function called ucompleteHandler but it's outputting the results from the function completeHandler instead of the xml data from the variable surl (which is in function fl_MouseClickHandler2). Do you know what I'm doing wrong?

    [ph]

    stop();

    var dataCenter:String = "us2";
    var apiKey:String = key;
    var splitLinks:Array = new Array();
    dest.visible=false;
    u.visible=false;

    btn_camp.addEventListener(MouseEvent.CLICK, fl_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,xmlE rror,false,0,true);
    loader.addEventListener(Event.COMPLETE, completeHandler,false,0,true);
    loader.load(requester);
    }

    // *** Initial xml load complete
    function completeHandler(e:Event)
    {
    loader.removeEventListener(Event.COMPLETE, completeHandler);
    loader.removeEventListener(IOErrorEvent.IO_ERROR,x mlError);

    san = new XML(e.target.data);
    nOfCamp = san.*.subject.length();

    for (i = 0; i< nOfCamp; i++)
    {
    allsub = san.*.subject[i].text();
    allid = san.*.id[i].text();
    ourl = "http://" + dataCenter + ".api.mailchimp.com/1.2/?method=campaignStats&output=xml&apikey=" + apiKey + "&cid=" + allid;
    m_txt.htmlText += "<a href='event:" + ourl + "|||" + allid + "'>" + allsub + "</a>\n\n";
    m_txt.addEventListener(TextEvent.LINK, linkEvent,false,0,true);
    }

    }

    // *** Link text from xml - to other text box
    function linkEvent(e:TextEvent):void
    {
    splitLinks = e.text.split("|||");
    TargetList = splitLinks[1];
    linkTarget = new URLRequest(splitLinks[0]);
    linkLoader = new URLLoader();
    linkLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlError,false,0,true);
    linkLoader.addEventListener(Event.COMPLETE, linkComplete,false,0,true);
    linkLoader.load(linkTarget);
    }


    // *** Link text load complete;
    function linkComplete(e:Event):void
    {

    linkLoader.removeEventListener(IOErrorEvent.IO_ERR OR,xmlError);
    linkLoader.removeEventListener(Event.COMPLETE, linkComplete);
    linkImport = new XML(e.target.data);
    trace(TargetList);
    nOfO = linkImport.opens.text();
    nOfSt = linkImport.clicks.text();
    nOfU = linkImport.unique_clicks.text();
    nOfUn = linkImport.unsubscribes.text();
    nOfF = linkImport.forwards.text();
    nOfCom = linkImport.abuse_reports.text();
    u.visible = true;
    m_txt.htmlText = "Clicks = " + nOfSt + "\n and Opens = " + nOfO + "\n Unique Clicks = " + nOfU + "\n Unsubscribes = <font color='#ff5500'>" + nOfUn + "</font>\n Forwards = " + nOfF + "\n Compliants = " + nOfCom + "\n";
    }

    u.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler2);

    function fl_MouseClickHandler2(event:MouseEvent):void
    {
    surl = "http://" + dataCenter + ".api.mailchimp.com/1.2/?method=campaignUnsubscribes&output=xml&apikey=" + apiKey + "&cid=" + TargetList;
    requester4 = new URLRequest(surl);
    loader4 = new URLLoader();
    loader4.addEventListener(IOErrorEvent.IO_ERROR,xml Error,false,0,true);
    loader4.addEventListener(Event.COMPLETE, ucompleteHandler,false,0,true);
    loader4.load(requester);

    }

    function ucompleteHandler(e:Event)
    {
    loader4.removeEventListener(Event.COMPLETE, ucompleteHandler);
    loader4.removeEventListener(IOErrorEvent.IO_ERROR, xmlError);

    san4 = new XML(e.target.data);
    trace(TargetList);
    dest.visible=true;
    dest.dstat.text=san4;
    }


    function xmlError(e:IOErrorEvent):void
    {
    trace(e);
    }

    [/ph]

  20. #20
    Member
    Join Date
    Apr 2014
    Posts
    63
    this view may be easier to read

    PHP Code:

    stop
    ();

    var 
    dataCenter:String "us2";
    var 
    apiKey:String key;
    var 
    splitLinks:Array = new Array();
    dest.visible=false;
    u.visible=false;

    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,xmlE rror,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,x mlError);

    san = new XML(e.target.data);
    nOfCamp san.*.subject.length();

    for (
    0inOfCampi++)
    {
    allsub san.*.subject[i].text();
    allid san.*.id[i].text();
    ourl "http://" dataCenter ".api.mailchimp.com/1.2/?method=campaignStats&output=xml&apikey=" apiKey "&cid=" allid;
    m_txt.htmlText += "<a href='event:" ourl "|||" allid "'>" 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
    {
    splitLinks e.text.split("|||");
    TargetList splitLinks[1];
    linkTarget = new URLRequest(splitLinks[0]);
    linkLoader = new URLLoader();
    linkLoader.addEventListener(IOErrorEvent.IO_ERRORxmlError,false,0,true);
    linkLoader.addEventListener(Event.COMPLETElinkComplete,false,0,true);
    linkLoader.load(linkTarget);
    }


    // *** Link text load complete;
    function linkComplete(e:Event):void
    {

    linkLoader.removeEventListener(IOErrorEvent.IO_ERR OR,xmlError);
    linkLoader.removeEventListener(Event.COMPLETElinkComplete);
    linkImport = new XML(e.target.data);
    trace(TargetList);
    nOfO linkImport.opens.text();
    nOfSt linkImport.clicks.text();
    nOfU linkImport.unique_clicks.text();
    nOfUn linkImport.unsubscribes.text();
    nOfF linkImport.forwards.text();
    nOfCom linkImport.abuse_reports.text();
    u.visible true;
    m_txt.htmlText "Clicks = " nOfSt "\n and Opens = " nOfO "\n Unique Clicks = " nOfU "\n Unsubscribes = <font color='#ff5500'>" nOfUn "</font>\n Forwards = " nOfF "\n Compliants = " nOfCom "\n";
    }

    u.addEventListener(MouseEvent.CLICKfl_MouseClickHandler2);

    function 
    fl_MouseClickHandler2(event:MouseEvent):void
    {
    surl "http://" dataCenter ".api.mailchimp.com/1.2/?method=campaignUnsubscribes&output=xml&apikey=" apiKey "&cid=" TargetList;
    requester4 = new URLRequest(surl);
    loader4 = new URLLoader();
    loader4.addEventListener(IOErrorEvent.IO_ERROR,xml Error,false,0,true);
    loader4.addEventListener(Event.COMPLETEucompleteHandler,false,0,true);
    loader4.load(requester);

    }

    function 
    ucompleteHandler(e:Event)
    {
    loader4.removeEventListener(Event.COMPLETEucompleteHandler);
    loader4.removeEventListener(IOErrorEvent.IO_ERRORxmlError);

    san4 = new XML(e.target.data);
    trace(TargetList);
    dest.visible=true;
    dest.dstat.text=san4;
    }


    function 
    xmlError(e:IOErrorEvent):void
    {
    trace(e);


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