as3 passing content of one text filed to another - actionscript-3

I'm tying to pass the contents of
B1L_bnt.text
to
buddy_txt.text
Can anyone tell me what am doing Wong here?
function clickHandler(event:MouseEvent):void
{
/*container_mcM.removeEventListener(MouseEvent.CLICK,clickHandler);*/
var clickedObject:DisplayObject = event.target as DisplayObject;
var bobby = Object(root).littlepicker.B1L_bnt.text;
if (clickedObject.name == 'frd_bnt1')
{
Object(root).BFFwho.buddy_txt.text = "bobby";
Object(root).gotoAndPlay(15);
}

Try this:
function clickHandler(event:MouseEvent):void
{
/*container_mcM.removeEventListener(MouseEvent.CLICK,clickHandler);*/
var clickedObject:DisplayObject = event.target as DisplayObject;
var bobby = Object(root).littlepicker.B1L_bnt.text;
if (clickedObject.name == 'frd_bnt1')
{
Object(root).BFFwho.buddy_txt.text = bobby;
Object(root).gotoAndPlay(15);
}
The issue was that you were declaring a variable named bobby. When you were trying to set the text of buddy_txtyou were setting it to a literal String 'bobby' instead of the value of the variable.

Related

How to check if a textbox contains a specific string or not?

I have an input textfield named "textbox" and a button named "submit".I also have two text messages "mc_error" and "form_submitted" which are not visible from the beginning. Upon clicking the button, I want it to check if the textfield contains "#" in it. I have tried the below code that uses indexOf but it always returns the value -1 and therefore upon execution always "mc_error" becomes visible.
var str:String = textbox.text;
submit.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
mc_error.visible = false;
form_submitted.visible = false;
function fl_MouseClickHandler(event:MouseEvent):void
{
var index:int = str.indexOf("#");
if(index == -1)
{
mc_error.visible=true;
}
else
{
form_submitted.visible=true;
}
}
Would be grateful if got some immediate answers as i need it working in 2 days.Thanks
Because you set variable before user inputs anything there and it is always "". Just don't use that variable (or read it in the function body as shown below) and it will be fine.
function fl_MouseClickHandler(event:MouseEvent):void
{
var str:String = textbox.text;
var index:int = str.indexOf("#");
if(index == -1)
{
mc_error.visible=true;
}
else
{
form_submitted.visible=true;
}
}

AS3 Flash How to make text fields required?

I want to know how to put restrictions in the fields like if the user didn't type anything or still has a blank field, then it should not submit but shows *required field or something like that. Examples would be great.
The codes. I don't know where to start from here
var fllname:TextField;
var address:TextField;
var ContactNo:TextField;
var quantity:TextField;
var otrack:TextField;
btnSubmit1.addEventListener(MouseEvent.CLICK, submit);
function submit(e:MouseEvent):void{
var urlvars: URLVariables = new URLVariables;
urlvars.fllname = fllname.text;
urlvars.Oadd = address.text;
urlvars.ContactNo = ContactNo.text;
urlvars.oquantiy = quantity.text;
urlvars.otrack = otrack.text;
urlvars.cake = txtCake.text;
urlvars.frosting = txtFrosting.text;
urlvars.topping = txtToppings.text;
urlvars.topping2 = txtToppings2.text;
urlvars.filling = txtFilling.text;
urlvars.amt = lblAmount.text;
var urlreq:URLRequest = new URLRequest("http://localhost/MCC/order.php");
urlreq.method = URLRequestMethod.POST;
urlreq.data = urlvars;
var loader : URLLoader = new URLLoader;
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlreq);
nextFrame();
}
You can use the enabled parameter to control if your btnSubmit1 is clickable, so you will probably need to start with is disabled.
btnSubmit1.enabled = false;
btnSubmit1.addEventListener(MouseEvent.CLICK, submit);
Next you will need to listen to the TextEvent.TEXT_INPUT event on all your TextFields
fllname.addEventListener(TextEvent.TEXT_INPUT,paramChanged);
address.addEventListener(TextEvent.TEXT_INPUT,paramChanged);
//etc etc
This will notify you any-time the user changes their value, you can then create a single function (or a function for each control) to test the values, once they pass you can re-enable the submit button.
function paramChanged(event:TextEvent):void
{
if (fllname.text != "" && address.text != "")//add your other fields here
{
btnSubmit1.enabled = true;
}
else
{
btnSubmit1.enabled = false;//If something changes that means we now fail the test you will want to disable the button again
}
}
You could make custom test functions for each field as needed.

ActionScript 3 - how to set empty display object variable?

What I initially wanted to do is this:
if (myTargetName == 'a') {
var myOtherTargetName:String = "b";
var myOtherTarget:DisplayObject = getChildByName(myOtherTargetName);
}
if (myTargetName == 'c') {
var myOtherTargetName:String = "d";
var myOtherTarget:DisplayObject = getChildByName(myOtherTargetName);
}
as you can see, I get a 'Duplicate variable definition' error since im declaring the variables twice. My solution I thought would be to just declare those variables outside the if statements, and change the variable inside the statement, like so:
var myOtherTargetName:String = ""
var myOtherTarget:DisplayObject = None;
if (myTargetName == 'a') {
myOtherTargetName = "b";
myOtherTarget = getChildByName(myOtherTargetName);
}
if (myTargetName == 'c') {
myOtherTargetName = "d";
myOtherTarget = getChildByName(myOtherTargetName);
}
This gives an error saying "access of undefined property None". Now, I don't want to set
myOtherTarget:DisplayObject
to an actual existing display object which is on the stage just yet, I want to set it to an object on the stage inside the if statements. Is there a way to set
myOtherTarget:DisplayObject
to nothing?
It is easy, copy+paste it:
var myOtherTarget:DisplayObject = null;
or simply:
var myOtherTarget:DisplayObject;

Actionscript error 1176: Comparison between a value with static type Number and a possibly unrelated type String?

For lines 18 and 24 Actionscript seems to be unhappy with my if statements. Being really new to this I don't know how to rectify the issue if any.
var strName:String;
var strSystem:String;
var strHeight:String;
var numHeight:Number;
var numSystem:Number;
var strOut:String;
var strOut2:String;
enter_btn.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void {
strName=txt_Name.text;
strSystem=txt_System.text;
numSystem=Number(strSystem)
strHeight=txt_Height.text;
numHeight=Number(strHeight);
if (numSystem == "M"){
var numWeight:Number= numHeight*numHeight*25;
var strWeight:String=String(numWeight);
strOut=strName+ "'s ideal weight is" +strWeight+"kilograms.";
txt_Answer.text=strOut
}
if (numSystem == "I"){
var numWeight2:Number= (numHeight*numHeight*25)/703
var strWeight2:String=String(numWeight);
strOut2= strName+"'s ideal weight is" +strWeight2 + "pounds";
}
{
}
}
What is with
}
{
}
}
at the end of your class? It's wrong as the middle {} does not start with any condition statement.
var strWeight:String=String(numWeight); should be var strWeight:String= numWeight.toString(); or var strWeight:String= numWeight.toFix();

How to check whether an AS3 "Object" variable is completely empty?

In Actionscript 3.0, how do I check if var myObject:Object is functionally identical to {}?
I take it I can't do ...
if (myObject == {}) {
// etc
}
... because Objects are reference types, right?
Check that it exists at least one field :
function isEmptyObject(myObject:Object):Boolean {
var isEmpty:Boolean=true;
for (var s:String in myObject) {
isEmpty = false;
break;
}
return isEmpty;
}
This works with dynamic object and classes, to check if an object contains fields this should be a more general solution
import flash.utils.describeType;
var test:String = "test";
var data:XML = describeType(test);
trace(data..accessor.length() > 0 || data..variable.length() > 0)