A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: copy textfield into another

  1. #1
    Member
    Join Date
    Jan 2003
    Location
    netherlands
    Posts
    34

    copy textfield into another

    Hello,

    I have a form with two textfields.
    In one textfield a visitor kan fill in a number.
    As soon as the visitor fills in the number, the other textfield must display this number but than times 2 (for now, later there will be a huge calculation). For example 10 in textfield1 becomes 20 in textfield2.

    This must happen very quickly without submitting a button.
    So if somebody want to type "100", he first has to type the "1".
    When he has done this, textfield2 must display "2"
    After the "1" becomes "0" so textfield2 displays "20".
    And after the "10" becomes another "0" so texfield2 displays "200"

    If this is unclear, plz let me know. I'll try to put this in other words.

    Tnx in advange,
    Gerjan

    p.s. I have done this before in javascript, see my attachment.
    Attached Files Attached Files

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    Here's a simple example:
    code:

    this.createTextField("t1", 1, 0, 0, 100, 20);
    t1.type = "input";
    t1.border = true;
    t1.restrict = "0-9";
    //
    this.createTextField("t2", 2, 0, 40, 100, 20);
    t2.border = true;
    //
    t1.onChanged = function()
    {
    t2.text = this.text * 2;
    };


    When you insert numbers in the first text field, the second updated itself thanks to the onChanged() method triggered by the first one.

  3. #3
    Member
    Join Date
    Jan 2003
    Location
    netherlands
    Posts
    34
    tnx for ure reply,
    i'll try and give you the results!
    Come gather 'round people
    Wherever you roam

  4. #4
    Member
    Join Date
    Jan 2003
    Location
    netherlands
    Posts
    34
    It's what I ment. I have it working now.

    There is only one thing;
    This is working fine when you use one textfield that effects the other.
    But now I want to use three fields, where two fields effects one.
    The values of the two fields you can change, will be used in a huge calculation. The outcome must be shown in the the third textfield.
    I don't see how this is possible now.
    Come gather 'round people
    Wherever you roam

  5. #5
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    It's exactly the same...
    code:

    this.createTextField("t1", 1, 0, 0, 100, 20);
    t1.type = "input";
    t1.border = true;
    t1.restrict = "0-9";
    //
    this.createTextField("t2", 2, 0, 40, 100, 20);
    t2.type = "input";
    t2.border = true;
    t2.restrict = "0-9";
    //
    this.createTextField("t3", 3, 0, 80, 100, 20);
    t2.border = true;
    //
    t1.onChanged = function()
    {
    t3.text = (t1.text != "" && t2.text != "") ? this.text * t2.text : "";
    };
    t2.onChanged = function()
    {
    t3.text = (t1.text != "" && t2.text != "") ? this.text * t1.text : "";
    };


    I just made sure that both input text fields weren't empty.

    Notice that
    code:

    t3.text = (t1.text != "" && t2.text != "") ? this.text * t2.text : "";
    // is the same as
    if (t1.text != "" && t2.text != "")
    {
    t3.text = this.text * t2.text;
    }
    else
    {
    t3.text = "";
    }


    and that the onChanged() methods can be written like this instead:
    code:

    t1.onChanged = function()
    {
    t3.text = (t1.text != "" && t2.text != "") ? t1.text * t2.text : "";
    };
    t2.onChanged = t1.onChanged;

    Last edited by nunomira; 08-17-2005 at 10:40 AM.

  6. #6
    Member
    Join Date
    Jan 2003
    Location
    netherlands
    Posts
    34
    Thank you very much.
    You helped me a lot!
    Come gather 'round people
    Wherever you roam

  7. #7
    Member
    Join Date
    Jan 2003
    Location
    netherlands
    Posts
    34

    create dropdown menu

    Is it also possible to create a dropdown menu in actionscript?

    Like you make a textfield in actionscript with:
    this.createTextField("t1", 1, 0, 0, 100, 20);
    Come gather 'round people
    Wherever you roam

  8. #8
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    It is, but if I were you, I'd search for one that's already made.

  9. #9
    Member
    Join Date
    Jan 2003
    Location
    netherlands
    Posts
    34
    one that is made with drawing instead of actionscript?
    Come gather 'round people
    Wherever you roam

  10. #10
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    It always requires ActionScript.
    So, a combination of the two.

  11. #11
    Member
    Join Date
    Jan 2003
    Location
    netherlands
    Posts
    34
    I think I have it almost now.
    The only thing I need is to call the function when you release a button in the dropdown menu and give a value to it.

    So for example, the button name is "color1" must give the value "color = 1" and call the same function as: t1.onChanged = function().
    Come gather 'round people
    Wherever you roam

  12. #12
    Member
    Join Date
    Jan 2003
    Location
    netherlands
    Posts
    34
    I think it's more clear to show you the .swf file, see the attachment.

    When you click on the grey buttons on the bottum, you see the textfield on the right go from 1 to 2.

    The only thing, nothing is happening with upper 2 fields.

    But when you edit the textfield on the right, manually... it does!

    So the T1.onChanged = function(), does only work if you change the field manualy.
    Is there a solution for this?
    Attached Files Attached Files
    Last edited by gerjanschoemake; 08-19-2005 at 06:58 AM.
    Come gather 'round people
    Wherever you roam

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