Skip navigation
Currently Being Moderated

Help me please information..

Oct 29, 2011 7:59 PM

While I am having you people around, I might take advantage and ask the following:

 

I have 2 buttons and a textfield. I click the button A to input a number in the textfield, and then I click the button B to give me let's say the square root of that number in the same textfield. I have been stuck for 3 days. help!

 
Replies
  • Currently Being Moderated
    Oct 30, 2011 4:32 AM   in reply to Samsimms

    If it works, what needs correcting?

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 30, 2011 7:52 AM   in reply to Samsimms

    Since it is an input field and you haven't restricted typing into it, you should be able to "type" any values you wish into it.  If when you say "type" you are actually talking about clicking your button that assigns the String "  9" to the textfield, your code for that button is only assign that String, so it cannot do any better than that.  If you want to append another 9 to the String in the textfield, then you need to use the appendText() method.  But appending "  9" to "  9" will end up giving you "  9  9" which will not be a number value. 

     

    Try the following instead of what you have...

     

    import flash.events.Event;

    // Defining a TextField object instance
    var txt_inp:TextField = new TextField();

    txt_inp.type = "input";
    txt_inp.x = 100;
    txt_inp.y = 50;
    txt_inp.width = 100;
    txt_inp.height = 20;
    txt_inp.border = true;
    txt_inp.borderColor = 0x0000da;

    txt_inp.restrict = "0-9";

    txt_inp.maxChars = 5;
    txt_inp.multiline = false;
    txt_inp.text = '';

    addChild(txt_inp);

    buttonA.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

    function fl_MouseClickHandler(event:MouseEvent):void
    {
      txt_inp.appendText("9");
    }

    buttonB.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

    function fl_MouseClickHandler_2(event:MouseEvent):void
    {
      trace("Mouse clicked");
      var res:Number = Math.sqrt(Number(txt_inp.text));
      txt_inp.text = String(res);
    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points