dcsimg
A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: text variable set

  1. #1
    Senior Member
    Join Date
    Feb 2003
    Posts
    129

    text variable set

    There's a dynamic text box with the variable name "score" in the main Flash area. In a movie clip, there's a button which, when pressed, should make the score variable (which begins at 0) increase by one. So for every press, 1 becomes 2, 2 becomes 3, etc.
    I have the code:

    on (press) {
    _root.score = _root.score+1;
    }

    However, this just makes the score become 11 instead of 2, 111 instead of 3, etc.
    What have I done wrong in the code in order for this to happen?
    Thanks for any help.

  2. #2
    Child Prodigy Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    551
    What you have to do is use a variable. Increment the variable by one each time, and then give the text box that variable's value like this:

    Code:
    on (press) {
    scoreVar = scoreVar+1;
    //This could also be written scoreVar += 1;
    _root.score.text = scoreVar;
    }

    Hope that helps.
    Rick
    Code:
      hobby = webDesign; waitYears(3);
      job = webDesign; this.love(job);

  3. #3
    Senior Member advance-media's Avatar
    Join Date
    Jan 2003
    Location
    URGENT: Germany but I'd like to work, live somewhere else, please help!
    Posts
    109
    Here U go!

    on (press) {
          _root.score = parseInt(_root.score)+1;
          _trace (_root.score);
    }


    Dancing with dynamic
    http://www.advance-media.com

  4. #4
    Child Prodigy Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    551
    pareInt - I've never used that function. I'm assuming that basically reads the text box and converts it to a variable, right?
    Code:
      hobby = webDesign; waitYears(3);
      job = webDesign; this.love(job);

  5. #5
    Senior Member advance-media's Avatar
    Join Date
    Jan 2003
    Location
    URGENT: Germany but I'd like to work, live somewhere else, please help!
    Posts
    109
    U need to check the FLASH help dictionary more frequently!

    parseInt (also look at parseFloat) converts the string to an integer (number) value in order to be able to use it for calculation.

    Best wishes
    http://www.advance-media.com

  6. #6
    Child Prodigy Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    551
    Thanks. I'll do that.
    Code:
      hobby = webDesign; waitYears(3);
      job = webDesign; this.love(job);

  7. #7
    Senior Member
    Join Date
    Aug 2002
    Posts
    121
    I dont understand, this worked for me:

    on (release) {
    score = ((score)+1);
    }


    -Nick
    -NickC-

  8. #8
    Senior Member
    Join Date
    Aug 2002
    Posts
    121
    This worked for me too...

    on (release) {
    score = score+1;
    }

    Please explain.
    -NickC-

  9. #9
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Because if you refer to the original question in this thread, score in this case is a text string in a textfield, and not an integer.

    If you preceded your tests with...

    score = "1";

    And tried...

    on (release) {
    score = score+1;
    trace(score);
    }

    The answer won't be what you got!

  10. #10
    Senior Member
    Join Date
    Aug 2002
    Posts
    121
    My first frame had
    score = 1;

    My second frame has a button with:
    on (release) {
    score = score+1;
    }

    and a dynamic text field called score.

    What am I not understanding....I try to learn from other peoples questions so excuse my persistance as I will excuse your curt response.
    -NickC-

  11. #11
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Ah! but your first frame had...

    score = 1;

    And not as I had...

    score = "1";

    Because as I said the variable in a textfield is a text string and not a value! So you must convert that text string into a value if you want to add the value of 1 to it.

    score = "1";
    trace (score + 1); // outputs "11"


    score = 1;
    trace (score + 1); // outputs 2

    So if score is a text string as it is in this case:

    score = "1";
    trace (parseInt(score)+1); // now outputs 2


    Curt enough for you this time?

  12. #12
    Senior Member
    Join Date
    Aug 2002
    Posts
    121
    Ahhhhhhhhhhhhhhh. Oui!
    and no...that one wasn't curt at all.

    curt
    Function: adjective
    Etymology: Latin curtus shortened -- more at SHEAR
    Date: 1630
    1 a : sparing of words : TERSE b : marked by rude or peremptory shortness : BRUSQUE
    2 : shortened in linear dimension
    -NickC-

  13. #13
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Yeah! Looked it up before I posted... http://dictionary.reference.com/translate/text.html

    But I really ment... "Was I rude enough for you this time?"

  14. #14
    Huygens to Titan PCRIDE's Avatar
    Join Date
    May 2002
    Location
    PLUTO
    Posts
    1,335
    I agree

  15. #15
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    With what? My rudeness?

  16. #16
    Senior Member
    Join Date
    Aug 2002
    Posts
    121
    I didn't consider you as being rude...
    I understand that you are French-Canadian.
    It's just your way!
    Cheers!
    -NickC-

  17. #17
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    I'm a Québecois first. A French-Canadian second, and a Canadian third!

  18. #18
    Child Prodigy Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    551
    Originally posted by Cornaglian
    ...so excuse my persistance as I will excuse your curt response.
    LMAO! I don't see how anybody can get any kind of rude / curt vibe from anybody else unless they say something like "F*** YOU!!" or something like that, you know? I mean, this isn't face to face so I find it quite hard to read people. (Then again, I find it hard to read people anyway...)

    I always try to take what I get from other people as best I can so I don't misinterpret it and upset someone for no reason.


    Just some thoughts
    Rick
    Code:
      hobby = webDesign; waitYears(3);
      job = webDesign; this.love(job);

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