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
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);
}
Copy link to clipboard
Copied
What textbox? What does this posting have to do with an array?
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.
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);
}
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
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
}
}
}
[/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
XXXStext.text = (boxArray
}
[/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.
Copy link to clipboard
Copied
Can anyone help please?
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
XXXStext.text = (boxArray
}
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
XXXStext.appendText(boxArray
}
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.
Copy link to clipboard
Copied
You're welcome
Copy link to clipboard
Copied
Is there any way to make it just trace each textfield once?
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
XXXStext.text = (boxArray
}
}
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?
Copy link to clipboard
Copied
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.