PDA

View Full Version : [AS3] Copying text from one textarea to another


Southern_Boy
09-28-2008, 05:52 PM
I am new to AS 3.0 so this may be a very basic question. I have a textarea called "My_TextArea" where text is dynamically generated based on a user answering a question. I want that dynamic text to appear in a second static textarea called "ta" where I have a slider that controls the size of the font. Any ideas?

Here is my code:

import fl.data.DataProvider;
import fl.events.ComponentEvent;
import fl.events.*;
import fl.controls.TextArea;
import fl.controls.ScrollPolicy;



//This code defines my variables
var Name:String = new String(); // this variable holds the name of the user
var My_knowledge:String = new String(); // this variable holds the knowledge level that the user chooses
var My_candidate:String = new String; // this is my variable for my candidate

// This variable formats the text for myTextArea box.
var textAreaFormat:TextFormat = new TextFormat();
textAreaFormat.size = 30;

// This code defines my dynamic textarea

var myTextArea:TextArea = new TextArea();
myTextArea.verticalScrollPolicy = ScrollPolicy.AUTO;
myTextArea.setSize(340, 214);
myTextArea.move(28, 350);
//myTextArea.alpha = 0;
myTextArea.setStyle("textFormat", textAreaFormat);
addChild(myTextArea);

//this variable formats my text in the slider box

var tf:TextFormat = new TextFormat("Myriad Pro", 12);

//This data provider holds the options for the level of knowledge.

var dpMy_knowledge:DataProvider = new DataProvider (["nothing", "a little bit", "a whole lot"]);
cbMy_knowledge.dataProvider = dpMy_knowledge;

cbMy_knowledge.addEventListener(ComponentEvent.ENT ER, cbMy_knowledgeHandler);


//This code adds mouse click event listeners for the submit button, and text size slider
btnSubmit.addEventListener(MouseEvent.CLICK, btnSubmitClick);
slyda.addEventListener(SliderEvent.THUMB_DRAG, slydaChange);


//This code defines my funcitons for the submit button.

function cbMy_knowledgeHandler(event:ComponentEvent):void {

My_knowledge = event.target.value;

}
function btnSubmitClick(event:MouseEvent):void {
Name = txtInputFName.text;
My_knowledge = cbMy_knowledge.value;//added this to bring in the variable

// the code below is the "if, else if , else" statement that return the appropriate response based on the knowledge level of the user.
if(My_knowledge == "nothing")
{
(My_candidate = " You are a very good candidate for E-101");
}
else if(My_knowledge == "a little bit")
{
(My_candidate = " You are a good candidate for E-101. You should use this program as a possible refresher");
}
else
{
(My_candidate = " You are a poor candidate for E-101 and should not waste your time. E-101 was developed for beginners. However, thank you for your time.");
}

myTextArea.text = ("Hey, " + Name +
". You are a person who knows " + My_knowledge + " about electricity." + My_candidate + ".");
}


//The code below is for the slider bar and the number indicatior that controls the size of the text.

function slydaChange(e:SliderEvent):void
{
tf.size = slyda.value;
ta.setStyle("textFormat", tf);
ns.value = e.value;
}

ns.addEventListener(Event.CHANGE, nsChange);

function nsChange(e:Event):void
{
tf.size = ns.value;
ta.setStyle("textFormat", tf);
slyda.value = ns.value;
}

rawmantick
09-28-2008, 08:15 PM
My_TextArea.addEventListener(Event.CHANGE,onChange );

function onChange(event:Event):void
{
ta.text = My_TextArea.text;
}

Hope it helps ...

Southern_Boy
09-30-2008, 02:41 AM
It does nothing...? No text appears in the second text box!