One Line Of Math Including Math.abs()
Ok, Ive tried and tried again
I want
if (//the absolute value of Xspeed plus the absolute value of Yspeed is greater than 10) { boundaries(); }
FlashKit > Flash Help > Flash Newbies
Posted on: 12-17-2008, 06:15 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Controlling The Odds Of Math.floor(Math.random()
Hey,
Is there a way to set a random number in a array to showup maybe once a day. Or every 5000 views or loops, or something like that. I would love to be able to control the odds of a array. Cheers!
ActionScript Code:
var pic_array = new Array();
pic_array[0] = "images/1";
pic_array[1] = "images/2";
pic_array[2] = "images/3";
pic_array[3] = "images/4";
pic_array[4] = "images/5";
pic_array[5] = "images/6";
pic_array[6] = "images/7";
pic_array[7] = "images/8";
pic_array[8] = "images/9";
pic_array[9] = "images/10";
pic_array[10] = "images/11";
pic_array[11] = "images/12";
pic_array[12] = "images/13";
pic_array[13] = "images/14";
ranNum = Math.floor(Math.random()*pic_array.length);
holder_mc.loadMovie(pic_array[ranNum]+".jpg");
[math] Line Of Sight
Last edited by Nutrox : 2004-11-22 at 09:14.
Hi guys.
I was just wondering if anyone knows how to work out the following...
I'm working on a platform based shooter and have sorted out all of the "line of sight" stuff that needs to be done. However, if the player tries to shoot through a platform (or wall) I would like a "spark" type of effect where the bullets would hit the platform (or wall).
Here's a quick pic of what I'm talking about:
The info I have to work with is... the X Y of where the bullet was fired from, the X Y of the target (cross-hairs) where the bullet will travel to, the X Y W H of the first platform (or wall) that the bullet's path passes through.
All I need to work out is the X Y of where the "spark" effect should be placed against the paltform (or wall).
I hope that makes sense
Cheers,
Si ++
Edit: One thing to keep in mind is that the bullets won't be displayed as movie clips in the game, so I can't use them for any collision detection.
MATH: General Math Ratio Formula?
So I have these sets of values that correspond with other values. But the manufacturer only gave me sets by 5. I need to break it out for every integer. Here's what I got ...
Code:
20=35
25=54
30=78
35=106
40=138
45=175
50=216
55=261
60=310
My question is how do I develop a formula in Flash that can give me values for numbers not divisible by 5? Accuracy to the nth power, figuratively speaking, isn't crucial.
Big thanks,
Layne
Math Help... Find Center Of A Line
hello, i need a little help finding a formula that can determing the center of a line.
lets say a line is drawn from (-30, -200) to (50, 300) in a movie clip. I need to be able to determing the coordinate of the center of the line.
thanks alot for any help. this should be easy, but for some reason my codes aren't finding the center.
MATH Distance To A Line From A Point
Hi Guys,
Does anyone know a function/formula for getting the distance from a point to a line (i.e. the closest point on the LINEAR line to the point).
It's really driving me nuts! I've found heaps of Math functions on the net, but I'm just not sure how to apply them in Flash...
Any help you wizards can provide would be awesome!
Thanks,
Lars
Find The Points In A Line (Math)
Oooo.. i'm trouble to find a points in a line Actually i want to make some footsteps in a sand. The footsteps are dhynamically placed on the stage. How to find the points in a dioganal. see the image
MATH Distance To A Line From A Point
Hi Guys,
Does anyone know a function/formula for getting the distance from a point to a line (i.e. the closest point on the LINEAR line to the point).
It's really driving me nuts! I've found heaps of Math functions on the net, but I'm just not sure how to apply them in Flash...
Any help you wizards can provide would be awesome!
Thanks,
Lars
Find The Points In A Line (Math)
Oooo.. i'm trouble to find a points in a line Actually i want to make some footsteps in a sand. The footsteps are dhynamically placed on the stage. How to find the points in a dioganal. see the image
Math.round(Math.random()*4)+1
Will this return values of 1 to 5 (inclusive).
If not, anyone know how to get random whole numbers 1 to 5?!
Cheers.
Dongle
Math.ceil Ll Math.floor
Hi there,
I have code to dynamictween my mc's.Works great.I only need the if statement to work so when my square reaches it's new size and position I can load in my content using a holder.Can someone help me out on this if statement.
and instead off scaling the holder,etc I want to control it's xy position when hitting but0,...
but0.onRelease = function()
{
_root.square.dynTween({duration:6, _y:[350, "In", 60], _yscale:[200, "out", 5], callback:"_root.action1"});
if (Math.ceil(this._dynTween) == Math.ceil(_root.square) || Math.floor(this._dynTween) == Math.floor(_root.square)) {
if (_root.squareTrigger == 1) {
if (_root.squareLoaded == undefined)
_root.square.squareHolder.loadMovie("content0.swf" );
_root.square.squareHolder._xscale = 33;
_root.square.squareHolder._yscale = 33;
_root.square.squareHolder._x += 35;
_root.square.squareHolder._y += 35;
_root.squareLoaded = 1;
}
_root.square.squareHolder._visible = true;
_root.squareTrigger = 1;
}
}
}
Grtz,
Math.atan && Math.atan2
Can someone please expplain to me what does Math.atan2 and Math.atan returns? I made a file to try to understand, but I cant figure out what they do!!!
I saw a lot o fo files wich use those actions, but still couldnt understand.
Var I = Math.round(Math.random()*1)
this should return either 1 or 0?
but it seems to be returning something else as well and i dont know what it is???
function startXPos() {
var i = Math.round(Math.random()*1);
_root.test1 = i;
_root.test2 = t;
return i;
}
i have this just after
if (startXPos() == 0) {
startX = -500;
endX = 750;
} else if (startXPos() == 1) {
startX = 750;
endX = -500;
} else {
startX = 0;
endX = 0;
}
_root.test3 = startX;
_root.test4 = endX;
As far as i am aware this should never return 0 for these two values but it does?!?
can someone please tell what im doing wrong here?
Math.round And Just Plain Math
Hi, I'm back with another question.
I want my exam to show a percentage at the end. I guess I'll concatenate a 'percent sign' at the end, but right now I'm having trouble with the math.
There are 13 questions. This is what I have:
score = Math.round(right/13*100);
The scores are coming out all wrong. Any ideas would be greatly appreciated.
Dan
Math.round() Or Math.random()
Is it better to use Math.round() or Math.random() reason I am asking I think I read somehwere that one was better. My problem is that I have a number of movie clips that are attach dynamically. They move randomly on the stage but for some reason they just stop moving randomly.. I think there was a post somehwere about that but cannot seem to find it.
Math Questions For The Math Experts :)
Hello there,
I am looking for a way to find a vector if i know one point and 1 angle...
Like i have A(x,y) and a vector starting from A(x,y) with an angle. I would like to know the position on a point X(x,y) that can be anywhere on that vector. I only know the coordinates of A and the angle. Possible?? I guess it has to be a function... ANy help would be appreciated
Math.min And Math.max Synopsis...
Hey,
I am looking for a good definition of the two mentioned in the title... Macromedia's documentation is crappy for the two... I know both follow this pattern:
math.min (x,y)... my Q is what is X and what is Y? are both constraints?
I'm lost.
Math.sin And Math.cos Speeds
I've just been reading through some old Flash 5 tutorials and came across a tutorial that used Math.sin and Math.cos quite a lot for trigonometry functions. The tutorial recommends creating an array of sin and cos values and using them instead of calling Math.sin and Math.cos all of the time in order to speed up the calculations (the functions are used a few times a second by multiple movie clips).
Is this still an issue with Flash?
I know that Flash 7 can process code faster than Flash 5, and that the CPU speed also comes into it, but after running a few tests using Math.sin and Math.cos (instead of the array idea) I don't really see any speed problems (that's on a 3Ghz PC though).
Does anyone have any thoughts on this?
Including The Problem/Question In Subject Line : Please Read
Last edited by Nutrox : 2007-03-10 at 11:43.
Please Read:
The actionscript forum has been receiving several posts with subject lines that do not specify the type of problem or question.
-------------------------------------------------------------------------
This presents two distinct problems:
1) It makes the post hard to sort through for people searching old posts for similar information.
2) The people who are most likely to provide the best response have to read your post before they can determine if it's something they can help with.
Please post your problem/question in the subject line
-------------------------------------------------------------------------
Instead of:
Help
Try:
[Shared Object] code fails for some users.
or:
[as] [xml] Can Shared Objects store XML?
-------------------------------------------------------------------------
Instead of:
How do they do this?
Try:
[design] 2A sky and clouds effect
-------------------------------------------------------------------------
Suggested Tags:
[as 2] actionscript 2.0 Flash MX 2004
[as 1] actionscript 1.0 Flash MX or Flash 5
[xml] xml
[txt] text file
[design] design
[js] javascript
[comps] components
[help] stuck on a problem
[looking 4] looking for a site or effect
[nd resource] need resource
[questn] general question
[so] shared object
[loConn] Local connection object
[advice] need advice or guidance
Math.sin (45) ?
Math.sin (45) shouldnīt be 0.7071067...?
I donīt know if there is any mistake, but it gave me 0,8509035...
I did it with a calculator at home and it gave me 0.7071... I guess I didnīt understand somthings
Math.....
i know Math.sqrt is the maths for square rooting something, but what is the annotation to squared something (ie a*a, or x*x)
Math ?
Hello,
I have a mouseover "zoom" MC on a background(city). How can I determine the distance between this MC and the _root._x position of the main movie? I would like to zoom in (scale) and have the x position of the main movie smoothly scroll to the x position of the "zoom" MC. My latest attempt is another MC, seperate from "zoom" and "city" on the main timeline with this action...
onClipEvent (enterFrame) {
if (_root.city._xscale==true) {
a = _root._x-_root.city.zoom._x;
_root._x = _root._x+a;
}
}
My math skills need some improvement. I can get the distance between the two _x positons with the variable "a".( I think, still questioning postive and negative values) How can I smoothly scroll the _x postion of the main movie to the _x postion of the "zoom" MC?
Thx in advance!
~GD~
Math.abs
Is the absolute value created by Math.abs by definition a positive number?
Or can it be negative.. if so, which Math object makes the total only positive...?
Thanks
- Dan
//NEED MATH WIZ
I'm alittle confused about the trig functions in actionscript. Its telling me that it returns the values in radians and to convert these to degrees I must use
degrees = (radians / Math.PI) * 180
Now, does that mean I would do the math first to get the radians stored in a var and then preform the above formula?
Heres what I'm after:
//text fields for user input
H = "";
V = "";
y = "";
//button to calc everything
on (release) {
if (H.length>=1 && V.length>=1 && y.length>=1) {
x = H/V;
z = Math.tan(y)*x;
radian = Math.atan(z); //inverse tan to get actual angle
display = radian/Math.PI*180;
} else {
display == "";
}
}
Basic example:
H=30
V=5
y=11.25
tan(11.25)= .1989124
.1989124*6= 1.1934742
inverse tan(1.1934742= 50.040698
So my actual angle at a Horizontal scale of 30 and a vertical of 5 would be 50.04 degrees if I'm using a 11.25 degree bend.
If the scale were 1:1 it would just be 11.25 degrees due to lack of distortion.
HOWEVER, I cant seem to get this to come out in flash. With the script I have above I get -87.518, so I know I'm way off.
Can anyone enlighten me????
Need Someone Who Knows Their Math
OK, my script requires that I rotate a movie clip to face the mouse. Now, I know trig. fairly well, and the basics of the formula are (N being the value I need):
90 + N = TAN-1 (X Difference / Y Difference)
But I can't find an inverted tangent function in the Math object. Does anyone how to perform a reverse tangent?
Need Math Help
i need to compute some formulas and am not real sure about how i set them up-- are there some math/action script wizards that could show me how to calculate these two formulas in action scripting??
i've made a stab at it, but not sure i'm correct, and have no way to check the results against known values...
TIA
i can't do scripts and subscripts here so "sq" is squared and "pi" is of course pi as in 3.14
1.
-----------------
G = 4piA/Lsq where A=piRsq,R is input (variable) Lsq= Csq/Fsq where C=3x10-to-the-8th and F is input (variable)
-----------------
2.
-----------------
L=20LOG(4piD/L) where D is input (variable) and L=C/F where C=3x10-to-the-8th and F is input (variable)
-----------------
any and all assistance will be greatly appreciated.
Math
Hello everyone. How do you write a simple addition statement?
Say I have three variables
quantity
price
total
how do I say: Total = (quantity * price) in Actionscript?
Thanks is advance to anyone who replies!
Math, Help Me.
Ok I have a circle.
Origin 0,0.
The Radius is dynamic, we'll call it X length.
We need to find a dynamic number of points on this circle. All equidistant from each other. We'll call this number Y.
Is there a formula to find the choordinates of each of the dynamic points?
A Little Math Help Pls
I am trying to simulate something filling with water in Flash 5 and I am having trouble with the bubble speeds.
I am using AS to animate everything... Basically, there is a solid color MC that decreases it's _y position over time, and random bubble MC's that do the same.... BUT I want them to adjust their speed accordingly so they don't pass the _y of the color MC, which is the top of the clip... I basically have this accomplished but there is too much deceleration as they get closer to the top.
Here is what I am using on the bubble clips now:
Code:
onClipEvent(enterFrame){
wtop = _parent.water._y; // water's surface
if (wtop <= 300){ // if water is up, start moving bubble.
// speed is random, assigned when clip is duplicated.
dist = Math.ceil((this._y - wtop)/speed);
if (this._y > wtop){
this._y -= dist;
}else{
doOtherThings...
}
}
}
Please let me know if anyone has any better ideas...
Thanks
Math
Hi
I am having version 5 of Flash.How can I perform mathematical operations on values entered on textbox1 and textbox2 and obtain the result on textbox3?
Math.cos And Math.sin
Why am I an eejit! when it comes to math? I'm trying to create a circular motion that at random intervals (randomizer &randomizer2 in the Suctionscript below) turns and twists. It's kinda hard to describe, but picture something like an infinite s-curve - or a phone doodle.
Now, creating the circular motion is no problem (thanks
again, MKit - and, yeah, I said I thought I'd be able to sort the rest out...). And reversing it around the same axis is not a problem either. (remove the four lines of code including and after mexoffset). But what I thought would be four lines of beautiful and precise code is just a worthless two-timing pile of piss-ant ass-crack word jumble! Suggestions anyone?
onClipEvent(load) {
flag=1
radius=40
xcenter=200
ycenter=200
this._x=240
this._y=200
}
onClipEvent(enterFrame) {
if (flag==1) {
xspeed+=.05
c=Math.cos (xspeed)
this._x=(c*radius)+xcenter
yspeed+=.05
d=Math.sin (yspeed)
this._y=(d*radius)+ycenter
randomizer=random(150)
if (randomizer == 1) {
flag=0
mexoffset=this._x-xcenter
xcenter+=2*mexoffset
meyoffset=this._y-ycenter
ycenter+=2*meyoffset
}
}
if (flag==0) {
xspeed-=.05
c=Math.cos (xspeed)
this._x=(c*radius)+xcenter
yspeed-=.05
d=Math.sin (yspeed)
this._y=(d*radius)+ycenter
randomizer2=random(150)
if (randomizer2 == 2) {
flag=1
mexoffset=this._x-xcenter
xcenter+=2*mexoffset
meyoffset=this._y-center
ycenter+=2*meyoffset
}
}
}
Math.exp() - I Need A Help
Hi... I'm having problems when I try to use the Math function: math.exp()... I don't know what is the right use of this function... I need to make a simple operation: example 2^4 = 16
is there other way to make this without Math.exp, or if there is not how can I use this on Flash MX?
May someone help me?
Thanks
Math.rem?
hi all
how can I find out if a number is odd or even ? rem used to do it for me in C
5 rem 2 = 1
6 rem 2 = 0
how can i do this in actionscript?
Thanx
MikeP
Math.pow(25, 1/2)
Has anyone else noticed this bug in flash mx??
Create two dynamic text boxes call "test1" and "test2".
Then put the following actions on the frame:
// Set test1 to the square root of 25
_root.test1 = Math.pow(25, 1/2);
// Set test2 to be the integer of test1.
_root.test2 = int(_root.test1);
You would expect that both variables would have the same value since 25 is a square number, but no - test1 = 5 and test2 = 4!!!!!
Experimenting with this I have found that it only happens for factors of 5 and to any power less than 1 !!!
Math.cos
i understand math.cos represents angles measure in radians, i need cos to represent degrees, i have this
Code:
//Global function to convert radians to degrees,
-global.radiansToDegrees = function (radians){
return (radians*180) / Math.PI;
}
how can i attach it to my function so that when i use math.cos, it is instantly converted from radians to degrees
Code:
function plotValues(theta, phi){
this.theta = theta;
this.phi = phi;
(theta)-90 = a1 + a2 * Math.cos(phi + a3) + a4 * Math.cos((2 * phi) + (2 * a5)) + a6 * Math.cos((3 * phi) + (3 * a7));
}
3D Math
I found this great 3D tutorial on Macromedia support website
http://www.macromedia.com/desdev/mx/.../flash_3d.html
before i say anything else, great tutorial and thanks to Chad Corbin for posting it.
this is straight forward enough... but I'm wondering if there's any tutorial out there that explains WHY it does WHAT it does... I mean... WHY and HOW a point in 3D space gets translated or rotated when multiply by a matrices... having the formula and not understanding doesn't do any good. Are there any books or tutorials that could help me out? thanks.
I want concepts....
Math Help
Ok, so I'm making a calculator that allows you to put in 2 numbers, then decide whether you want them to be divided, multiplied, subtracted, or added to each other! For some reason, adding the two together doesn't work. Neither does division. With division, as soon as you click show answer it clears everything. with addition it adds the two together LITERALLY. example: i put in 1 + 1. It answers 11. for division, i put in 1 + 1. all slots for putting numbers in are blank!!! WHAT'S THE PROBLEM?!?!?!?! The file is too big to attach to this document, so if you want a copy of it e-mail me at blkensercks1124@aol.com
Alex
Math Help
Hey, here's some script contributed by Jaffasoft:
Code:
move = function (mc, xmove, ymove) {
trace("Called OEF function for "+mc);
mc.onEnterFrame = function() {
this._x += (xmove-this._x)/ease;
this._y += (ymove-this._y)/ease;
if ((Math.abs(xmove-this._x)<=5) && (Math.abs(ymove-this._y)<=5)) {
delete mc.onEnterFrame;
trace("Deleted OEF function for " +mc);
}
};
};
my question is regarding the Math.abs part... can someone explain exactly what Math.abs does? I read the entry in the Actionscript dictionary, but i guess it just aint clicking this monday morning....
thanks,
-myk
how do you auto-format actionscript on this forum? I've seen it done in other posts, but cant find a reference for what tag to put in my post to di it... thanks
Math Help Again
You don't understand what i'm saying! my number (i think) needs to be a string! here's the actions script i'm using
answer = (setnum1)+(setnum2);
setnum1 = answer;
setnum2 = "";
this makes it so when you put in 1 + 1 and press enter, the answer appears in the field with the var. name of answer, and it also appears in the first setnum1 field. then it clears setnum2. I did this because I'm making this calculator for my mom and she does a lot of re-peated math. meaning if she needs to add 100 numbers together she could just go 1 + 1 enter then do + 2 enter + 8 enter and so on.
for my division problem, here's the action script.
answer = (setnum1)/(setnum2);
setnum1 = (answer);
setnum2 = "";
like the addition one above it's pretty much the same as the addition one. only the problem with this one is when you press enter it clears EVERYTHING! WHY?!?!?!
I have attached a zip file with the fla file inside. please download this and tell me what the freakin' problem is!
Math.int() ?
There used to be a Math command in flash 5 called Math.int that displayed ONLY the whole number to the left of the decimal place.
Example:
Math.int(9.1111) == 9
Math.int(9.9999) == 9
This doesnt work in MX, and I cant find a new command that does the same thing.
I have a timer that activates an event based on getTimer(). The event occures every n seconds. I want to display the integer (Math.int) of getTimer()/1000. I cant use Math.round (or ceil, or floor), because its looks stupid. (The event ocures in actual seconds, the display of the rounded getTimer will round up or down, so the counter is half a second out at all times!)
Does anyone know a work around?
Cheers.
Some Math Help Please.
hello
can anyone help me out with some code to smoothly move an object?
say i have a circle that should move from point A to point B, but once it reaches point B it still has enough velocity to head a little over point B than slows to zero, reverses direction and goes back to point B, but still heads out a little bit in the other direction... and so on.... like about 5 times.
i hope it wasnt too complicated explained. =)
thanks!
Math Help
I have eight input text boxes,
width and hight they have the varible name as follows.
ww hh
ww2 hh2
ww3 hh3
ww4 hh4 - this is where the user puts in the width and the hight
and what I need this to do is based on the width and
Hight come up with the price of the unit. so if a user
put's in 22 and 34 I have a button on the stage that
reads get price and what I need that button to do is
to add those to numbers together and place a price in
the dynamic text box lable price. so If I have 8 diffrent
prices
40-50 = 100.00
60-70 = 200.00 exc......
How do I code that. ?????
Math Help
I have eight input text boxes,
width and hight they have the varible name as follows.
ww hh
ww2 hh2
ww3 hh3
ww4 hh4 - this is where the user puts in the width and the hight
and what I need this to do is based on the width and
Hight come up with the price of the unit. so if a user
put's in 22 and 34 I have a button on the stage that
reads get price and what I need that button to do is
to add those to numbers together and place a price in
the dynamic text box lable price. so If I have 8 diffrent
prices
40-50 = 100.00
60-70 = 200.00 exc......
How do I code that. ?????
__________________
demdps
Math Help Take A Look
I have a screen that allows a user to place an order the fields ask
for quanity - width - hight
then there is a button for them to get their price I have it working except for the quanity- if they place an order for 2 or more I can not get the button to multiply the price by that number also there is another field that allows the user to pick there metal choice. if the user picks lead then the price dose not change but if they pick brass the price increase by 15.00 and I can not get that to work either. I placed a copy of the order form in this message PLEASE HELP
Math.cos And Math.sin Help
Ok im making a space ship game and ive learned this before but i forget the formula used to make the spaceship go the way its pointing....
code: onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
this._x+= Math.sin(Math.PI);
this._y+= Math.cos(Math.PI);
}
if(Key.isDown(Key.LEFT)){
_root._rotation-=5;
}
if(Key.isDown(Key.LEFT)){
_root._rotation+=5;
}
}
ok i beleave its somthing like that :S help me out plz
Anyone For A Bit Of Math?
Okay.
This is what I want to happen.
Inside an MC called "place",
there is another MC called
"you", which can move around
inside "place". That works.
But, when "you" moves, the
"place" doesn't move with
it, therefore if "you" moves,
it isn't always in the middle
of the screen. Basically I
want to create a scrolling
game.
INFO
width of "place" = 746 px
height of "place"= 384 px
default x pos of "place"= -78.1
default y pos of "place"= 14.1
default x pos of "you"= -78.1
default y pos of "you"= 14.1
Thanks
Math...ugh
first I apologize for not posting actual code, but there is a ton of it in this movie and none having to do with this problem since I have no solution yet--
I have a mc which I want to set on a course to intercept another mc. I can easily deduce a point to aim for, by adding the target's velocity to it's current position. (Each of these mcs is moving in the direction they are rotated, by the way-- they can only move forward and to move another direction they have to turn.) So I want to set the _rotation of the first mc, the interceptor, to face the point I defined as the intercept point.
So, for example, if the interceptor is at _x:100, _y:100, and _rot:180 and the intercept point is at _x:0, _y:100 I need the interceptor to turn its rotation to +90, or 270. I think.
There must be a formula for this, but nothing I've tried is working. Anyone have any thoughts? Something simple and elegant and bugproof!?
R
Math Help
is there any way to get flash to round a number up to the next even number?? EXAMPLE if someone gives me the measurment of 12.75 or
(12 3/4) is there any way flash can round that up to the next even number in this case 14
|