• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Dynamic TextField Array Help

Guest
Jul 11, 2012 Jul 11, 2012

Copy link to clipboard

Copied

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

TOPICS
ActionScript

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 11, 2012 Jul 11, 2012

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.textFieldName.text);

}

Votes

Translate

Translate
LEGEND ,
Jul 11, 2012 Jul 11, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 11, 2012 Jul 11, 2012

Copy link to clipboard

Copied

Sorry i havent explained myself properly, i have a movieclip with a texbox in it the MC is called "box". Then i have created a loop to dynammically add them to the stage depending on the number num_clips is changed to. I want to know how to add the loop to an array, so i can identify each instance of "box" and trace the text that was input by the user.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 11, 2012 Jul 11, 2012

Copy link to clipboard

Copied

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.textFieldName.text);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 11, 2012 Jul 11, 2012

Copy link to clipboard

Copied

Thanks Ned that worked a charm. Just one small thing that doesnt matter im just curious about is, when i get the trace result it skips loads of lines in the output the shows the result. Thanks very much again for you help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 23, 2012 Aug 23, 2012

Copy link to clipboard

Copied

Hi Ned, sorry i have reopend this but im still having trouble, this is the changed code,

[AS]

var boxArray:Array = new Array

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();

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.txTitle.text);

}

}

}

[/AS]

[AS]

Which will trace what i put into the textfields, but when i try something like

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

        trace(boxArray.txTitle.text);

        XXXStext.text = (boxArray.txTitle.text);

}

[/AS]

Only the last thing entered into the textfield appears in XXXStext.text

I have tried numerous things but cant come up with the soloution.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2012 Aug 25, 2012

Copy link to clipboard

Copied

Can anyone help please?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 25, 2012 Aug 25, 2012

Copy link to clipboard

Copied

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.txTitle.text);

        XXXStext.text = (boxArray.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.txTitle.text);

        XXXStext.appendText(boxArray.txTitle.text);

   }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2012 Aug 25, 2012

Copy link to clipboard

Copied

Thanks Ned it worked, but it traces it multiple times. For example when the loop creates 2 textfields and i enter A in the first one and B in the second, it will trace A. AB, ABA, ABAB.

Thanks again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 25, 2012 Aug 25, 2012

Copy link to clipboard

Copied

You're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2012 Aug 25, 2012

Copy link to clipboard

Copied

Is there any way to make it just trace each textfield once?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 25, 2012 Aug 25, 2012

Copy link to clipboard

Copied

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,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();
      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.txTitle.text);
        XXXStext.text = (boxArray.txTitle.text);
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2012 Aug 25, 2012

Copy link to clipboard

Copied

Thank you very much ned, once again you have saved me hours of stress. Is a function inside a function always bad or is it ok if one relys on the other?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 26, 2012 Aug 26, 2012

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines