A Flash Developer Resource Site

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

Thread: Input text change with button help!

  1. #1
    Senior Member
    Join Date
    Aug 2009
    Posts
    113

    Input text change with button help!

    Hi! Using the text tool, I have made a Input Textbox with the instance name of voca2_pg and the other one is voca3_pg. It has a text inside: 1 and 11, respectively.

    Now I made a button that should send info to the input text that when I click the back button, text will change to a lower number, or when I click the next button it will change to a higher number.

    Example: (they are inside the textbox)

    2 12

    if I click next button, it will be: 3 13

    HOW???
    Last edited by ayusuits; 09-23-2009 at 12:17 AM.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    1st, you need a dynamic textfield, not an input. Select the fields and change them via the property panel. So voca2_pg and voca3_pg will be dynamic and display the changes.

    One thing i'll assume, because your explanation wasn't clear, that each field contains only one value, ie: voca2_pg has 1 and voca3_pg has 11.

    then, you set 2 variables with the default values (the ones you start with).
    PHP Code:
    var firstNum:Number 1;
    var 
    secondNum:Number 11
    you display these values in your dynamic textfields:
    PHP Code:
    voca2_pg.text=firstNum;
    voca3_pg.text=secondNum
    your buttons will add or retreive 1 from the 2 variables firstNum and secondNum and display them in the dynamic textfields:

    PHP Code:
    button1.onPress = function() {
    voca2_pg.text=firstNum 1;
    voca3_pg.text=secondNum 1;
    }; 
    same with the other, except you use firstNum-1 since you're going down.
    If there are boundries, for example you don't want them to go past 0 or another number, use an if statement, for example if(firstNum>0), etc.. or if(firstNum<9) etc.. (< means smaller than and > bigger than)

    gparis

  3. #3
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    if I change them into dynamic, clients wont be able to type some text right?

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    ok, then use this:

    PHP Code:
    button1.onPress = function() {
    voca2_pg.text++;
    voca3_pg.text++;
    }; 
    gparis

  5. #5
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    where do I put this?
    Code:
    button1.onPress = function() {
    voca2_pg.text=firstNum + 1;
    voca3_pg.text=secondNum + 1;
    };
    I pasted that in the frame where my button is, and when I tried it, the voca2_pg.text=firstNum; that is written in the textbox became NaN????

    Oh, it should be the action for the button T_T

    but if I put it inside the button

    I get this error: Statement must appear within on handler
    Last edited by ayusuits; 09-23-2009 at 01:42 AM.

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    use the above code (post4).

    gparis

  7. #7
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    this is what I get:

    Statement must appear within on handler

  8. #8
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    These codes:

    var firstNum:Number = 1;
    var secondNum:Number = 11;

    should be put in the VAR properties of the textbox?

    and

    voca2_pg.text=firstNum;
    voca3_pg.text=secondNum;

    should be typed in the textbox separately???

  9. #9
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    just paste post4 in a frame. first code was for dynamic textfields.

    gparis

  10. #10
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    yah, I figured it out now. thank you so much gparis

  11. #11
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    button1.onPress = function() {
    voca2_pg.text++;
    voca3_pg.text++;
    };

    what to do if I want it to stop at certain number like

    from: 1 11
    up to: 10 20

    only?

    i dont get this part:

    if(firstNum>0), etc.. or if(firstNum<9) etc.. (< means smaller than and > bigger than)
    Last edited by ayusuits; 09-23-2009 at 03:07 AM.

  12. #12
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    i used this but it is not working:

    Code:
    button1.onPress = function() { 
    if(firstNum<10)
    	voca2_pg.text--; 
    else if(firstNum<20)
    	voca3_pg.text--; 
    	}; 
    
    button2.onPress = function() { 
    if(firstNum>1)
    	voca2_pg.text++;
    else if(firstNum>11)
    	voca3_pg.text++; 
    	};

  13. #13
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    as there is no more firstNum, use voca2_pg (and3) instead.

    gparis

  14. #14
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    Ahh I got it. What if I want to add 10 instead of 1 when clicking on the button?

    ex. 1 - 11

    will go to

    11 - 21


    Can I still do it in AS2? Bec. I only know AS2 T_T poor me..

    And also, since it is an input textbox, when I type 1, voca3_pg will automatically will go to 11,
    when I type 10, voca3_pg will automatically go to 21... and so on..
    Last edited by ayusuits; 09-23-2009 at 11:36 PM.

  15. #15
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    voca2_pg.text++;

    Is the same than saying
    voca2_pg.text+=1;

    that is also shorthand for
    voca2_pg.text=voca2_pg.text+1;

    you have the choice.

    gparis

  16. #16
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    woooohhh... i will try that one so there should be =

    Thank you so much, actually Ive been searching that for hours but I think Im typing the wrong tags bec. I dont know howto call that.. hehe

  17. #17
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    how come the minus code is working but on the adding part it is not? They have the same code..

    PHP Code:
    minus_btn.onPress = function() { 
        
    voca2_pg.text-=10;
        
    voca3_pg.text-=10;
        }; 

    add_btn.onPress = function() { 
        
    voca2_pg.text+=10;
        
    voca3_pg.text+=10;
        }; 
    if I typed 10 - 20 and click the add button it will go like this:

    1010 - 2010
    101010 - 201010

  18. #18
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    ok, I already made it. thanks!

  19. #19
    Senior Member
    Join Date
    Aug 2009
    Posts
    113
    can I get this forum back to life?

    PHP Code:
    minus_btn.onPress = function() { 
        
    voca2_pg.text-=10
        
    voca3_pg.text-=10
        }; 

    add_btn.onPress = function() { 
        
    voca2_pg.text+=10
        
    voca3_pg.text+=10
        }; 

    if I typed 10 - 20 and click the add button it will go like this:

    1010 - 2010
    101010 - 201010


    not 10, 20, 30

  20. #20
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    convert the text to a number with Number()

    gparis

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