Flex :: Actionscript 3 - How To Use Math Mod Function
Aug 25, 2011How to use math mod function in flex?
calculate like this 7 mod(%) 2 = 1
How to use math mod function in flex?
calculate like this 7 mod(%) 2 = 1
I'm new to Actionscript programming. I'm trying to figure out what is the best way to return multiple variables, each having a different data type, from a function. For example, if a function needs to return variable aa ( a string) and variable bb (a number).
The function I'm using just crunches a lot of math, and doesn't relate to an object in a GUI. One method I got from a Google search used an Object, but as (I think) this requires me to create a class, I wondered if there was a simpler way. Since an array can hold elements of different data types, perhaps this is a simpler approach (?). [code]...
I wonder how to make a Math.random() function, or something similar where it chooses a number from 0-9. But as the program progresses, another random variable will appear. That random value is what I want removed from the 0-9 scale. (The other random variable is also from 0-9)
View 4 RepliesHow can I make Flash calculate the value of the function y= (1 - x^2)^3 where x is the user input value?
View 3 RepliesFor some reason my math.floor function is not working (trace yields "undefined")..[code]
View 2 RepliesI am new to Flash and Action Scripts. I am trying to put together some Mortgage Calculators for a client and am having issues getting the syntax for the formula correct. Below is my code could someone look it over and give some pointers on how to structure the formula. It is a standard mortgage payment calculator. num1 is Loan Amount num2 is interest rate and num3 is loan term they are the instance names of the unput text boxes.
equels_btn.addEventListener(MouseEvent.CLICK,equel sClick);
num1.border = true;
num2.border = true;[code]........
I get the folowing error when I click the equels_btn
TypeError: Error #1006: value is not a function. at LoanPayment_fla::MainTimeline/equelsClick()
I am generating random numbers between 1 and 90 how do I do it so I don't get any repeats. Here is the code I am using.
ActionScript Code:
var num:Number = Math.ceil(Math.random()*90);
I cant get this to work. I think its pretty self explanatory what I want to do, set _x to a random position (b1 - b6)
Code:
onClipEvent (load) {
stop();
b1 = 462;
b2 = -462;
b3 = -1388;
b4 = -2314;
b5 = -3240;
b6 = -4166;
} onClipEvent (load) {
RanNum = Math.ceil(Math.random() * 6);
_x = ["b" + RanNum];
}
I have problem about math. I want write function of laplace transform in flash.
X(s)=kd*s^2 +kp*s+Ki;
F(s)=s^3 +(10+kd)*s^2 +(20+Kp)*s+Ki;
Gc(s)=X(s)=/F(s);
How I write code(actionscript) in flash, when Kp Ki Pd is value of user input. And S is Laplace transform.
Here is the problem:
var p:int = 0;
var n:Number = 0;
n = 32.999999999999999;
p = Math.floor(n);
trace(p); // returns 33
n = 32.11111111111111;
p = Math.floor(n);
trace(p); // returns 32
I would expect both of these to return 32. I have searched, and it seems this is an unreported bug in AS3. Or ... am I doing something wrong?
How do you round a number to 2 decimal places using the Math.round function?
View 3 RepliesI want to make a function like y= (1 - x^z), where both x and z are user input values. How is that possible?
View 1 RepliesWat is the diffrence between these two?
View 2 Replieswat's the difference between finding a angle using Math.atan2(y,x) function and by finding using the movie clip's rotation (mc._rotation*Math.PI/180);
View 9 RepliesI have a code in which I have to use Math.round if a certain value is for example 3.67 (67 is higher than 50) and Math.ceil if a value is for example 3.23 (23 is lower than 50). What can I do to make flash calculate if what after the dot �.� in 3.23 (for example) is higher than 50?
View 2 RepliesI'm trying to rotate a point in my Canvas from a given point (center). In my MouseDown handler, I save the point where user click (oldPos), and in my MouseMove handler, I'm doing this:
private function onMouseMove(event:MouseEvent):void
{
// Where the user pointer right now
[code]......
I am trying to construct an equilateral triangle with the following code, but I am not seeing what I would expect to. I would expect to see a triangle drawn to the stage, but I don't see one. I think there must be something wrong in terms of the location of the tri sprite on the screen.
[Code]...
UPDATE: I can now see the triangle but it is not filled in. It seems to have the generally-correct shape, but I would expect for it be 3 sided, rather than 4.
I'm trying to build a calculator in Flex / actionscript 3 but have some weird results using the class Math :
trace(1.4 - .4); //should be 1 but it is 0.9999999999999999
trace(1.5 - .5); //should be 1 and it is 1
trace(1.444 - .444); //should be 1 and it is 1
trace(1.555 - .555); //should be 1 but it is 0.9999999999999999
I know there are some issues with floating point numbers, but as you can see, it should at least fail for all of my examples, am I right?How the problem is solved in other calculators and how should I proceed in order to build a usable calculator in Actionscript 3 .
I have a video player in flex which constantly plays a movie. Is there a way to see how many times it has played? So each time the movie is played, text filled populates with +1.
View 1 RepliesSo here is a piece of code that I have seen used a lot but don't really quite understand:
myVar = Math.min(Math.max(myVar, this.min), this.max);
or some variation thereof. I understand that the function first finds the maximum value of two values then turns around and uses that to find the minimum between two values.why this is done? And how do you know when to use it?
So here is a piece of code that I have seen used a lot but don't really quite understand:[code]or some variation thereof. I understand that the function first finds the maximum value of two values then turns around and uses that to find the minimum between two values.And how do you know when to use it?
View 3 RepliesLet's say I have a Custom Event Class, and it has several Event types stored in static Constant:
[Code]...
Is there an easy way to validate that the type passed to the Constructor is one of the Static Constants of the Class, without having to check it against each value?
I have an AS3 program that calls a function multiple times. The function must return multiple variables, so I created a class for the function to declare an object containing all of these variables. For example, here's my class:
package
{
public class PER
{
[Code].....
Let's say the calling program calls the function, which returns the variables into data_set1 (where data_set1 depends on input variables arg1, arg2, arg3) using:
var data_set1:PER = function_name(arg1, arg2, arg3);
The calling program does some stuff, then calls the function again, but returns the variables into a new variable name, data_set2:
var data_set2:PER = function_name(arg4, arg5, arg6);
My intention is that data_set1 and data_set2 are different (e.g. not linked together).
My question is, given that arrays are passed by reference, will data_set1 be modified to agree with data_set2 upon the 2nd function call? Why or why not?
Given a Function object, can you get its name as a String? See example:
function doThingWithCallback(callback:Function):void {
trace("i'm going to run " + callback); // outputs "i'm going to run function Function() { }"
}
[code]....
This example is sort of arbitrary, but it would be very useful to get function names for debugging, particularly when passing around Function objects.
I have created a flash 3d racing game which relies heavily on AS3's Math functions (sin, cos, tan, asin, acos, atan). It also makes heavy use of Matrix3D and Vector3D functions. The game works great on a PC, but the cars flip around and display innacurate positions on Mac computers. I know this is an issue due to the note on the Math docs page: [URL]
which states: "Note: The Math functions acos, asin, atan, atan2, cos, exp, log, pow, sin, and sqrt may result in slightly different values depending on the algorithms used by the CPU or operating system. Flash runtimes call on the CPU (or operating system if the CPU doesn't support floating point calculations) when performing the calculations for the listed functions, and results have shown slight variations depending upon the CPU or operating system in use."
how do I get this game to work on a Mac? I've tried using lookup tables and inline FastMath style approximations. But lookup tables still create the same problem, and the inline approximations I have found are not accurate enough for my game. I've also tried rounding values with floating point errors, but that has not seemed to help (in my implementation) either. I think the specific problem is with the use of Math.atan. I have not found an accurate approximation for this.. but I maybe that is not even necessary.
How do I get a random number between 0.8 and 1.2 using Math.random(); ? It would be nice if you explain.
View 1 RepliesWhat is math.round() do? In kirupa's Random numbers tutorial, he explained the use of math.floor(), but said round() was for another time. Yet I see that, and not .floor() in use in the random movement tutorial.
View 1 RepliesAre there any math libraries for as3?
I need primarily statistics and regression formulas.
[Code]....
why is it undefined?
here's where all you math genius' get to help me out. I know that this principal is not difficult and was taught sometime during my highschool years.I need a math formula which reduces the ratio of any x:y to the smallest quanity possible. Basicaly so that the smaller of the two numbers is 1 and the other number is whatever it would be, compared to 1... but, I need it to work for both posative and negative numbers.(I'm the ultimate Math newb.. bear with me)
so. I have x=20, y=20 is 1:1
-20, y=-10 is -2:-1
x=10, y=-5 is 2:-1
ect.
so what is the formula for that?