Hi, i am currently trying to write code, so if i enter a value into a textbox it will move a symbol up and down the screen according to the value. I was using the method of removing the child at for example removeChildAt(1) then deleting it and re adding it in a different place. But for some reason as i have 10 symbols and textboxes it kept deleting random things. So i decided to try remove child by name, but this still hasn’t worked could anyone help me? Here is my code.
// EXAMPLE WHERE TEXTBOX USED TO POSITION A BALL ON THE STAGE
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.text.*;
import flash.events.*;
public class testScript extends Sprite
{
// text boxes for rating
private var myTextBox:TextField = new TextField();
private var myOutputBox:TextField = new TextField();
private var myText:String = "";
private var myBrain:brain = new brain ;
private var myTextBox2:TextField = new TextField();
private var myTextBox3:TextField = new TextField();
private var myTextBox4:TextField = new TextField();
private var myTextBox5:TextField = new TextField();
private var myTextBox6:TextField = new TextField();
private var myTextBox7:TextField = new TextField();
private var myTextBox8:TextField = new TextField();
private var myTextBox9:TextField = new TextField();
private var myTextBox10:TextField = new TextField();
// text in the text boxes
private var myText2:String = "your job";
private var myText3:String = " feelings";
private var myText4:String = " finance";
private var myText5:String = "living arrangements";
private var myText6:String = "mental health";
private var myText7:String = "motivation";
private var myText8:String = "physical health";
private var myText9:String = "relationships";
private var myText10:String = "thinking";
// Calling the symbols
private var myJob:job = new job ;
private var myFeelings:feelings = new feelings ;
private var myFinance:finance = new finance ;
private var myLivingArrangements:livingArrangements = new livingArrangements ;
private var myMentalHealth:mentalHealth = new mentalHealth ;
private var myMotivation:motivation = new motivation ;
private var myPhysicalHealth:physicalHealth = new physicalHealth ;
private var myRelationships:relationships = new relationships ;
private var myThinking:thinking = new thinking ;
public function testScript()
{
captureText();
captureText1();
captureText2();
captureText3();
captureText4();
captureText5();
captureText6();
captureText7();
captureText8();
captureText9();
}
public function captureText():void
{
// textbox for brain
myTextBox.type = TextFieldType.INPUT;
myTextBox.background = true;
myTextBox.border = true;
myTextBox.height = 50;
myTextBox.width = 70;
var xPosition = 46;
var yPosition = 343;
// position of textbox for brain
myTextBox.y = yPosition;
myTextBox.x = xPosition;
// adds textbox and the brain symbol
addChild(myTextBox);
addChild(myBrain);
myTextBox.text = myText;
trace(myTextBox.text);
myTextBox.addEventListener(Event.CHANGE,positionSymbol);
}
// textbox for job
/*
myTextBox2.type = TextFieldType.INPUT;
myTextBox2.background = true;
myTextBox2.border = true;
myTextBox2.height = 50;
myTextBox2.width = 70;
var xPosition1 = 148;
var yPosition1 = 343;
// position of textbox for brain
myTextBox2.y = yPosition1;
myTextBox2.x = xPosition1;
// add job symbol and textbox
addChild(myTextBox2);
addChild(myJob);
myTextBox2.text = myText;
trace(myTextBox2.text);
myTextBox2.addEventListener(Event.CHANGE,positionSymbol1)
*/
// feelings
public function captureText2():void
{
myTextBox3.type = TextFieldType.INPUT;
myTextBox3.background = true;
myTextBox3.border = true;
myTextBox3.height = 50;
myTextBox3.width = 70;
var xPosition2 = 257;
var yPosition2 = 343;
// position of text box for feelings
myTextBox3.y = yPosition2;
myTextBox3.x = xPosition2;
addChild(myTextBox3);
addChild(myFeelings);
myTextBox3.text = myText;
trace(myTextBox3.text);
myTextBox3.addEventListener(Event.CHANGE,positionSymbol2);
}
public function captureText3():void
{
// finance
myTextBox4.type = TextFieldType.INPUT;
myTextBox4.background = true;
myTextBox4.border = true;
myTextBox4.height = 50;
myTextBox4.width = 70;
var xPosition3 = 364;
var yPosition3 = 343;
myTextBox4.y = yPosition3;
myTextBox4.x = xPosition3;
addChild(myFinance);
addChild(myTextBox4);
myTextBox4.text = myText;
trace(myTextBox4.text);
myTextBox4.addEventListener(Event.CHANGE,positionSymbol3);
}
public function captureText4():void
{
// living arrangements
myTextBox5.type = TextFieldType.INPUT;
myTextBox5.background = true;
myTextBox5.border = true;
myTextBox5.height = 50;
myTextBox5.width = 70;
var xPosition4 = 465;
var yPosition4 = 343;
myTextBox5.y = yPosition4;
myTextBox5.x = xPosition4;
addChild(myLivingArrangements);
addChild(myTextBox5);
myTextBox5.text = myText;
trace(myTextBox5.text);
myTextBox5.addEventListener(Event.CHANGE,positionSymbol4);
}
public function captureText5():void
{
// mental health
myTextBox6.type = TextFieldType.INPUT;
myTextBox6.background = true;
myTextBox6.border = true;
myTextBox6.height = 50;
myTextBox6.width = 70;
var xPosition5 = 560;
var yPosition5 = 343;
// position of textbox for brain
myTextBox6.y = yPosition5;
myTextBox6.x = xPosition5;
addChild(myMentalHealth);
addChild(myTextBox6);
myTextBox6.text = myText;
trace(myTextBox6.text);
myTextBox6.addEventListener(Event.CHANGE,positionSymbol5);
}
public function captureText6():void
{
// motivation
myTextBox7.type = TextFieldType.INPUT;
myTextBox7.background = true;
myTextBox7.border = true;
myTextBox7.height = 50;
myTextBox7.width = 70;
var xPosition6 = 646;
var yPosition6 = 343;
// position of textbox for brain
myTextBox7.y = yPosition6;
myTextBox7.x = xPosition6;
addChild(myMotivation);
addChild(myTextBox7);
myTextBox7.text = myText;
trace(myTextBox7.text);
myTextBox7.addEventListener(Event.CHANGE,positionSymbol6);
}
public function captureText7():void
{
//physical health
myTextBox8.type = TextFieldType.INPUT;
myTextBox8.background = true;
myTextBox8.border = true;
myTextBox8.height = 50;
myTextBox8.width = 70;
var xPosition7 = 748;
var yPosition7 = 343;
// position of textbox for brain
myTextBox8.y = yPosition7;
myTextBox8.x = xPosition7;
addChild(myPhysicalHealth);
addChild(myTextBox8);
myTextBox8.text = myText;
trace(myTextBox8.text);
myTextBox8.addEventListener(Event.CHANGE,positionSymbol7);
}
public function captureText8():void
{
// relationships
myTextBox9.type = TextFieldType.INPUT;
myTextBox9.background = true;
myTextBox9.border = true;
myTextBox9.height = 50;
myTextBox9.width = 70;
var xPosition8 = 843;
var yPosition8 = 343;
// position of textbox for brain
myTextBox9.y = yPosition8;
myTextBox9.x = xPosition8;
addChild(myRelationships);
addChild(myTextBox9);
myTextBox9.text = myText;
trace(myTextBox9.text);
myTextBox9.addEventListener(Event.CHANGE,positionSymbol8);
}
public function captureText9():void
{
// thinking
myTextBox10.type = TextFieldType.INPUT;
myTextBox10.background = true;
myTextBox10.border = true;
myTextBox10.height = 50;
myTextBox10.width = 70;
var xPosition9 = 940;
var yPosition9 = 343;
// position of textbox for brain
myTextBox10.y = yPosition9;
myTextBox10.x = xPosition9;
addChild(myThinking);
addChild(myTextBox10);
myTextBox10.text = myText;
trace(myTextBox10.text);
myTextBox10.addEventListener(Event.CHANGE,positionSymbol9);
}
public function captureText1():void
{
myTextBox2.type = TextFieldType.INPUT;
myTextBox2.background = true;
myTextBox2.border = true;
myTextBox2.height = 50;
myTextBox2.width = 70;
var xPosition1 = 148;
var yPosition1 = 343;
// position of textbox for brain
myTextBox2.y = yPosition1;
myTextBox2.x = xPosition1;
// add job symbol and textbox
addChild(myTextBox2);
addChild(myJob);
myTextBox2.text = myText;
trace(myTextBox2.text);
myTextBox2.addEventListener(Event.CHANGE,positionSymbol1);
}
// use for the Event.CHANGE event. Has a different class.
public function positionSymbol(event:Event):void
{
var myBrain:brain = new brain();
var rating:int = int(myTextBox.text);
var position:int;
removeChild( getChildByName("myBrain") );
// convert rating to position on stage
position =(3 * rating * 10);
trace(position);
if ((position <= 800))
{
myBrain.y = position;
addChild(myBrain);
}
}
public function positionSymbol1(event:Event):void
{
var myJob:job = new job();
var rating:int = int(myTextBox2.text);
var position:int;
removeChildAt(4);
// convert rating to position on stage
position =(3 * rating * 10);
trace(position);
if ((position <= 800))
{
myJob.y = position;
addChild(myJob);
}
}
public function positionSymbol2(event:Event):void
{
var myFeelings:feelings = new feelings();
var rating:int = int(myTextBox3.text);
var position:int;
removeChildAt(6);
// convert rating to position on stage
position =(3 * rating * 10);
trace(position);
if ((position <= 800))
{
myFeelings.y = position;
addChild(myFeelings);
}
}
public function positionSymbol3(event:Event):void
{
var myFinance:finance = new finance();
var rating:int = int(myTextBox4.text);
var position:int;
removeChildAt(7);
// convert rating to position on stage
position =(3 * rating * 10);
trace(position);
if ((position <= 800))
{
myFinance.y = position;
addChild(myFinance);
}
}
public function positionSymbol4(event:Event):void
{
var myLivingArrangements: livingArrangements = new livingArrangements();
var rating:int = int(myTextBox5.text);
var position:int;
removeChildAt(9);
// convert rating to position on stage
position =(3 * rating * 10);
trace(position);
if ((position <= 800))
{
myLivingArrangements.y = position;
addChild(myLivingArrangements);
}
}
public function positionSymbol5(event:Event):void
{
var myMentalHealth:mentalHealth = new mentalHealth();
var rating:int = int(myTextBox6.text);
var position:int;
removeChildAt(11);
// convert rating to position on stage
position =(3 * rating * 10);
trace(position);
if ((position <= 800))
{
myMentalHealth.y = position;
addChild(myMentalHealth);
}
}
public function positionSymbol6(event:Event):void
{
var myMotivation:motivation = new motivation();
var rating:int = int(myTextBox7.text);
var position:int;
removeChildAt(13);
// convert rating to position on stage
position =(3 * rating * 10);
trace(position);
if ((position <= 800))
{
myMotivation.y = position;
addChild(myMotivation);
}
}
public function positionSymbol7(event:Event):void
{
var myPhysicalHealth:physicalHealth = new physicalHealth();
var rating:int = int(myTextBox8.text);
var position:int;
removeChildAt(15);
// convert rating to position on stage
position =(3 * rating * 10);
trace(position);
if ((position <= 800))
{
myPhysicalHealth.y = position;
addChild(myPhysicalHealth);
}
}
public function positionSymbol8(event:Event):void
{
var myRelationships:relationships = new relationships();
var rating:int = int(myTextBox9.text);
var position:int;
removeChildAt(17);
// convert rating to position on stage
position =(3 * rating * 10);
trace(position);
if ((position <= 800))
{
myRelationships.y = position;
addChild(myRelationships);
}
}
public function positionSymbol9(event:Event):void
{
var myThinking:thinking = new thinking();
var rating:int = int(myTextBox10.text);
var position:int;
removeChild(myThinking);
// convert rating to position on stage
position =(3 * rating * 10);
trace(position);
if ((position <= 800))
{
myThinking.y = position;
addChild(myThinking);
}
}
}
}
Thank you