Copy link to clipboard
Copied
Hi Im trying to use A movie clip with four input textfields nested inside the input textfield ( Customer Name, Delivery, Phone Number, Address), after a user presses the save button, I want to save the text to my output textfields(Customer Name ,Delivery, Phone Number,Address). but every time I press the save button it overwrites the output textfield box. Im trying to create a new output textfield every time a user enters information into the input textfield and list that info ten to a page... any help or direction is highly appreciated!!!
I see that you still have the writeText function nexted within another function. Get that out of there and give it the same level of access as the dispar function.
I think I am starting to understand what you are trying to do. What you need to do is to make the object you are targeting only be the last tbox object that you added. To do this you should have a variable outside of the functions ( private var newText:tbox; ) that you assign only to the most recent tbox created as it gets created..
...Copy link to clipboard
Copied
If you are using the same instance names for the inpout and output textfields that might be where your problem arises. Show the code you are using for the save button event hamdler function and explain where it doesn't do what you expect.
Copy link to clipboard
Copied
// this is the function that takes the input textfields offstage
public function dispar(e: MouseEvent): void {
ranUp += 1;
ps1.r.text = String(ranUp);
trace(ps1.r.text);
bg_.NOD.ru.text = String(ranUp);
trace("this home" + bg_.NOD.ru.text)
bg_.NOD.fdf.text = ps1.DF.text, "" + ps1.DF.text;
trace("fuel delivery" + ps1.DF.text);
trace("ranUp", ranUp);
ps1.x = 800; // input text field MC(ps1) moving offstage
ctext();
}
// this is my function that creates an array of the output textfields and lists them by ten, and i take my input MC (ps1) to equal my output box
public function ctext() :void {
var aTEXT: Array = new Array();
var nTEXT: Number = 10;
for (var i: Number = 0; i < nTEXT; i++) {
var newText: tbox = new tbox()
newText = new MovieClip();
aTEXT = TEXT;
newText.visible = false;
newText.x = view.gg.x + 450;
newText.y = 88 + 0 * newText.height + 0 * 3.8;
aTEXT.push(newText);
addChildAt(newText, 8);
trace(" view", view.x);
trace(" newText", newText.x, newText.y);
switch (newText) {
case aTEXT[0]:
newText.cn.text = ps1.CN.text, "";
trace(TEXT.cn.text);
newText.pn.text = ps1.PN.text, "";
newText.ad.text = ps1.Ad.text, "";
newText.ot.text = ps1.OT.text, "";
break;
if (
case aTEXT[1] (aTEXT[0] :
newText.cn.text = ps1.CN.text, "";
trace(TEXT.cn.text);
newText.pn.text = ps1.PN.text, "";
newText.ad.text = ps1.Ad.text, "";
newText.ot.text = ps1.OT.text, "";
break;
case aTEXT[2]:
newText.cn.text = ps1.CN.text, "";
trace(TEXT.cn.text);
newText.pn.text = ps1.PN.text, "";
newText.ad.text = ps1.Ad.text, "";
newText.ot.text = ps1.OT.text, "";
break;
case aTEXT[3]:
newText.cn.text = ps1.CN.text, "";
trace(TEXT.cn.text);
newText.pn.text = ps1.PN.text, "";
newText.ad.text = ps1.Ad.text, "";
newText.ot.text = ps1.OT.text, "";
break;
case aTEXT[4]:
newText.cn.text = ps1.CN.text, "";
trace(TEXT.cn.text);
newText.pn.text = ps1.PN.text, "";
newText.ad.text = ps1.Ad.text, "";
newText.ot.text = ps1.OT.text, "";
break;
case aTEXT[5]:
newText.cn.text = ps1.CN.text, "";
trace(TEXT.cn.text);
newText.pn.text = ps1.PN.text, "";
newText.ad.text = ps1.Ad.text, "";
newText.ot.text = ps1.OT.text, "";
break;
case aTEXT[6]:
newText.cn.text = ps1.CN.text, "";
trace(TEXT.cn.text);
newText.pn.text = ps1.PN.text, "";
newText.ad.text = ps1.Ad.text, "";
newText.ot.text = ps1.OT.text, "";
break;
case aTEXT[7]:
newText.cn.text = ps1.CN.text, "";
trace(TEXT.cn.text);
newText.pn.text = ps1.PN.text, "";
newText.ad.text = ps1.Ad.text, "";
newText.ot.text = ps1.OT.text, "";;
break;
case aTEXT[8]:
newText.cn.text = ps1.CN.text, "";
trace(TEXT.cn.text);
newText.pn.text = ps1.PN.text, "";
newText.ad.text = ps1.Ad.text, "";
newText.ot.text = ps1.OT.text, "";
break;
case aTEXT[9]:
newText.cn.text = ps1.CN.text, "";
trace(TEXT.cn.text);
newText.pn.text = ps1.PN.text, "";
newText.ad.text = ps1.Ad.text, "";
newText.ot.text = ps1.OT.text, "";
break;
}*/
}
Copy link to clipboard
Copied
I don't know what you are trying to do with the following two lines...
var newText: tbox = new tbox()
newText = new MovieClip();
I also do not know what you expect from lines like the following - what is the "" doing?
newText.cn.text = ps1.CN.text, "";
I don't see any code relative to a Save button which is where you say the problem comes from.
Copy link to clipboard
Copied
tbox is a class name/linkage to my outbox textfield MC, i'm creating an array that populate ten output textfield boxes
and sorry for newText = new MovieClip(); that is suppose to be commented out
newText.cn.text = ps1.CN.text,""; is my sad attempt to make my output customer name textfield equal whatever the user types into the customer name input text
I've tried changeEvent, TextEvents, etc... I'm so lost at the point my code is kinda messy right now. I don't really have a solid basis...
ps1.serialize.addEventListener(MouseEvent.CLICK, dispar);// this my save button listener
the save button doesn't per say saves the text, i try to do that with the ctext(); function, the save button moves the MC(ps1) off stage.
Copy link to clipboard
Copied
If you want the textfields to write their contents to other textfields as you enter text into them then the following would work... the following uses the same textfield names inside a different container to make it easier to code (meaning newText1 also contains CN, PN, Ad, OD).
ps1.CN.addEventListener(Event.CHANGE, writeText);
ps1.PN.addEventListener(Event.CHANGE, writeText);
ps1.Ad.addEventListener(Event.CHANGE, writeText);
ps1.OD.addEventListener(Event.CHANGE, writeText);
function writeText(evt:Event):void {
newText1[evt.currentTarget.name].text = evt.currentTarget.text;
}
Copy link to clipboard
Copied
thank you I will try when I get to my cpu
Copy link to clipboard
Copied
Hey Ned, I tried... I get no text in newText, and when I try to add more text/ or change the text from the the input text I get error 1069... thx for all your help!!!!
line 173 is //////newText[evt.currentTarget.name].text = evt.currentTarget.text;
ReferenceError: Error #1069: Property CN not found on tbox and there is no default value.
at Function/Deliverydispatch/ctext/writeText()[/Users/YellowEngineGaming/Desktop/DD/DelD.as:173]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::TextInput/handleChange()
public function ctext(): void {
var aTEXT: Array = new Array();
var nTEXT: Number = 10;
for (var i: Number = 0; i < nTEXT; i++) {
var newText: tbox = new tbox()
aTEXT = TEXT;
// newText.visible = false;
newText.x = view.gg.x + 450;
newText.y = 88 + 0 * newText.height + 0 * 3.8;
aTEXT.push(newText);
addChildAt(newText, 9);
trace(" view", view.x);
trace(" newText", newText.x, newText.y);
ps1.CN.addEventListener(Event.CHANGE, writeText);
ps1.PN.addEventListener(Event.CHANGE, writeText);
ps1.Ad.addEventListener(Event.CHANGE, writeText);
ps1.OT.addEventListener(Event.CHANGE, writeText);
function writeText(evt: Event): void {
newText[evt.currentTarget.name].text = evt.currentTarget.text;
}
}
}
Copy link to clipboard
Copied
The error appears to be indicating that you didn't name the textfields teh same as the ones in ps1.
You should never nest named functions inside other functions.
Copy link to clipboard
Copied
thx for all your help Ned, Its Working great now. I just have one more question. at the moment all my newText textfield i have equal the same information, how do I set it up to save each newText field uniquely?
public function dispar(e: MouseEvent): void { |
ranUp += 1; |
ps1.r.text = String(ranUp); | |||
trace(ps1.r.text); |
bg_.NOD.ru.text = String(ranUp); | |||
trace("this home" + bg_.NOD.ru.text) | |||
bg_.NOD.fdf.text = ps1.DF.text, "" + ps1.DF.text; | |||
trace("fuel delivery" + ps1.DF.text); | |||
trace("ranUp", ranUp); |
ps1.x = 800; |
ps1.CN.addEventListener(Event.CHANGE, writeText); | |||
ps1.PN.addEventListener(Event.CHANGE, writeText); | |||
ps1.Ad.addEventListener(Event.CHANGE, writeText); | |||
ps1.OT.addEventListener(Event.CHANGE, writeText); |
var newText: tbox = new tbox(); | |||
addChildAt(newText, 8); | ||||
newText.x = view.gg.x + 450; | ||||
newText.y = 88 + 0 * newText.height + 0 * 3.8; | ||||
trace("this is the number of children", numChildren); | ||||
if (ps1.x == 800) { | ||||
ps1.CN.text = ''; | ||||
ps1.PN.text = ''; | ||||
ps1.Ad.text = ''; | ||||
ps1.OT.text = ''; | ||||
} |
// THIS SETS UP EACH NEWTEXT(MC) RIGHT UNDER EACH OTHER EVERY TIME A USER ADDS INFORMATION
if (numChildren > 11 && numChildren <= 12) { | ||||
newText.y = 88 + 1 * newText.height + 1 * 3.8; |
8
} |
if (numChildren > 12 && numChildren <= 13) { | ||||
newText.y = 88 + 2 * newText.height + 2 * 3.8; |
} |
if (numChildren > 13 && numChildren <= 14) { | ||||
newText.y = 88 + 3 * newText.height + 3 * 3.8; |
} |
if (numChildren > 14 && numChildren <= 15) { | ||||
newText.y = 88 + 4 * newText.height + 4 * 3.8; |
} |
if (numChildren > 15 && numChildren <= 16) { | ||||
newText.y = 88 + 5 * newText.height + 5 * 3.8; |
} |
if (numChildren > 16 && numChildren <= 17) { | ||||
newText.y = 88 + 6 * newText.height + 6 * 3.8; |
} |
function writeText(evt: Event): void { |
newText[evt.currentTarget.name].text = evt.currentTarget.text; |
} |
} |
Copy link to clipboard
Copied
I don't understand what you mean. What do you want to do with the text that is in the newText textfields? Try to limit the code you show only to what is relevant to your questions. It can be difficult to go thru alot of code to try to see what might relate to the question, and when it looks like the way yours does it is even harder.
Copy link to clipboard
Copied
Sorry, I don't know why it paste like that. I'm trying to save the information in newText, and not have the save information changed when ps1 text is changed. because of the CHANGE event all the newText i add on stage have the same information inside. hope that makes sense... thx for any pointers
Copy link to clipboard
Copied
I see that you still have the writeText function nexted within another function. Get that out of there and give it the same level of access as the dispar function.
I think I am starting to understand what you are trying to do. What you need to do is to make the object you are targeting only be the last tbox object that you added. To do this you should have a variable outside of the functions ( private var newText:tbox; ) that you assign only to the most recent tbox created as it gets created... (change the line in the function to using just: newText = new tbox(); ) Then in the writeText function you target using that variable as you have it. That should only target the most recent tbox that you add.
Also, if you only have one set of ps1 textfields you should only assign the event listeners to them once. If I understand what you are doing, your current code reassigns the listeners everytime you create a new tbox. If that is the case, find somewhere else to assign them outside of the dispar function
Copy link to clipboard
Copied
Thank you so much Ned, I understand everything now
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now