Wednesday, 27 January 2016

STRING VARIABLES AS2 WITH TEXT BOX



--------------------------------------------------------------------------------------------------------------
STEP:1
MAKE BUTTON SYMBOL
MAKE TEXTBOX
GIVE INSTANCE NAMES
btn1
txt1
---------------------------------------------------------------------------------------------------------------
KEEP IN MIND NOT GIVE VARIABLE NAME TO COMPONENT
//HERE TEXT BOX NAME  btn2
var btn1:String = "btn1";
btn2.text = btn1
--------------------------------------------------------------------------------------------------------------
STEP:2
COPY AND PAST BELOW CODE IN ACTION SCRIPT PANEL
txt1.text = "";
btn1.onPress = function(){
var var1:String = "A";
var var2:String = "B";
var var3:String = "C";
txt1.text = var1+var2+var3; // output: ABC
trace(var1+var2+var3); // output: ABC
}
---------------------------------------------------------------------------------------------------------------
EXAMPLE:2




----------------------------------------------------------------------------------------------------------------
txt1.text = "";
txt3.text = txt1.text + txt2.text;

A.onPress = function(){
var var1:String = "A";   
txt1.text = var1// output: A
trace(var1); // output: A
}
B.onPress = function(){
var var2:String = "B";   
txt2.text = var2// output: B
trace(var2); // output:B
}
C.onPress = function(){
var var3:String = "C"; 
txt3.text = txt1.text + txt2.text + var3; // output: ABC
}

-----------------------------------------------------------------------------------------------------------------
STRING VARIABLES  MATCH
I T ALSO HELP IN MATCHING GAMES IN AS2
-------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------
=======================================================================
MATCHING STRING AS2
MAKE TWO BUTTON & TWO TEXT BOX
GIVE TEXT BOX INSTANCE NAMES REACTIVELY LIKE txt1, txt2
BUT YOU NEED BUTTON INSTANCE NAMES
=======================================================================
//MAIN TIME LINE FRAME NO:1 CODE
var Num1:String = "GREEN";
var Num2:String = "RED";
txt1.text = Num1

// FOR RUN FUNTION  ADD EVERY TIME FuntionString() INSIDE BUTTON OR UNDER BUTTON FUNCTION

function FuntionString() {

//IF TEXT MATCH
if(txt1.text==txt2.text){
gotoAndStop(2);
}
//IF TEXT NOT MATCH
if(txt1.text!=txt2.text){
gotoAndStop(3);
}
}
=======================================================================
BUTTON INSIDE CODES
=======================================================================
// IF TEXT MATCH BUTTON INSIDE CODE
on(press){
txt2.text = Num1
FuntionString()
}
// IF TEXT NOT MATCH BUTTON INSIDE CODE
on(press){
txt2.text = Num2
FuntionString();
}
//BUTTON RETURN TO FRAME 1 INSIDE CODE
on(press){
gotoAndStop(1);
}



-----------------------------------------------------------------------------------------------------------

READ MORE
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000520.html
http://help.adobe.com/en_US/as2/reference/flashlite/WS5b3ccc516d4fbf351e63e3d118ccf9c47f-7f64.html
https://www.youtube.com/watch?v=Yt9Z-EQOgM0
http://www.homeandlearn.co.uk/csharp/csharp_s2p2.html
-------------------------------------------------------------------------------------------------------------

+ addition operator

expression1 + expression2
Adds numeric expressions or concatenates (combines) strings. If one expression is a string, all other expressions are converted to strings and concatenated. If both expressions are integers, the sum is an integer; if either or both expressions are floating-point numbers, the sum is a floating-point number.
Note: Flash Lite 2.0 supports the addition (+) operator for adding numeric expressions and concatenating strings. Flash Lite 1.x only supports the addition (+) operator for adding numeric expressions (such as var1 = 1 + 2 // output: 3). For Flash Lite 1.x, you must use the add operator to concatenate strings.

Availability

Flash Lite 2.0

Operands

expression1 - A number or string.
expression2 - A number or string.

Returns

Object - A string, integer, or floating-point number.

Example

Usage 1: The following example concatenates two strings and displays the result in the Output panel.
var name:String = "Cola";  
var instrument:String = "Drums";  
trace(name + " plays " + instrument); // output: Cola plays Drums 
Note: Flash Lite 1.x does not support the addition (+) operator for concatenating strings. For Flash Lite 1.x, you must use the add operator to concatenate strings.
Usage 2: This statement adds the integers 2 and 3 and displays the resulting integer, 5, in the Output panel:
    trace(2 + 3); // output: 5 
This statement adds the floating-point numbers 2.5 and 3.25 and displays the resulting floating-point number, 5.75, in the Output panel
    trace(2.5 + 3.25); // output: 5.75 
Usage 3: Variables associated with dynamic and input text fields have the data type String. In the following example, the variable deposit is an input text field on the Stage. After a user enters a deposit amount, the script attempts to add deposit to oldBalance. However, because deposit is a String data type, the script concatenates (combines to form one string) the variable values rather than summing them.
var oldBalance:Number = 1345.23;  
var currentBalance = deposit_txt.text + oldBalance;  
trace(currentBalance); 
For example, if a user enters 475 in the deposit text field, the trace() function sends the value 4751345.23 to the Output panel. To correct this, use the Number() function to convert the string to a number, as in the following:
var oldBalance:Number = 1345.23;  
var currentBalance:Number = Number(deposit_txt.text) + oldBalance;  
trace(currentBalance);
The following example shows how numeric sums to the right of a string expression are not calculated:
var a:String = 3 + 10 + "asdf";  
trace(a); // 13asdf  
var b:String = "asdf" + 3 + 10;  
trace(b); // asdf310 




EmoticonEmoticon