CS3 Adding an integer to a variable & getURL question (AS2/AS3)
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Adding an integer to a variable & getURL question (AS2/AS3)

  1. #1
    Junior Member
    Join Date
    Feb 2002
    Posts
    9

    Adding an integer to a variable & getURL question (AS2/AS3)

    I have been stuck on AS2 for a long, long time, and I want to learn AS3 but I don't really know where to start with things that should be relatively simple. I'll start, actually, with my getURL question.

    I have an old, Flash MX file that attempts to load URLs based on a "while" command, and so what that file does is add strings to form a URL which is then opened in a browser. The "while" works until the "counter" variable reaches 0. For example, this forum is located at: <http://board.flashkit.com/board/forumdisplay.php?29>. My old Flash MX file would take that address then add one to the number 29 for as long as the "counter" had value, so if you started with "5," the file would load URL <http://board.flashkit.com/board/forumdisplay.php?29>, then <http://board.flashkit.com/board/forumdisplay.php?30>, then <http://board.flashkit.com/board/forumdisplay.php?31>, and so on and so forth until <http://board.flashkit.com/board/forumdisplay.php?33>.

    Back when I made the file everything worked in sequential order (29, 30, 31), but now when I run it modern browsers respond seemingly random (30, 29, 31, 33, 34).

    on (release) {
    while (countdown > 0) {
    countdown = eval("countdown") - 1;
    full = eval("front") + eval("middle") + eval("end");
    getURL(eval("full"), "_blank");
    middle = number(middle) + 1;
    }
    countdown = eval("countdown") + 5;
    }

    Front is the beginning of the URL, like <http://board.flashkit.com/board/forumdisplay.php?>, middle is the number, like 29, and end is anything that needs to go after. Now, the above is AS2. Anyone know why the URL would be loading in random order?

    The second part should be a much easier question. In AS3, how do I add an integer to a variable for display in a text field? What I want to do is click a button to have a text field increase + 1.

    MyTextField.text = "10";
    One.addEventListener(
    MouseEvent.CLICK,
    function(evt:MouseEvent):void {
    MyTextField.text = MyTextField + 1;
    }
    );

    The above formula turns MyTextField into "[object TextField]1," whereas I want it to evaluate the value of MyTextField then add 1 every time I click on the button One (so the first click would yield 11).

    Thanks!
    Last edited by G.v.P; 05-17-2013 at 06:13 AM.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    105
    If I were wanting to update the content in a textfield, I would create a variable that holds the data of your starting value then assign that variable to your text field. then have a 2nd variable that holds how many times your button has been clicked and add those two together.

    See below

    Code:
    var startingValue:uint = 10;
    var counter:uint=1;
    
    MyTextField.text = String(startingValue);
    One.addEventListener(
    MouseEvent.CLICK,
    function(evt:MouseEvent):void {
    MyTextField.text = String(startingValue + counter);
    counter++
    }
    );

  3. #3
    Junior Member
    Join Date
    Feb 2002
    Posts
    9
    Ahh, I see, so get rid of the undefined + 1 and just make everything a variable. Okay. I'm so used to Number, hehe.

    I will test that out, thank you. counter++ does the trick! Now to tackle getURL in AS3 ;D.

  4. #4
    Junior Member
    Join Date
    Feb 2002
    Posts
    9
    Okay, so in using the code provided by jkell (thank you) I am going in the right direction, but I am still not familiar with how counter++ works. I tried to enter a new while condition, but the while condition is not operating how I would like:

    while (Number(MyTextField.text) > 0){
    full.text = String(body.text + count.text + ext.text);
    navigateToURL (new URLRequest (String(full.text)), "_blank");
    currentValue = Number(MyTextField.text);
    MyTextField.text = String(currentValue - countOne);
    countCurrent = Number(count.text);
    count.text = String(countCurrent + countOne);
    }

    Okay, so what I want to do is have it so a serial URL address will continue to load until the MyTextField reaches 0. What the above code does is it will add to the count.text, or the "29" in <http://board.flashkit.com/board/forumdisplay.php?29>, and the default for MyTextField is 5, so the full.text will end up being <http://board.flashkit.com/board/forumdisplay.php?33> (the while command starts with 29). What I want to happen is I want 5 websites to load in "_blank," but what I'm getting is only the last of the 5--<http://board.flashkit.com/board/forumdisplay.php?33>--to load.

    I am thinking I need to add something similar to counter++ at the end, but I'm not sure how to write it. Any suggestions?

    Edit: Hrm, this forum suggests I can only do one navigatetoURL per frame

    http://www.actionscript.org/forums/s....php3?t=250594

    Flash is only able to execute one navigateToURL function per frame. A player problem, unfortunately.
    If that's true I'll have to check out Timers or use multiple frames, I suppose. Nuts.
    Last edited by G.v.P; 05-18-2013 at 11:19 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