Precision Angle Calculation Question.
I'm having an issue where I'll have two points, "a" and "b". I am trying to navigate point "a" to "b" ("b" stays stationary) in a straight line. It works if they're close enough together but the farther apart they are they more "a" misses "b" as it sails by. Does flash and actionscript round off to a low decimal accounting for the innacuracy? Or is it my math that is off?
ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)
Posted on: 03-02-2007, 04:40 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Angle Calculation, Display And Pivot Point
Hello,
I have a project and I'm really stuck on a direction to move.
(See attached pic) I have 2 lines (line M and L). A line intersects both with a point (point A) sitting on line M. I'd like to have the user move point A along the x axis using the point on line L as a pivot. Finally I'd like to show the angle (in degrees) of the interior angles (angles 1, 2, 3, and 4 in the pic)
I've been reading about the atan2 method to calculate angles but cant seem to wrap my brain around it. I'm also having difficulty figuring out how to set the pivot point.
Can someone point me in the right direction on where to start.
Thanks for any help
G
Attached Images
Precision Of _x
hello;
I have :
var booger = 48.45;
mc_instance._x = booger ;
trace ( booger ); //==> 48.45
trace ( mc_instance._x ); //==> 48.4
any thoughts
thanks
Shannon Burnett
Asheville NC USA
Better Precision On _x
Hello
How can I get better precision on a movieclip _x property than a tenth's pixel?
Or isn't that possible?!?
Regards Toben
Edited: 11/20/2006 at 02:55:32 AM by toben
Help Me Set Decimal Precision
I have this file which I am attempting to set decimal precision. Take a look at the ActionSctipt here and tell me why this isn't working. View the URL of the .swf and the .fla
http://web.csuchico.edu/~rp15/CDES270B
//code form a button where yellow and x are dynamic textfields.
//When subtotal reaches 29.5, it should display $29.50, instead it
//renders $29.5.
on (release) {
yellow += 2.95;
subtotal += 2.95;
// test variables initialized
var test = 0;
var test_num = 0;
test_num = subtotal%1;
if (test_num == 0) {
// whole number, append two zeros
subtotal.toString();
x = "$"+subtotal+".00";
} else {
// not a whole number so append one zero
test = (subtotal*100)%2;
if (test == 0) {
subtotal.toString();
x = "$"+subtotal+"0";
} else {
subtotal.toString();
x = "$"+subtotal;
}
}
}
MX Float Precision
Hi all
Just wondering how to cap a limit on the number of decimal places for a float. In Director its setting the floatPrecision, but how about flash?
Many thanks
pete
GetBounds() Precision?
Hello, I'm making (done) a getter/setter property for MovieClips to make it more convenient. Here is the code I use.
code: //LEFT
getLeft = function () {
var b = this.getBounds(_root);
return b.xMin;
};
setLeft = function (x) {
var b = this.getBounds(_root);
b = this._x-b.xMin;
this._x = x-b;
};
MovieClip.prototype.addProperty("_left", getLeft, setLeft);
//RIGHT
getRight = function () {
var b = this.getBounds(_root);
return b.xMax;
};
setRight = function (x) {
var b = this.getBounds(_root);
b = this._x-b.xMax;
this._x = x+b;
};
MovieClip.prototype.addProperty("_right", getRight, setRight);
//TOP
getTop = function () {
var b = this.getBounds(_root);
return b.yMin;
};
setTop = function (y) {
var b = this.getBounds(_root);
b = this._y-b.yMax;
this._y = y-b;
};
MovieClip.prototype.addProperty("_top", getTop, setTop);
//BOTTOM
getBottom = function () {
var b = this.getBounds(_root);
return b.xMax;
};
setBottom = function (y) {
var b = this.getBounds(_root);
b = this._y-b.yMin;
this._y = y-b;
};
MovieClip.prototype.addProperty("_bottom", getBottom, setBottom);
delete getLeft;
delete setLeft;
delete getRight;
delete setRight;
delete getTop;
delete setTop;
delete getBottom;
delete setBottom;
To test it out, I have a Flash file with this:
code:
//bounds.as is the code I showed earlier
#include "bounds.as"
thing._left = 0;
trace(thing._left);
I get -1 returned, didn't I just set it to 0?
Little Precision For The Install
Hi mate.
This is some precision for the installation of the flashcom trial, because I think it needs some (I search for 1 day why this ****ing apz not work lol).
I'm talking here for windows OS.
OK the first thing to now is that the trial version do not allow you during the install to choose where the directory "samples" will be ( YOUR SWF AND HTML FILE MUST BE IN THIS DIRECTORY TO BE ABLE TO CONNECT TO FLASHCOM). So if you're installing the flashcom to the default directory you will never be able to publish files you've done on the net cause user have to access this sample directory WHICH IS NOT NOW IN YOUR WEBROOT FORLDER.
So just install your flashcom in your webroot directory and don't forget that the file wanna use with flashcom MUST BE in the sample directory (which is now too in your webroot folder --> can publish on the net).
This is it. Very small but so ....
I tried to find why I was unable to change the sample directory when I found that with the developper version you are not able to change it. Only in the production one.
This is why we use this trick.
I hope this thread will help some others... And save their time.
C ya mate
Number Precision
Hi!
How can I round the number to a particular decimal place?
Example: 0.132456783929 should be 0.1324
Any cool algorithms or existing solutions for that?
Tnx!
Cheers
Precision Hit Test
hey guys i am working on a game for some mates, but i do not know how to add in precise hittests. Here is my fla, and i was wondering if someone could put it in for me. I no that sounds a bit scabby, but honestly i learn by having a code there and being able to change it to see how it is done.
AS3 Decimal Precision
Well I'm having a little problem with decimal in as3. Here's what I'm trying to do :
ActionScript Code:
var p:Number = 0;addEventListener(Event.ENTER_FRAME, mainLoop);function mainLoop(evt:Event){p+= 0.1;trace(p);}
And I get those weird results :
0.1
0.2
0.30000000000000004
0.4
0.5
0.6
0.7
0.7999999999999999
0.8999999999999999
0.9999999999999999
1.0999999999999999
In AS2, no problem, I get the right incrementation. Also, doing this in AS3 works well too:
ActionScript Code:
var p:Number = 0;addEventListener(Event.ENTER_FRAME, mainLoop);function mainLoop(evt:Event){p+= 1;trace(p/100);}
Any idea why this is happening?
Digit Precision
hello
i have a problem
i have a number stored in a variable , the number is lets say : 23.56789 and many other digits
i want to round it up to : 23.57
how do I do that in flash ? i only know how to round it up to an integer
please heeelp
What Is Flash's True Precision ?
According to the Flash documentation numbers can be double-precision, but in my tests I find that Flash is not nearly that precise. Example:
test1 = 123456789012345678; // 18 place holders
test2 = 12345678901234567; // 17 place holders
temp = test1 - 1;
test 1= test1 - temp;
temp = test2 - 1;
test2 = test2 - temp;
Now both test1 and test2 SHOULD equal 1, but test1 = 0 (due to loss of precision) and test2= 1. I really need double-precision (actually I really would love 128-bit precision), and this isn't anywhere close. Any clues?
_alpha Precision Error ?
Hi,
I'll try and assign _alpha something like this:
_alpha = 97.91666666
and when I trace _alpha's value I get:
_alpha = 97.65625
If I try and add the difference
(0.260416666) back into _alpha, it spits out the exact same number.
What's the reason for this? Why is _alpha adjusting the value I set it? Is there a way to rectify this precision error? Is it an error at all?
Cheers. =)
HELP Math Precision Error
Flash MX version6
The code below places a value of -4.44089209850063e-16 in the variable crx.
Then when attempting to add crx to 100 ... crx has NO value!!!!!!!!
Code:
var vax = -2.25;
var vay = 11.875;
var vaz = -0.187499999999829;
var vbx = 0.186139126359066;
var vby =-0.982400944672849;
var vbz = 0.0155115938632414;
var crx=( vby*vaz - vbz*vay);
var cry=( vbz*vax - vbx*vaz);
var crz=( vbx*vay - vby*vax);
var tmpVar = 100;
var tmpVar2 = tmpVar + crx;
trace(crx);
trace(tmpVar2);
HELP how do I deal with this !
Shipstern
Loss Of Number Precision?
Hi,
I have made a simple little thing (for lack of a better word) that draws a golden spiral both with straight lines and in curves. This is not the problem though, my code pretty much works. My problem is, that although both spirals look fine on their own, there seems to be a great loss of precision, mostly, I believe in the curved spiral. Notice that as the spiral progresses, is misses each turning point by more and more each time. Is Flash rounding or something similar?
Thanks, wil try and put more detail shortly
Maintaining Precision Through Equations
Hello,
I am working on a calibration calculator for work, and I've come to a sticky situation.
I have equations that take user input and provide the readings they should expect. My problem is with the decimal precision that my results show.
Orginally, I had just rounded the result values using the Math class, which would give just a flat number with no decimals. The problem is that that method destroys any precision they had.
For example, if their inputs are to two decimal precision then their output should be at that same precision.
I found RobertPrenner's post with his formatDecimal function, but it only solves half of my problem. Now I can keep decimal precision but I don;t know how to go about checking for the level of precision to use.
From what I remember from when I was an engineering major, the result of an equation can only be as precise as the least precise input. So if my inputs were 100, 5.9, and 2.64372, the result would have no decimal whereas if the input were 5.46, 3.564, and 3.291, the result would have two decimal places.
What I'm assuming I need is a good quick way to check the number of decimal places but I'm not real great with Actionscript.
I'm thinking what I would do is use '% 1' to get the remainder then count the length, but I'm not sure if that is soemthign I can do, or how exactly to do it.
Anyone have any experience with this problem?
[AS3] Number Compute Precision
Hello,
Number compute doesn't always give me good result.
How to explain it ?
For example :
Attach Code
var num:Number = new Number(32.55);
var num2:Number = new Number(10);
var num3:Number = num - num2;
trace(num + " - " + num2 + " = " + num3);
// gives 32.55 - 10 = 22.549999999999997
Precision Hit Test Needs To Be More Precise
Hey guys,
I am quite a way through creating my own game from scratch and i have smacked straight-on, head first into a triple layer brick wall.
As it is I have my hitTest code(Below.) which detects a hitTest on the _x and _y positon of my car MC. The code is placed on the background, however, as the car mc is large it overlaps the wall when they are driving, until the _x and/or _y position are colliding.
So, basically, I need it so it goes off the hitTest of my actual picture rather than the _x/_y postions, any ideas?
My code(partial) at the moment;
ActionScript Code:
<b>.....</b>x = Math.sin(_root.car.dude._rotation*(Math.PI/180))*_root.speed;y = Math.cos(_root.car.dude._rotation*(Math.PI/180))*_root.speed*-1;<b>.....</b>if <b>(!_root.land.map.hitTest(_root.car<font color="black">._x+x, _root.car._y+y,</font> true))</b> {_x += x*-1;_y += y*-1;<b>.....</b>
..... this just means there are bits of code i have, but have cut out
EDIT:: Sorry, exlude the [ color=black] and [ /color] the as they were placed in by the editor and not me, so they're not part of my code
Number Precision Problems
After a LOT of debugging, I finally tracked down what looks to be a bug in flash. If not a bug, then at the very least its a case of terrible documentation...
According to the Docs, the x and y values of a Sprite are of datatype Number.
However, they do not behave the same as real Numbers. They seem to lose precision very quickly.
Below is some code that illustrates the problem.
First lets test a real Number variable:
var i:int;
var n:Number = 113;
for (i=0; i< 10; i++){
n *= .5;
trace(n);
}
This produces the (correct) output:
56.5
28.25
14.125
7.0625
3.53125
1.765625
0.8828125
0.44140625
0.220703125
0.1103515625
Now lets test out the "Number" of the Sprite variable, x:
var i:int;
var s:Sprite = new Sprite();
s.x = 113;
for (i=0; i< 10; i++){
s.x *= .5;
trace(s.x);
}
This produces the (incorrect) output:
56.5
28.25
14.100000000000001
7.050000000000001
3.5
1.75
0.8500000000000001
0.4
0.2
0.1
What gives??
Why does the documentation say that Sprite.x and Sprite.y are Numbers when they clearly are not the same as the regular Number datatype?
Nested SWF Coordinate Precision
My problem: In a nested SWF, I can't change the x and y coordinates of an object by less than 0.05.
I have a simple SWF called movieOne. movieOne consists of a simple red square. I am loading movieOne into a SWFLoader object in another movie called movieTwo.
here's the code from movieOne:
Code:
mySquare.x += 0.05;
mySquare.y += 0.05;
trace(mySquare.x + ", " + mySquare.y);
there are two frames so it loops infinitely, and keeps incrementing the coordinates of mySquare.
when i play movieOne by itself, it works fine. here's the trace from movieOne:
Code:
0.05, 0.05
0.1, 0.1
0.15, 0.15
0.2, 0.2
0.25, 0.25
0.3, 0.3
0.35, 0.35
0.4, 0.4
0.45, 0.45
0.5, 0.5
etc...
When I load movieOne into an SWFLoader in another movie, for some reason it will only go up to 0.35 and then stop incrementing. the trace from movieTwo shows:
Code:
0.05, 0.05
0.1, 0.1
0.15, 0.15
0.2, 0.2
0.25, 0.25
0.3, 0.3
0.35, 0.35
0.35, 0.35
0.35, 0.35
0.35, 0.35
etc...
to make things more bizarre, if i change the increment value to 0.1 instead of 0.05, it works fine in movieOne AND movieTwo.
any ideas?
Flash Sound Transform Precision
So I am trying to create a program that adjusts the volume of a sound based on Decibel levels and not sound volume/pressure as the sound transform class in flash 9 does. The formula for this I have found to be 0.00002 * Math.pow(10, (DBval/20));
The problem is that the sound volume in Flash moves smoothly downward until 0.01 is crossed. Giving the SoundTransform a volume of 0.0089 will have a massive drop in volume. The documentation makes no mention of the precision that is supported. Is there a way to fix this jump using the exsiting sound class? Is there a way i can write my own sound transformation class that scales smoothly? I can't find documentation/code for how the SoundTransform and Sound classes are implemented.
In the worst case is there a way i can use quicktime or something to play these sounds? If I can't fix this then flash/flex are useless to our team for altering precision sound.
Precision Color Control And The Math Behind Transparency
Would someone be able to point me to the mathematical equations behind calulating transparencies and tints and movie color transforms, as well as the methods that are used for tweening properties.
I am working at a visual psychophysics lab and so we are very particular about what the software is actually doing when calulating a transparency.
For example, supose I have a grey object (RGB= 150,150,150) that is covered by a
blue grey object (150,170,190) at 50% alppa. It creates a color that is (150,160,170). But if
the blue grey object is tweening from 50% to 100% alpha, then on frame 5 out of 6, how do you determine the color of the area?
In the blue channel is it
150 + (170-150)(5/6) =
(round down?)
Question group ONE:
Are all the transitions linear?
How does rounding work? At the 5/6?
Or at the end of the computation? Is it round up after .5 or does it floor or ceiling?
Question group TWO:
How do tints work? If a movie clip is is tinted but contains colors that that are alpha'd, the what is the order of opertations. Lets say you were over the same grey obect, but the blue grey object was in a movie clip with a tint. How does the math work?
Question group THREE:
I notice that there are is ra,ba,ga as well as rb,ba and gb. Could you explain how these work if you change a property of a movie clip?
(Using something like newColourObject.setTransform(colourTransform)
Again I am wondering about the order of calulations with relation to the other types of modification like alphas inside of movie clips or tints aplied to the whole movie clip.
Thanks!
3d Calculation
http://www.nlc.net.au/~oceana/3d/3d.htm
On the webpage are 2 graphics which explain my question (I'm not so sure about figure 2). I need two equations;
-----------------------------------------------------------
Figure 1. I want to derive (x3,y3 - the point at which the line intersects with the plane) from the other co-ordinates (x1,y1,z1),(x2,y2,z2),(x4,y4,z4),(x5,y5,z5),(x6,y6 ,z6),(x7,y7,z7)
-----------------------------------------------------------
Figure 2. Rotating a point: I want to derive (x2,y2,z2) from (x1,y1,z1), a1, a2
-----------------------------------------------------------
First and formost, i'm stupid.
I've looked at the 3d tutorials and movies and again...i'm stupid.
-----------------------------------------------------------
If anyone could give me these 2 equations, USING THE VARIABLES THAT I HAVE GIVEN, you would be single handedly responsible for unleashing the worlds stupidest flash coder into the world of 3d.
Finally, i'm stupid... should have paid more attention in school.
Any help is greatly appreciated, thanks!
BlinkOk (posted in games/actionscript/3d)
MMP Calculation
I have a problem, In flash MX i have 120 pic and a few textboxes. what i need to do is get the values from the textboxes devide them by 120 odd numbers. So far so good
The problem i have is that i cant figure out how i can take the returned quotients and sort them so i get the highest 120 and still know from which text box they came from.
Can Anyone help.
Calculation
Hi, very newbie here.
I need to build a calculation.
Where X times Y% equals total. ( X xY%=? )
I need a separate box for each number.
Does anyone have any ideas for this or could point
me to a tutorial about it?
It's just a little ditty for my home web site.
Thanks in advance
frobby
Calculation Help
I'm making a volumetric converter for a site and with a bit of help from Fkit I've figured out the basics. However it gives the answer to lots of decimal places. How do I make it give the answer to one decimal place, please?
AS Calculation
I need to determine the number of pages of my catalog in order to make them visible or not.
- Every page contains 6 items, so If myCatID_A contains 12 items :
THEN this will give 6/12 = 2 pages (good !!).
- But if my CatID_B contains 13 I'll have 13/6 = 2.166666666666 !!!! How to tell to A.S that he need to count 3 pages instead of 2.xxxx ???
Thank you,
Calculation
I cannot get to make an item (veg1) turn into a value ($1.99). when I click on the squares on the left, a name appears in each text box. Then I need to input an integer. By pressing total_btn, it should calculate all the sub1_txt + ...+ sub4_txt.
Kindly advise how to make it to work.
Date Calculation
Was wondering if anyone knew and equation to calculate the weeks of the year. That could be done in flash.
I am creating a front end for a data base system, and well I want to display the weeks.
Thx.
Help On Simple Calculation
Hi everyone.
I know what I am asking is a very simple thing.Its simple calculation.
But I am just not able to figure it out. Please help.
What i want to do is make a simple calculation on some question like
How old are you
i.under 15 we will award him 4 points
ii.15 to 30 we will award him 3 points
iii.30 to 50 we will award him 2 points
iv.50 plus we will award him 1 point
How much do you weigh
______ kgs
What is your height
______ cms
Ideal body weight in kilos is your height in centimeters minus 100. So if you are 175 centimeters tall, you can be up to 75 kilos. Your ideal weight range would be between 72.5 – 77.5 Kilos.
Users within the weight range get 5 points
Users 1 – 5 kilos above or below rangeget 4 points
Users 6 – 10 kilos above or below range get 3 points
Users 11 – 15 kilos above or below range get 0 points
Users 16+ kilos above or below range get -10 points
The maximum score that a user can get is 9. That is for users who are under 15, within their weight range.
I want to know how would I calculate the weightage and the different varitions in weight ranges.
I am also attaching the FLA.
Kindly help please
Pause In Calculation?
Hello,
I've made a flash to calculate some numbers.
There are lots of calculations to be done in the press of one button but for some reason the correct end result is not reached unless i press the calculate button twice.
Here is my code...
function onCalculate() {
one = Number(Head);
two = Number(Forequarter);
three = Number (Hindquarter);
four = Number (Gait);
five = Number (ntb);
six = Number (coat);
seven = Number (size);
eight = Number (temperament);
nine = Number (showshine);
ten = Number (feet);
eleven = Number (headsop);
twelve = Number (forequartersop);
thirteen = Number (hindquartersop);
fourteen = Number (gaitsop);
fifteen = Number (ntbsop);
sixteen = Number (coatsop);
seventeen = Number (sizesop);
eighteen = Number (tempermentsop);
nineteen = Number (generalsop);
twenty = Number (feetsop);
twentyone = Number (headsoptotal);
twentytwo = Number (forequartersoptotal);
twentythree = Number (hindquartersoptotal);
twentyfour = Number (gaitsoptotal);
twentyfive = Number (ntbsoptotal);
twentysix = Number (coatsoptotal);
twentyseven = Number (sizesoptotal);
twentyeight = Number (temperamentsoptotal);
twentynine = Number (generalsoptotal);
thirty = Number (feetsoptotal);
headsoptotal = one*headsop;
forequartersoptotal = two*forequartersop;
hindquartersoptotal = three*hindquartersop;
gaitsoptotal = four*gaitsop;
ntbsoptotal = five*ntbsop;
coatsoptotal = six*coatsop;
sizesoptotal = seven*sizesop;
tempsstotal = generalsoptotal*temperamentsop;
generalsoptotal = (eight+(nine/2))/2;
feetsoptotal = ten*feetsop;
sum = headsoptotal + forequartersoptotal + hindquartersoptotal + gaitsoptotal + ntbsoptotal + coatsoptotal + sizesoptotal + tempsstotal + feetsoptotal;
total = sum*10;
}
I think it has something to do with the caculations in the bold line,
tempsstotal = generalsoptotal*temperamentsop;
I just want to be able to press a 'calculate' button once and for the program to work it all out in one go any idea's anyone?
Thanks in advance
Ady
p.s dont laugh at my code, i'm very new to this!
MX Simple Calculation Help
I want to make a simple calculation tool, but I have no idea where to start. It looks pretty simple as I am sure it is not that hard to make.
All I need to do is have an imput box where someone can put in a number the have it auto multiply that number by .30. Then take that # and multiply it by 12
here is an image incase I didn not explain it well
183 Days Calculation
I’m new so I’m Justin. In my epic battle between a Lotus Notes developer and my attempt to transition to HTML and Flash I have ran into a problem. In our current database (in Lotus Notes) there is a 183 day calculator for someone who tested. You put in their test date and get the date they can retest. Is it possible to do the same in flash? Could someone show me how please?
Calculation Question
i have some drag and drop object. how can i give them some value etc(cost, engery they used)??? and then do a calculation to between them?
Simple Calculation (anyone Know How)
I have price * amount = total
amount is an input box
so the user can input any amount they require
press a button and it will work out the total
CalculatePrice = function (answer) {
P = Price;
A = Amount;
the_total = P*A;
return the_total;
};
submit.onRelease = function() {
text_answer = CalculatePrice(the_total);
};
The above works
got that work working but i need lots of these, now am a bit stuck here is the code that does not work:
CalculatePrice = function (answer) {
P = Price;
A = Amount;
P1 = Price1;
A1 = Amount1;
the_total = P*A;
the_total1 = P1*A1;
return the_total , the_total1;
};
submit.onRelease = function() {
text_answer = CalculatePrice(the_total);
text_answer1 = CalculatePrice(the_total1);
};
As you can see I have more than one total to work out, does anyone know how to do this? if so please let me know.
I have also attached the .fla
Flash Calculation
I have 4 digital display components with instance names mat, oat, rat and %oa
I’m trying to write a flash calculation that computes mat and displays the result
My formula is mat = (oat-rat)(%oa) + rat
The operator would input the outside temperature (example 85)
Then they would input the return air temperature (example 72)
Then they would input the percent outside air (example 10% or .1)
Then the operator would press a button and the values would be plugged into the equation and computed and the answer displayed on the mat display
Mat=(85-72)(.1)+ 72
Mat = 73.3
Variables are:
Mat is mixed air temperature
Oat is outside air temperature
rat is return air temperature
%oa is percent outside air
curTemp1 = mat.val; this reads the value of the display
curTemp2 = oat.val; this reads the value of the display
curTemp3 = rat.val; this reads the value of the display
curTemp4 = %oa.val; this reads the value of the display
how would I write the code for this
Flash Calculation
I have 4 digital display components with instance names mat, oat, rat and %oa
I’m trying to write a flash calculation that computes mat and displays the result
My formula is mat = (oat-rat)(%oa) + rat
The operator would input the outside temperature (example 85)
Then they would input the return air temperature (example 72)
Then they would input the percent outside air (example 10% or .1)
Then the operator would press a button and the values would be plugged into the equation and computed and the answer displayed on the mat display
Mat=(85-72)(.1)+ 72
Mat = 73.3
Variables are:
Mat is mixed air temperature
Oat is outside air temperature
rat is return air temperature
%oa is percent outside air
curTemp1 = mat.val; this reads the value of the display
curTemp2 = oat.val; this reads the value of the display
curTemp3 = rat.val; this reads the value of the display
curTemp4 = %oa.val; this reads the value of the display
how would I write the code for this
Simple Calculation
I'm trying to do a simple calculation but I'd really like the answer to round to the nearest 2 decimal places. It is a financial calculator. I don't know much actionscript...
Any help is greatly appreciated!
----------------------------
function onCalculate() {
one = Number(number_one);
two = Number(number_two);
result_sum = one + 15 + 50;
result_product = result_sum * 1.1;
}
Calculation Help Needed
Hi There,
I'm a bit new to actionscripting. I'm creating a calculator in flash, basicly recreating something that was created in excel. My questions is, is there any tutorials or any sample code that someone could point me to where I can learn from. I'm basicly looking to have a user enter data into about 12 text input information and then after that execute calculations based on the inputed information.
Thanks in advance for any help.
Calculation Help Needed
I've built a calculator in flash and I can't get the function to calculate. Is there anyone that might be able to chat with me to figure this out? My aim is spectsteve7.
Thanks in advance.
Date Calculation
Hello,
I searched through the forums and couldn't find exactly what im looking for. Basically i have a Trivia flash movie that changes the trivia each day. I have 365 trivia questions set up and need to be able to calculate what number day it is of the year. Using typical date functions only gives me the day of the month and i need it on a 365 day basis.....so i can change the trivia for a year without it repeating.
Thanks in advance,
Chris
Reverse Calculation
Okay, I'm going to ask someone a huge favour..
I have been working with this all day but cant seem to figure it out..
Math problem again
anyway, I have a function that calculates y based on a property called Y, and some other variables as well, like z, in order to get the perspective-view I want for my game.
and in my editor i've made, I have what you could call a reversed version of that function. it calculates the Y based on y, so I could click the mouse somewhere and it would place it at the right Y in gamespace.
At first this was easy to do, when the calculation looked something like this.
ActionScript Code:
y= horizon+Y*z+z/10;
then the reversed function would look like this.
ActionScript Code:
Y= (y-horizon-z/10)/z;
that's pretty simple, altough I admit that does confuse me a bit.
and now when I have added more compexity to the function for more depth I just cant manage to reverse it. this is what it looks like...
ActionScript Code:
y=int(horizon+z/ground*(600-horizon)+(Y+(0-(Y*Y)/(((600-horizon)/18.5)*(600-horizon))))*(z/100));
yep, that's a big bad one. I started out with cutting out almost all of the function, then adding bit by bit while updating the reversed function.
I only got as far as this..
ActionScript Code:
y= (Y+(0-(Y*Y)));
reversed version:
ActionScript Code:
Y=y-(y-(Math.sqrt(0-y)));
and now it gets confusing, I cant even think straight, all I do is moving around the divisions and stuff and hope it will give the correct result.. but im not getting anywhere =
I really hope someone would help me with this, even if just pointing me in the right direction.
Any comment would be welcome.
Thank you =)
String Calculation In AS3
I have made this StringCalc class in AS3, which parses a string into objects and then calculates it. Before I made it, I googled around to check if there existed anything like it, but i could only find unanswered questions asking for the very same thing, or unfinished attempts.
Now I am throwing this out here, both to share it and hopefully to get some suggestions on how to make this class more efficient. It also proably contains bugs, and should do more errorhandling. All comments are appreciated. I have coded it in Rambo style, it does the job, but looks rather messy. I would think there are better practises, but im not very experienced in this kind of coding.
It currently support addition, subtraction, division, multiplication and ordered operations (parantheses)
Usage:
trace( StringCalc.calculate("4*(2+10)") );
Test with this example here
PHP Code:
package no.muldal.math {
public class StringCalc {
public static function calculate(value:String):Number {
var s:String = value;
// Convert nonenglish comma desimal delimiters to
// english dot
while (s.search(",") != -1) {
s = s.replace(",", ".");
}
// These two loops beneath appends the proper
// multiply sign when a formula is written
// like 2(2+2), and converts it to 2*(2+2)
for (var g:int = 0; g < s.length; g++) {
if (s.charAt(g) == "(" &&
s.charAt(g-1) != "(" &&
s.charAt(g-1) != "+" && // if operator is already assigned, skip
s.charAt(g-1) != "-" &&
s.charAt(g-1) != "*" &&
s.charAt(g-1) != "/" &&
g != 0 // if it is not the first char
) {
s = s.substring(0, g)+"*"+s.substring(g, s.length);
}
}
for (var h:int = 0; h < s.length; h++) {
if (s.charAt(h) == ")" &&
s.charAt(h+1) != ")" &&
s.charAt(h+1) != "+" && // if operator is already assigned, skip
s.charAt(h+1) != "-" &&
s.charAt(h+1) != "*" &&
s.charAt(h+1) != "/" &&
h != s.length-1 // if it is the last char, dont append
) {
s = s.substring(0, h+1)+"*"+s.substring(h+1, s.length);
}
}
// Code beneath sorts out the ordered operations
// into a xml structure. I used XML cause it was
// easy to debug and navigate in.
var equation:XML = <equation/>;
var currentOrder:XML = equation;
var startIndex:int = 0;
for (var i:int = 0; i < s.length; i++) {
var o:XML;
var e:String;
if (s.charAt(i) == "(") {
e = s.substring(startIndex, i);
if (e != "") {
currentOrder.appendChild(e);
}
startIndex = i+1;
o = <order/>;
currentOrder.appendChild(o);
currentOrder = o;
}
if (s.charAt(i) == ")") {
e = s.substring(startIndex, i);
if (e != "") {
currentOrder.appendChild(e);
}
startIndex = i+1;
currentOrder = currentOrder.parent();
}
if (i == s.length-1) {
e = s.substring(startIndex, i+1)
if (e != "") {
currentOrder.appendChild(e);
}
}
}
// This traverses the operations in the correct
// order and calculuates them accordingly
var t:Function = function(order:XMLList):* {
var eq:String = "";
for (var j:int = 0; j < order.length(); j++) {
if (order[j].nodeKind() == "text") {
eq += order[j];
} else if (order[j].localName() == "order") {
eq += arguments.callee(order[j].children());
}
}
return calc(eq);
}
t(equation.children());
return t(equation.children());
}
// The calculating function. Splits the operation
// by operators into objects in an array, which
// makes it easy to calculate the actual equation
private static function calc(eq:String):* {
var startIndex:int = 0;
var a:Array = new Array();
for (var i:int = 0; i < eq.length; i++) {
var o:Object;
if (eq.charAt(i) == "+") {
o = new Object();
o.operation = "add";
o.value = eq.substring(startIndex, i);
a.push(o);
startIndex = i+1;
} else if (eq.charAt(i) == "-") {
o = new Object();
o.operation = "subtract";
o.value = eq.substring(startIndex, i);
a.push(o);
startIndex = i+1;
} else if (eq.charAt(i) == "*") {
o = new Object();
o.operation = "multiply";
o.value = eq.substring(startIndex, i);
a.push(o);
startIndex = i+1;
} else if (eq.charAt(i) == "/") {
o = new Object();
o.operation = "divide";
o.value = eq.substring(startIndex, i);
a.push(o);
startIndex = i+1;
}
if (i == eq.length-1) {
o = new Object();
o.operation = "none";
o.value = eq.substring(startIndex, i+1);
a.push(o);
}
}
var result:Number;
// If there is no value, insert zero.
// I.e. if a user has written -2+2, this equals to
// the equation 0-2+2 etc.
if (a[0].value == "") {
result = 0;
} else {
result = parseFloat(a[0].value);
}
for (var j:int = 0; j < a.length; j++) {
// If there is no value, insert zero. Prevents
// script from breaking, when users insert stuff
// like 2+++2, which translates here to 2+0+0+2
// Probably should return error instead?
if (j != a.length-1) {
if (a[j+1].value == "") {
a[j+1].value = "0";
}
}
if (a[j].operation == "add") {
result += parseFloat(a[j+1].value);
} else if (a[j].operation == "subtract") {
result -= parseFloat(a[j+1].value);
} else if (a[j].operation == "multiply") {
result *= parseFloat(a[j+1].value);
} else if (a[j].operation == "divide") {
result /= parseFloat(a[j+1].value);
}
}
return result;
}
}
}
My usecase is a project I am working on that has a WebService that returns formulas in a string. Later I will add support for translating predefined variables which exist in the same WebService. Then it will be able to calculate i.e. (Tp*Sp) where Tp is bound to a slidebar etc.
Strange Calculation
Hello Friends,
I'm doing a simple calculation here like :
Gamma = _root.Punit;
Neutron = stepperMain.value;
Sigma = Gamma + Neutron;
trace(Gamma);
trace(Neutron);
trace(Sigma);
totalPrice.text = Sigma;
------------------
And if Gamma is equal to 13,90
and if Neutron is equal to 2
the result is 13.92 !!!! super !! Grrrrrrrrrrr!
if you can help !
thanks
Mileage Calculation
Hi, Got a project where I need to get values for total miles between two cities (US). Does anyone have a script or example for how to get the values based on a text field and dropdown menu for state?
Thanks.
Random Calculation?
http://www.moond.com/main.html
any expert can give some opinions or methods to do the plant growing like that website?
Surface Calculation
Hi, My Boss asked me to make a programm with which a object could be drawn (mathematic shape 6 edges) and the surface of that object could be calculated. Is there anyway this could be done with Flash ?
|