Skip navigation
TwistedPixel23
Currently Being Moderated

Dynamic TextField Array Help

Jul 11, 2012 8:45 AM

Tags: #dynamic #array #textfield

I want to be able to trace what the user has entered into the textbox, how do i go about it..

 

 

 

[AS]

quantityMenu.XXXSinput.addEventListener(KeyboardEvent.KEY_UP,XXXSupdateTextfield) 

function XXXSupdateTextfield(evt:KeyboardEvent):void{

//----------------------------------------------        

//----------------------------------------------

var num_clips:int = 999;

//----------------------------------------------

var nextYPos:int = 10;

//----------------------------------------------

var i:int = 0;

//----------------------------------------------

var container:MovieClip = new MovieClip();

//----------------------------------------------

addChild(container); for (i=0; i<num_clips ; i++) {

//---------------------------------------------- 

var boxMC:box = new box();

//----------------------------------------------

boxMC.x = 100;  boxMC.y = nextYPos;

//---------------------------------------------- 

//----------------------------------------------

container.addChild(boxMC);

//----------------------------------------------

nextYPos+=boxMC.height+1;

//---------------------------------------------- 

if (int(quantityMenu.XXXSinput.text) > 1){    

num_clips = int(quantityMenu.XXXSinput.text);

 

}

} [/AS]

 

Any help is greatly appreicated

 
Replies
  • Currently Being Moderated
    Jul 11, 2012 9:01 AM   in reply to TwistedPixel23

    What textbox?  What does this posting have to do with an array?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 11, 2012 10:15 AM   in reply to TwistedPixel23

    Just declare the array outside the loop (shown as boxArray below) and push each box instance into the array after it is instantiated inside the loop....

     

    var boxMC:box = new box();

     

    boxArray.push(boxMC);

     

     

    Then later on you only need to use the array to target each box's textfield text....

     

    for(var i:uint=0; i<boxArray.length, i++){

          trace(boxArray[i].textFieldName.text);

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 25, 2012 12:45 PM   in reply to TwistedPixel23

    You should start a new posting if you have a new problem, especially after so much time has passed.  Tagging onto an old one makes it less noticeable.

     

    If you are saying the following code

     

       for(var v:uint=0; v<boxArray.length; v++){

            trace(boxArray[v].txTitle.text);

            XXXStext.text = (boxArray[v].txTitle.text);

       }

     

    only shows that last item of whatever boxArray is, that is what you are telling it to do by assigning  ( = ) the value to it.  Each time it loops, you are reassigning it a new value by using the =.   If you use the appendText() method, it will build each one after another...

     

       for(var v:uint=0; v<boxArray.length; v++){

            trace(boxArray[v].txTitle.text);

            XXXStext.appendText(boxArray[v].txTitle.text);

       }

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 25, 2012 5:42 PM   in reply to TwistedPixel23

    You're welcome

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 25, 2012 7:01 PM   in reply to TwistedPixel23

    The way you show your code with dashed lines separating lines of code and no indentation to show structure makes it very difficult to read.  It looks like you have a function defined within a function.  That is something you should never do.

     

    I took your code and recreated what I can make of it, and it only traces A and B when I specify 2 textfields and enter A in  one and B in the other.

     

    var boxArray:Array = new Array();

    quantityMenu.XXXSinput.addEventListener(KeyboardEvent.KEY_UP,XXXSupdat eTextfield);


    function XXXSupdateTextfield(evt:KeyboardEvent):void{

       var num_clips:int = 999;
       var nextYPos:int = 10;
       var i:int = 0;
       var container:MovieClip = new MovieClip();
       addChild(container);

       for (i=0; i<num_clips ; i++) {
          var boxMC:box = new box();
          boxArray.push(boxMC);
          boxMC.x = 85;
          boxMC.y = nextYPos;
          boxMC.SizeIndicator.text = ("XXXS")
          container.addChild(boxMC);
          nextYPos+=boxMC.height+1;
     
          if (int(quantityMenu.XXXSinput.text) > 1){
            num_clips = int(quantityMenu.XXXSinput.text);
          }
       }

     

       quantityMenu.updateForm.addEventListener(MouseEvent.MOUSE_UP, traceText);
    }

     

    function traceText(e:MouseEvent):void{
        for(var v:uint=0; v<boxArray.length; v++){
            trace(boxArray[v].txTitle.text);
            XXXStext.text = (boxArray[v].txTitle.text);
        }
    }

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 26, 2012 4:26 AM   in reply to TwistedPixel23

    Repeating... That is something you should never do.  I can't really think of any situation where a function relies on another such that is needs to be contained within it.  As you can hopefully see in your case, there was no need for it at all -  the whole function was pulled out intact without any need to modify it.  In other cases where you might think it needs to be, there is always a way around it, such as declaring a variable outside a function to make it available to multiple functions.

     
    |
    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