| Advance Scripting In Flash - Part 5 | In the previous article of Flash 5 Tutorial Series we had discussed about Set Variable, Set Property, Get Property, XY Position, XY Scale, Visibility, Rotation & Alpha. Now lets Continue with Math Objects, Date & String Function. Math Object I LN 2 Returns the natural logarithm of 2 (approx 0.693) Syntax : Math . LN2 Example : trace (Math.LN2); The output window will show a value 0.693 PI Returns the ratio of circumference of the circle to its diameter. Syntax : Math.PI; Example : trace (Math.PI); The output window will show a value of 3.14 SQRT2 Returns the square root of 2 Syntax : Math.SQRT2; Example : trace (Math.SQRT2); The output will be 1.414 LOG 2E The logarithm of E to the base of 2 Syntax : Math. LOG 2E; Example : trace (Math. LOG 2E); The output will be approximately 1.442 E Returns the Euler's constant and the base are of natural logarithms. Syntax : Math.E; Example : trace (Math.E); The output window will display a value of 2.718. Math Object II Math object is the top level object which can be used without using a constructor. With the methods and properties of this object, any kind of mathematical accessing and manipulation can be done. There are several methods of math object. They are: abs Returns the absolute value of a number. Syntax: Math. abs (); Example: On (press) { trace (Math. abs (-3.2)); } The output window will show 3.2 as the value. cos, sin, tan Returns the cos, sin and tan value of a number. Syntax: Math .sin ( ); Math .cos ( ); Math .tan ( ); Example: On(press) { trace (Math.sin(45)); trace (Math.cos (45)); trace (Math. tan (45)); } The output will be 3.2 0.5253219 0.850903 1.6197751 POW Returns the value of x raised to the power of y. Syntax : Math.pow (x,y) Example : trace (Math.pow(2,3)) The output window will show a value 8. Sqrt Returns the square root value of a number. Syntax : Math.Sqrt (x) : X - number for which square root has to be found. Example : Math .Sqrt (4) ; The output window will show a result 2. Date Get Year Returns the year of the date object, according to the local time. The year displayed will be year - 1900. Syntax : variable.get year ( ); Example : on (press) { a = new date ( ); b = a.get year( ); } where a is instance of date holding the current date (i.e. 2001/17/10) b will hold value "01" (i.e. 2001-1900) The last two digit of the year will be displayed, if getyear command is used. Get Full Year Returns the full year of the specified date, according to the local time. Syntax : variable .get full year ( ); Example : a = new date ( ); b = a.getfull year ( ); where value of a be 2001/07/10 value of b will be "2001" since get full year function will not display the last two digits, but it will give the full year (i.e. 2001). Get Month This command returns the month from the date object according to the local time. Syntax : variable.getmonth ( ); Example : a = new date ( ); b = a.getmonth( ); where the variable a holds 2001/07/10 (year, month, date, hour, minute, sec, milli sec) the variable b holds "10", the date will be displayed in the format (year/month/date).
|