A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Adding to a URL

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    4

    Adding to a URL

    Hi I'm looking to create some actionscript for a button that goes something like this.

    The button is a link that opens up in a new window lets say the URL is "www.test.com/new.jsp?test="

    I've got the actionscript for that but what I want to be able to do is basically have another eventlistener for the click that uses an array that has a list of words that would go in after "test="

    So I have an array with a list of words like "word1, word2, word3, word4"

    On the first click of the button I want it to take me to "www.test.com/new.jsp?test=word1"

    On the second click of the button I want it to take me to "www.test.com/new.jsp?test=word2"

    On the third click of the button I want it to take me to "www.test.com/new.jsp?test=word3"

    etc.. I hope that made sense. I would greatly appreciate the help!

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Here's a small example
    Code:
    var idx:int = 0;
    var words:Array = ["word1", "word2", "word3", "word4"];
    var req:URLRequest = new URLRequest("www.test.com/new.jsp");
    
    button.addEventListener(MouseEvent.CLICK, lookupWord);
    
    function lookupWord(e:MouseEvent):void{
      var urlvars:URLVariables = new URLVariables();
      urlvars.test = words[idx];
      req.data = urlvars;
      navigateToURL(req);
      idx = (idx + 1) % words.length; //loops around after exhausting the array.
    }

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