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

reusable input text to create new output text

New Here ,
Nov 10, 2014 Nov 10, 2014

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!!!

TOPICS
ActionScript
641
Translate
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 , Nov 13, 2014 Nov 13, 2014

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..

...
Translate
LEGEND ,
Nov 11, 2014 Nov 11, 2014

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.

Translate
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
New Here ,
Nov 11, 2014 Nov 11, 2014

// 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;

  }*/


}

Translate
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 ,
Nov 11, 2014 Nov 11, 2014

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.

Translate
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
New Here ,
Nov 11, 2014 Nov 11, 2014

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.

Translate
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 ,
Nov 11, 2014 Nov 11, 2014

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;

}

Translate
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
New Here ,
Nov 11, 2014 Nov 11, 2014

thank you I will try when I get to my cpu

Translate
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
New Here ,
Nov 11, 2014 Nov 11, 2014

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;

 

  }

  }

  }

Translate
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 ,
Nov 12, 2014 Nov 12, 2014

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.

Translate
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
New Here ,
Nov 13, 2014 Nov 13, 2014

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;

}

}
Translate
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 ,
Nov 13, 2014 Nov 13, 2014

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.

Translate
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
New Here ,
Nov 13, 2014 Nov 13, 2014

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

Translate
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 ,
Nov 13, 2014 Nov 13, 2014

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

Translate
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
New Here ,
Nov 13, 2014 Nov 13, 2014

Thank you so much Ned, I understand everything now

Translate
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 ,
Nov 14, 2014 Nov 14, 2014
LATEST

You're welcome

Translate
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