A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Can you use Variable inside setSelection?

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    63

    Can you use Variable inside setSelection?

    This works:

    code:

    bt.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

    function fl_MouseClickHandler(event:MouseEvent):void
    {

    stage.focus = mt;
    mt.setSelection(5, 25);
    }



    Although the following does not work.

    code:

    var cs = "<MCAPI"
    var cf = "</MCAP>"

    bt.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

    function fl_MouseClickHandler(event:MouseEvent):void
    {

    stage.focus = mt;
    mt.setSelection(cs, cf);
    }



    Anyone know what I'm doing wrong?

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

    Thst because you need number values and not text values, try this I found and manipulated.

    PHP Code:
    const input:String "<MCAPI The quick brown fox jumped over the lazy dog.</MCAP>";

    var 
    cs "<MCAPI";
    var 
    cf "</MCAP>";

    function 
    getSubString(begin:Stringend:StringfullString:String):void
    {
        var 
    startIndex:Number fullString.indexOf(begin) + begin.length;
        
    //var endIndex:Number = fullString.indexOf(end) - 1;// first case of
        
    var endIndex:Number fullString.lastIndexOf(end);// last case of

        
    trace(fullString.substring(startIndexendIndex));

        
    stage.focus mt;
        
    mt.setSelection(startIndex,endIndex);
    }


    bt.addEventListener(MouseEvent.CLICKfl_MouseClickHandler);

    function 
    fl_MouseClickHandler(event:MouseEvent):void
    {
        
    getSubString(cs,cf,mt.text);// text value
        //getSubString(cs,cf,input);// written const


    ans a CS5 file

  3. #3
    Member
    Join Date
    Apr 2014
    Posts
    63
    Thank you FruitBeard

    I think there may be a more simple solution. Here is my XML feed i'm loading:

    http://us2.api.mailchimp.com/1.2/?me...cid=2cc39ee165

    Although when I load that in my AS it comes out looking like some mass amount of code so I used cstat.text = unescape(san); to make it look more like the above url (using the unescape feature) as you see it in your browser but then it puts all kinds of junk before and after the <MCAPI> and </MCAPI> tags resulting in the xml feed to not validate. Therefore instead of doing your script above could there maybe be a more simple loading script that could just load it in clean?

    Here is my code:

    code:

    btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

    function fl_MouseClickHandler(event:MouseEvent):void
    {

    var url = "method=campaignClickStats&output=xml&apikey=" + apiKey + "&cid=2cc39ee165";


    var variables:URLVariables = new URLVariables(url);
    var request:URLRequest = new URLRequest();
    request.url = "http://" + dataCenter + ".api.mailchimp.com/1.2/?method=campaignClickStats";
    request.method = URLRequestMethod.POST;
    request.data = variables;

    //create the loader
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, completeHandler);

    loader.load(request);


    }

    function completeHandler(e:Event) {

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


    }


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

    The xml is a tad messy when you get it yes,i got it to work like this, importing it as TEXT, then you can messa round with from within.
    PHP Code:
    btn.addEventListener(MouseEvent.CLICKfl_MouseClickHandler);

    function 
    fl_MouseClickHandler(event:MouseEvent):void
    {
        var 
    url "http://us2.api.mailchimp.com/1.2/?method=campaignClickStats&output=xml&apikey=d42ca0bbda36b2dce5e85bbf75841890&cid=2cc39ee165";
        var 
    request:URLRequest = new URLRequest(url);
        var 
    loader:URLLoader = new URLLoader();

        
    loader.dataFormat URLLoaderDataFormat.TEXT;
        
    loader.addEventListener(Event.COMPLETEcompleteHandler);
        
    loader.load(request);
    }

    function 
    completeHandler(e:Event)
    {
        var 
    san = new XML(e.target.data);
        
    cstat.text san;


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

    Even though the question changed dramatically from the first question of why is this not working (setSelection)
    This is possibly what you desire.

    PHP Code:
    btn.addEventListener(MouseEvent.CLICKfl_MouseClickHandler);

    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;

    function 
    fl_MouseClickHandler(event:MouseEvent):void
    {
        
    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);
    }

    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 *****");
        }
    }

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

    you might need to add some of the necessary imports at the start!!!
    Last edited by fruitbeard; 09-20-2014 at 04:52 AM. Reason: Typos

  6. #6
    Member
    Join Date
    Apr 2014
    Posts
    63
    i have tried soooo many things ... what you did in your first post worked and worked well. I thank you very much for the help. You really know your stuff

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