Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Drawing API (angle Formula)



Alright, I suddenly have a lot of time on my hands, so I decided to start learning how to use the drawing API. I went through the simple tut on it here. That's easy, I understand how it all works (dealt with moveTo and lineTo). Okay, but my question now is this: "What is the simplest mathematical formula for moving a line (or rather calculating a line to...) along an angle." I've attached my source, albeit messy as I didn't think I'd have a problem, and you can see I just made up some junk to get it to go -like- an angle. Anyway, the function which has all the vital stuff in it is on the first frame...shouldn't be hard to find.

Anyway, thanks in advance,
--Elios



KirupaForum > Flash > Flash 8 (and earlier) > Flash MX
Posted on: 05-27-2003, 03:46 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Help On Angle Formula
Im making a flash sorta 3d engine and I need a reliable angle formula (to get the angle with points X, Y, CX, CY)
Right now I'm using ACOS((X-CX)/Dis) where dis is the distance from X, Y to CX, CY. It seems that ACOS isnt all that reliable, and so I keep getting NaN. Does anyone know one thats fast and effective?

Need Formula For Drawing Method
I need help figuring out a formula for a dynamically-generated diagram. Of course the lines will be drawn using the AS drawing API and I know I will need six coordinates total (the start point, the moveTo point, the curveTo point, the anchor point, and the end point) to draw the line.

The position of both start and end points will be dynamic. Please see the diagram at the link for exactly what I need.

http://www.themassivedump.com/uploads/drawing-logic.gif

I don't really know where to begin. If there are any geometry wizzes out there, your help would be GREATLY appreciated.

Thank you in advance!

[MX04] Drawing A Line At A Certain Angle Untill It Hits A Wall
ok, i am making a top down game and when the player shoots a gun i want there to be a line drawn coming from him and it should stop being drawn when the line touches a wall

eg: if the player is right next to the wall the line will be very short if he shoots at the wall, but if he shoots the other direction then the line will be very long before it hits the other wall...

i thought about doing this by sending out an invisible probe mc that moves in the angle untill it hits a wall and then drawing a line from the player to the probebut that would use a lot of processing power if there could be a player and up to 20 enemies shooting machine guns which fire extremely fast... major hit on performance...

i just need the code that draws a single straight line that stops when it hits a wall with an instance name of wall, but i can't just put the walls on the top layer and hope they cover any excess line up, bcause there could be a wall in the middle of the map...

any help?

Rotation Formula Help? ( I Guess Formula Is What I Need?)
I have a picture of a globe 180 pixels diameter I'm tryin to roll it on to the screen and stop it in a certain location in it's proper orientation. (top on top bottom at the bottom) it rolls into another clip where it fits into a complete picture so the stopping needs to be perfect. I am unsure how to come up with the exact rate of rotation in relation to the distance traveled and the final position it is in? Can someone point me in the right direction with this?
I can understand more math than I can come up with out of my own head so don't be afraid to go there?

I Need The Formula
Hey there!
Greets from Helsinki!

Thanks to afew of you I am finally gettting better with the root thing.ex:

on (release) {
_root.gotoAndPlay("text2");
// label here must be between " "!
}

However I stil need abit of help as im still abit lost with this thing.Im doing a project where i have several little pic thumbs in one of these mouse vr scrollers.Now all of these pic thumbs are inside one movie clip.

Now, the idea is when you click on anyone of the thumbs you will get a bigger version of that pic.I have 27 large pics and i was thinking i would put each one inside its own movieclip as i have to fade them in when they appear.

Anyways I know i need to use tell targetting for this but i also am not sure what formula i need to be able to tell 1 movie clip with an instance to contact another movieclip with an instance.The above pasted root code only works for movie clip to main timeline.I need movie clip from movieclip.

Can anyone be kind enough to send me the right code.Im not very good with actionscript so please keep it straight forward if you can

Cheers!

Chris

What Formula I Need To Use?
Hi...Everybody!
Can any body please help me in doing this?
I have a moving ball in side tha polygon shaped boundary.
To detect the boundary, I couldn't use hitTest, because it is not working.

Few of my friends told me, there is a way in coordinate jeometry to detect the boundaries. Since I am very poor in mathematics, not able to do this.

What should be the approach to do this?

Can anybody explain what formula I need to use to detect the boundaries in this particular case.

For reference, I have attached the file...Please help me..!

Thank you very much.
Lokesh V

Have Any Formula?
PHP Code:



bool = false;
m = 0;
onEnterFrame = function()
  if (bool) {
    m--;
    if (m<-5) {
      bool = false;
    }
  } else {
    m++;
    if (m>5) {
      bool = true;
    }
  }
  trace(m);





have any formula can replace this?

Anyone Know What This Formula Does?
hi guys, im currently trying to figure out a formula which i got from http://levitated.net/daily/levRotationalTG.html

In the script they have this formula

var rbit:Number = Math.sin(Math.PI/180 * theta);
var rbit90:Number = Math.sin(Math.PI/180 * (theta - 90));

Can anyone explain to me how does that work? or what does this formula do??

thank you so much

Formula 1
http://resanium.com/news/categ-Formula1-2113.html Formula1
Formula1

Formula For SetTransform?
Hey guys, I want setTransform to control the color of a MovieClip as I move the mouse; It works okay but I can't control the colors -

yoyoyo = new Object();
yoyoyo.ra = 0;
yoyoyo.rb = _root.r;

etc....then

_root.r = Math.abs(this._x);
_root.g = Math.abs(this._x);
_root.b = Math.abs(this._x);

Anyway, supppose for example I want the mc to fade through the rainbow from red to purple...I assume there's some sort of calculated formula/something out there, can anyone help me? Thanks. Love, J_red

Question About The Formula
Hi

I have an axis X,Y
and i have a quarter circle on the origin of the axis (the circle is located in the positive area of X and Y)

the thing is that i have this formula that i found in a tutorial
90* dist (x)/(dist (x) + dist (y))
this formula gives me the angle of the triangle with the following 2 sides:
The angle between the horizontal axis X and the line passing from the origin of the axis to a point on the perimeter of the circle
why does this forumla work? What is the concept behind this equation???

Insert Formula
How to insert this formula in actionscript, i cant find the commands:
m=d*((1-k)/(1-k^n))

I cant find the last part k^n. It's k exponented to n.

sorry for my english.

Rotation Formula
I want a movie clip to point to the mouse. What's the code to do this?

Rotation Formula
I want a movie clip to point to the mouse. What's the code for this?

Problem With The Formula, Please Help
I'm facing a problem with actionscript that will calculate the people's DOB. Can someone help me to figure this out please?

The example is:
D.O.B is 13.1.1975
i need this to be add up one by one that is
1+3+1+1+9+7+5=27
this going on by adding the 2 and 7,
2+7=9

so the final result will be 9.

Can anyone help me with this, i'm poor in math calculation and scripting.

Thanks.

Zoom Formula
Okay guys...

I have a movieclip inside a movieclip. Picture a small box within a big box. When I click the small box movieclip I want the big box moviclip to scale say...300 and move to where the small box inside is centered on the stage.

What is the formula to calculate know how to center the mc when it is scaled to 300? I assume it would be the same way if it was a scale of 100?

I hope I am making sense.

duck

The LUHN Formula...
Hello everyone. For a school project, I need to make a program in action script that can check for LUHN numbers, using conditional loops.

If you're not familiar with LUHN, this is an explanation from wikipedia:

1. Counting from rightmost digit (which is the check digit) and moving left, double the value of every second digit. For any digits that thus become 10 or more, take the two numbers and add them together. For example, 1111 becomes 2121, while 8763 becomes 7733 (from 2×6=12 → 1+2=3 and 2×8=16 → 1+6=7).
2. Add all these digits together. For example, if 1111 becomes 2121, then 2+1+2+1 is 6; and 8763 becomes 7733, so 7+7+3+3 is 20.
3. If the total ends in 0 (put another way, if the total modulus 10 is congruent to 0), then the number is valid according to the Luhn formula; else it is not valid. So, 1111 is not valid (as shown above, it comes out to 6), while 8763 is valid (as shown above, it comes out to 20).




So far, I've got this code:


Code:
a = "12345"; // this is a test number

b = 0;
for (i=0; i < a.length; i++){
b += parseInt(a.charAt(i));
trace(a.charAt(i));
}
trace ("b =" + b);
All that does is separate the test number digits and add them all together though... any help would be appreciated.

Tween Formula
Hi all. I have a tween formula I received from a friend. Well, I copied the formula exactly, then I modified the tween command, but kept the same number of parameters.

Here's my command:
Code:
_root.reviews_bn.xSlideTo(118 + 30, 1, "easeOutBack", 3.1);
This does absoluetly nothing.

here's the tween formula (I have truncated it to show only the first couple of lines.)
Code:
MovieClip.prototype.tween = TextField.prototype.tween = Sound.prototype.tween = function (prop, propDest, timeSeconds, animType, delay, callback, extra1, extra2) {
// Sets default values if undefined/invalid
if (timeSeconds < 0.001) timeSeconds = 2; // default time length
if (animType == undefined || animType == "") animType = "easeOutExpo"; // default equation!
if (delay == undefined) delay = 0; // default delay

etc . . .
How would I write a command to make my button do the easeOutBounce?

thanks

Grid Formula
I have a large grid with 1200 squares numbered from 0 to 1199. The grid is 40 squares wide by 30 squares down.

What I need is a formula to work out the x and y position of a certain number.

Here is a small example

0 1 2
3 4 5
6 7 8

Number 3 is at position x=1 y=2
Number 8 is at postion x=3 y=3
etc...

Formula Troubles
I'm trying to implement the formula here:
http://mathworld.wolfram.com/Lambert...rojection.html

I've got the one direction working. I can go from Lat and Long to X and Y, and it lines up nicely with my map. I can't get the opposite direction working, though. Anyone see what I'm doing wrong?


ActionScript Code:
private static const refLong:Number=-97/180*Math.PI;
    private static const refLat:Number=52/180*Math.PI;
    private static const par1:Number=49/180*Math.PI;
    private static const par2:Number=56/180*Math.PI;
    private static const n:Number=Math.log(Math.cos(par1)/Math.cos(par2))/Math.log(Math.tan(Math.PI/4+par2/2)/Math.tan(Math.PI/4+par1/2));
    private static const F:Number=Math.cos(par1)*Math.pow(Math.tan(Math.PI/4+par1/2),n)/n;
    private static const p0:Number=F*Math.pow(1/Math.tan(Math.PI/4+refLat/2),n);
    private static const mapScale:Number=2332.23618;
    private static const mapXOffset:Number = 154.5, mapYOffset:Number = 360.5;

    public static function xyToLatLong(xx:Number,yy:Number):Object {
        var lat:Number;
        var long:Number;
        xx=(xx-mapXOffset)/mapScale;
        yy=(yy-mapYOffset)/-mapScale;
        var p:Number=(n>0?1:(n<0?-1:0))*Math.sqrt(xx*xx+Math.pow(p0-yy,2));
        lat=2*Math.pow(Math.tan(Math.pow(F/p,1/n)),-1)-Math.PI/2;
        long=refLong+(Math.pow(Math.tan(xx/(p0-yy)),-1))/n;   
        return {long:(long*180/Math.PI), lat:(lat*180/Math.PI)};
    }
I ran a test of values like so, and the output shows that it's completely wrong.


ActionScript Code:
for (var long:Number=-102;long<-90;long+=1) {
        var point:Point = Translates.latlongToXY(51,long);
        var object:Object=Translates.xyToLatLong(point.x,point.y);
        trace(long + " == " + point.x + " == " + object.long );
    }


Code:
-102 == 26.712220529679684 == -1135.5010071401673
-101 == 52.240326996537036 == -1396.6290212246217
-100 == 77.7880637761956 == -1831.3959953950255
-99 == 103.35052658870202 == -2700.2616311357683
-98 == 128.92280832721508 == -5305.523710362504
-97 == 154.5 == Infinity
-96 == 180.0771916727846 == 5111.523710362569
-95 == 205.64947341129763 == 2506.2616311357865
-94 == 231.21193622380406 == 1637.3959953950327
-93 == 256.75967300346264 == 1202.6290212246256
-92 == 282.28777947032 == 941.5010071401697
-91 == 307.79135511276246 == 767.1919306173606
I've tried double-checking that my code matches the formula, but I can't find the problem. Anyone?

I also can't find another source for the formulas to make sure the web site has it right.

Scaling Formula
Hey all,

So I'm working on a tool that will allow you to select MCs on the stage, and then to scale them real time by dragging the mouse. I wrote a function to handle the scale change and update on MOUSE_MOVE, but it's a bit jittery. It works pretty smoothly/well on a positive scale change, but not so much with a negative scale change. It seems to shrink a bit too exponentially for me, and before I know it, it's inverted, and scaling the other way (except for the limiter I put on it, but that just seems to make it twitchier).

I was just wondering if any of you out there (better at math than I am!!! ) have tried to handle scale changes in this way, and might have a better idea of a scale formula I could use, or an idea to tweak mine so that the negative scale changes are smoother.

Here's the code I'm using right now:


ActionScript Code:
private function scaleMyTarget(e:MouseEvent):void {
    var deltaX:Number = stage.mouseX-startX;
    var deltaY:Number = stage.mouseY-startY;
   
    var dScale:Number;
   
    if (Math.abs(deltaX) > Math.abs(deltaY)) {
        dScale = ((_scaleTarget.width+deltaX)/_scaleTarget.width)*initScale;
    } else {
        dScale = ((_scaleTarget.height+deltaY)/_scaleTarget.height)*initScale;
    }
    if (dScale < .3) {
        dScale = .3;
    }
    _scaleTarget.scaleX = dScale;
    _scaleTarget.scaleY = dScale;
   
   
}

The "initScale" is a variable set to the current scale when you click on the target. I also set the "startX" and "startY" on MOUSE_DOWN to capture the initial x/y pos of the mouse. The rest should be relatively self explanatory. I was also thinking of trying to triangulate the mouse coords to get a single "net" change I could use for "delta", instead of using the idea that whichever change was greater, use that. I think that might help with some of the twitch, but not positive. Anyways, if anyone has any ideas for this, let me know. Also, if anyone knows of a good way to set up an inverse scale function (for something attached to the MC, but I don't want to scale, just change x/y pos based on the bounding box I create around things), that would be awesome. I tried doing something like:


ActionScript Code:
dToolScale = (_scaleTarget.width/(_scaleTarget.width+deltaX))*toolScale;

but that REALLY didn't work too well....

Anyways, I'll update this if I find something decent, but in the mean time, if anyone has any suggestions, any help would be much appreciated!!!

How To Calculate A Formula?
i wanna let a number like 16/44 to 4/11

how to calculate the formula??

var a = 3;
var b = 6;

var temp = b%a;

x = a/temp;
y = b/temp;

result is : x/y = 1/2

but this formula can't use on a > 10
can any expert can teach me?

Distance Formula
Hey, I was doing the nodes tutorial on bit-101.com, a great tutorial by the way, and I was just wondering where this distance formula comes from. I understand x2 - x1 and y2 - y1, but where does that square root of dx^2 + dy^2 come from? Thanks!

ActionScript Code:
dx = thingA._x - thingB._x;dy = thingA._y - thingB._y;dist = Math.sqrt(dx*dx+dy*dy);

Help With Rotation Formula
at the moment it is not working at top left correct(about 10˚ of rotation at about 180˚ off) and bottom left is inverted (180˚ to much). I had all but top left working but when fixing that I broke the bottom left.
It should make a top view of a man rotate to face the mouse. 0 rotation of the man he is facing down, this was unintentional the code was intended to make him face up but I didn’t mind
This code is for a RPG that I am making for a beginner’s flash class


http://www.ping.be/~ping1339/gonio.htm (I added this link coz this is the referents I used to refresh my understanding of Trigonometry. Might be useful for some keen people)


Quote:




onClipEvent (load){
Cx = Stage.width/2
Cy = (Stage.height/2)- 30 //the 30 is to les on the inpact of the interface



}
on (release){

//rotashon of man
if (_xmouse >Cx && _ymouse>=Cy){ //betwen 0 and 89 top right θ./_|
Radian= ((Math.PI/2) - Math.atan( (_ymouse-Cy)/(_xmouse-Cx) ))
}
if (_xmouse >=Cx && _ymouse<Cy){//betwen 90 and 179 botom right θ`|_
Radian=(Math.PI/2) +((Math.PI/2) - (Math.atan((_xmouse-Cx)/(Cy-_ymouse))))
}
if (_xmouse <Cx && _ymouse<=Cy){//betwen 180 and 269 botom left /_|`θ

Radian=(Math.PI/2) + (Math.atan((_xmouse+Cx)/(Cy-_ymouse)))
}

if (_xmouse <= Cx && _ymouse > Cy){//betwen 270 and 359 top left |_.θ
//Radian=((2*Math.PI) + ((Math.atan((_ymouse-Cy)/(Cx-_xmouse)))))
Radian=((2*Math.PI)+(Math.PI/2) + ((Math.atan((_ymouse-Cy)/(Cx-_xmouse)))))

}
_global.man_angal= Radian*(360/(2*Math.PI)) //convert Radians to Degree


trace("Radian "+Radian)
trace("man_angal in deges "+_global.man_angal)




//send moveing instrucshons
if (((Cx + 10)> _xmouse)||(Cx - 10)< _xmouse) {//test for minamin movement
_global.moveX = (_xmouse-Cx)//send moveing instrucshons
}
if (((Cy + 10)> _ymouse) || (Cy - 10)< _ymouse) {//test for minamin movement
_global.moveY = (_ymouse-Cy)
}

}

Distance Formula
Hey, I was doing the nodes tutorial on bit-101.com, a great tutorial by the way, and I was just wondering where this distance formula comes from. I understand x2 - x1 and y2 - y1, but where does that square root of dx^2 + dy^2 come from? Thanks!

ActionScript Code:
dx = thingA._x - thingB._x;dy = thingA._y - thingB._y;dist = Math.sqrt(dx*dx+dy*dy);

A Better Easing Formula?
Ive been using this formula: test._x += ((200 - test._x) / 16); for some time but never with an alpha. I was never totally happy that the object never quite reached its destination but it was something that could slide.

Problem is im trying to fade an object in using this formula and the object never quite reaches 100: test._alpha += ((100 - test._alpha) / 16);

The lower the "speed" value the closer it gets but obviously a lot faster. Im sure theres a better formula out there that uses a "time" factor aswell and surely hits the desination to the exact decimal point?

NOTE: I have tried using Math.ceil() but didnt like the effect + it didnt quite reach the destination either.

The (X,Y) Point Rotation Formula
hi,
I was wondering if anyone had or knows the rotation formula to rotate a point via the x,y, and/or z axes.

thank you in advance--
jimi mudgett

Something Wrong With My Rotation Formula
Hi, I'm starting to experiment with the drawing API and I can't figure this thing out... I'm trying to rotate 2D points about the origin... but when it rotates... it also sizes it down... something must be wrong with my math... can you tell?

function rotatePoly(){
&nbsp;var theta = ((Math.PI*degree.text)/180.0);
&nbsp;for(var i=0;i<thisPolygon.length;i++){
&nbsp;&nbsp;thisPolygon[i].x = Math.cos(theta)*thisPolygon[i].x-Math.sin(theta)*thisPolygon[i].y;
&nbsp;&nbsp;thisPolygon[i].y = Math.sin(theta)*thisPolygon[i].x+Math.cos(theta)*thisPolygon[i].y;
&nbsp;}
&nbsp;drawPoly();
}

Math Formula Plugin
is there a math plugin for flash 5 or flash mx .. with which i can write math equations in flash ... is there a thrid part tool or something ... if u have any information please let me know

Math Formula Plugin
is there a math plugin for flash 5 or flash mx .. with which i can write math equations in flash ... is there a thrid part tool or something ... if u have any information please let me know

Motion Formula Not Very Exact
Hi all,

I've used this formula below for a while since i watched some lynda.com course videos and found it very usefull. Untill now, because it has a minor problem and i wonder if there is another way.

This is what i'm doing:


Code:
//Create interval var
var nInterval:Number;

Ease = 6;

// Calculation to get a nice animated motion to new values.
function Calculation():Void {
mcMask._width += (newW - mcMask._width) / Ease;
}

function startMaskMotion():Void {
newW = 365;
trace("mcMask._width = " + mcMask._width); // Traces: mcMask._width = 365.2
trace("newW = " + newW); // Traces: newW = 365
Calculation();
updateAfterEvent();
}

function endMaskMotion():Void {
newW = 725;
trace("mcMask._width = " + mcMask._width); // Traces mcMask._width = 724.7
trace("newW = " + newW); // Traces newW = 725
Calculation();
updateAfterEvent();
}

btTest.onRollOver = function(){
clearInterval(nInterval);
nInterval = setInterval(startMaskMotion, 30);
}

btTest.onRollOut = function(){
clearInterval(nInterval);
nInterval = setInterval(endMaskMotion, 30);
}
I've given a "new width (newW)" and using an interval it checks the calculation over and over again untill the mcMask._width is equal to the "new width (newW)"

But when i trace it, it's not equal at all. It's near equal and it probably has something to do with the /Ease part since at some point it can's divide anymore.

And this is just an example that pretty much fits, but i've got other experiences with a difference of over 7 px. I couldn't find this example anymore.

How can i get this exact?

Because i want to check if the condition has been met, for instance:

if (newW == mcMask._width) {
"do another animation"
}

Can i use another condition or is there a way to make it 100% exact?

Thanks in advance!

[F8] Easing Formula Irritation.
Ive been using an easing formula for quite some time. Its always done the job fairly well up till now. Ive started using the easing formula for alpha. Unfortunately the object doesnt not always fade in fully and therefore appears partially transparent!

Below is the code and the output:


Code:
var speed:Number = 16;
var dest:Number = 100;
test._alpha += ((dest - test._alpha) / speed);

/*******OUTPUT*******/
6.25
12.109375
17.578125
22.65625
27.34375
31.640625
35.546875
39.453125
42.96875
46.484375
49.609375
52.734375
55.46875
58.203125
60.546875
62.890625
64.84375
66.796875
68.75
70.703125
72.265625
73.828125
75.390625
76.5625
77.734375
78.90625
80.078125
81.25
82.421875
83.203125
83.984375
84.765625
85.546875
86.328125
87.109375
87.890625
88.28125
88.671875
89.0625
89.453125
89.84375
90.234375
90.625
91.015625
91.40625
91.796875
92.1875
92.578125
92.96875
93.359375
93.75
94.140625


The higher the "speed" value the further it stops from its "destination". The object stops fading at 94.140625 and the easing script just keeps it at 94.140625.

Now this easing script in my opinion isnt 100% correct as IMO there should be another factor "time" and the speed should always be set to "2". I aint no Math genius but something clearly isnt right about this formula. I did come across another R.Penner's easing formula but couldnt get it to work.

Are these the only 2 formula's about? Is there something better out there as the fact that the object doesnt reach its "destination" is irritating. Below is the output of same formula with speed set to "2". It still doesnt reach 100 either but gets closer at least... obviously way quicker than I want it to!


Code:
50
75
87.5
93.75
96.875
98.4375
99.21875
99.609375


Note I have tried using Math.ceil() around the formula and it works.... but the easing is not a nice effect at all. Below is the output result:


Code:
50
75
87.890625
93.75
96.875
98.828125
100


The second I change the "speed" value to anything other than "2" 100 will never be reached and my object will be slightly transparent!

LUHN Formula, Help Needed.
Hello everyone. For a school project, I need to make a program in action script that can check for LUHN numbers, using conditional loops.

If you're not familiar with LUHN, this is an explanation from wikipedia:

1. Counting from rightmost digit (which is the check digit) and moving left, double the value of every second digit. For any digits that thus become 10 or more, take the two numbers and add them together. For example, 1111 becomes 2121, while 8763 becomes 7733 (from 2×6=12 → 1+2=3 and 2×8=16 → 1+6=7).
2. Add all these digits together. For example, if 1111 becomes 2121, then 2+1+2+1 is 6; and 8763 becomes 7733, so 7+7+3+3 is 20.
3. If the total ends in 0 (put another way, if the total modulus 10 is congruent to 0), then the number is valid according to the Luhn formula; else it is not valid. So, 1111 is not valid (as shown above, it comes out to 6), while 8763 is valid (as shown above, it comes out to 20).




So far, I've got this code:


PHP Code:



a = "12345"; // this is a test number

b = 0;
for (i=0; i < a.length; i++){
            b += parseInt(a.charAt(i));
            trace(a.charAt(i));
}
trace ("b =" + b);




All that does is separate the test number digits and add them all together though... any help completing this would be appreciated.

Smooth Scrollbar Formula
Hey guys,

I'm working on implementing a smooth scrollbar similar to the one from the tutorial on http://www.stilva.com/#smooth-scrollbar. My problem is that the formula stilva uses is quite cumbersome and difficult to use.

The code is (in AS2 format from the tutorial):

PHP Code:




speed = .7;
mc2.setMask(mask);
//sets the mask
createEmptyMovieClip("mc1", this.getNextHighestDepth());
//creates an empty movie clip
setInterval(smoothscroll, 40);

function smoothscroll()
{
   mc1._y = speed * (mc1._y - (button._y+mc1._y
                        * (button._height/mask._height) ) )
                        +(button._y+mc1._y*(button._height/mask._height));
   mc2._y = (1-mc2._height/mask._height)*mc1._y+mc2._height/2;
}







Could somebody break down this formula into what each part actually does. The tutorial doesn't say anything about it and im lost trying to adapt it. Basically i would like to find out what part affects the maxScroll and the minScroll.

Any help would be appreciated, thx.

Help Action 3 And Simple Formula's
Hello

I have just upgraded from Flash 8 to CS3 and i am surprised how difficult it is to do a simple formula in Action Script 3.

I have a form which i have developed using Action Script 2.

I have a cells called:

Male
Age
Weight.
RMR

So i have a statement if Male then weight *17.5+615 I then have the result show up in RMR.

Below is the action script i am using at the moment.

_root.onEnterFrame = function() {

if (sex=="Male" && age>=10 && age<=18) {
var c:Number = Number((kgs*17.5)+651);
cal = Math.floor(c);
rmr = cal;
}

Could someone advise what i need to do to make this work in AS3?

Rearanging A Maths Formula
It's been a whle since I did my engineering maths...

How can I arrrange

fv = pv * (1 + i) ^n (to the power of n)

and get

i = ......

thanks

Surface Area - Formula?
Looking for some help - does anyone know the formula to find the surface area of a flat 4-sided shape where the sides aren't parallel?

Thanks a lot!!!

Excell Formula To Flash
I'm working on a small component to calculate the required dosage for a certain chemical preparation.

The calculation is based on the following Excell-formula:

dosage = (+((LOG(100000/E6)/C6)-M13)/L13)/K13

I created the following AS code to perform the calculation, but I get a completely different result:


Code:
var dosage:Number = 100000/e6;
dosage= Math.log(dosage);
dosage= dosage/c6;
dosage= dosage-m13;
dosage= dosage/l13;
dosage= dosage/k13;
Does anyone see what I'm doing wrong?

I suppose I'm misinterpreting the Excell-formula - I don't know nothing about Excell...

Thanks for looking into this...

Scroller/Dragger - Need Formula
I seem to run into this problem a lot. I've done some searching and can't find the answer. All i need to do is translate the Y position of dragger button to the Y position of an MC. Here's my code, it's close, but not quite there. Anybody have more accurate math? Thank you!









Attach Code

MC // mc to scroll
Drag_MC // Dragger

var mcYMin //minimum position of content MC
var mcYMax //maximum position of content MC

var dragYMin //minimum position of dragger MC
var dragYMax //maximum position of dragger MC

//Dragger on Press, then MC onEnterFrame

var mcRange = mcYMax-mcYMin
var dragRange = dragYMax-dragYMin
MC._y = (-Drag_MC._y/dragRange) * (mcRange) + mcYMax //not totally correct

























Edited: 05/17/2007 at 09:11:49 AM by burritobot

Drag/Zoom Formula
I have a draggable MC that can also be scaled up and down. I need to dynamically figure out the R, T, L, B boundaries for the mc while it scales.

The MC is viewable within a 600x400 window, and need to be draggable to the right-most, top-most, left-most and bottom-most boundaries of that viewable area. Does that make sense? Here's the code I have so far...







Attach Code

//viewable window
var xArea = 600
var yArea = 400

//boundaries need to scale as MC gets to be larger than viewable window
//obviously this code doesnt work because since myMC is draggable,
//the x and y position of myMC is dynamic
function setBounds() {
boundR = myMC._x
boundT = myMC._y
boundL = Math.abs(myMC._width-xArea)
boundB = Math.abs(myMC._height-yArea)
}

function dragMC() {
myMC.startDrag(false,boundL,boundT,boundR,boundB);
}
function scaleUp(){
myMC._xscale+=10
myMC._yscale+=10
setBounds()
}
function scaleDown(){
myMC._xscale-=10
myMC._yscale-=10
setBounds()
}

Need A Help With Perspective Scaling Formula
I am trying to make an object seem to approach from a distance (center) to the sides
I currently have the object and it works well .. but in reverse ...I cannot seem to make it slow at the beginning then as it approaches you speed up....
I was hoping someone may know a link ..or the math better than I....

I have added my test code if that helps at all ...It is just moving a ball for now
the code to move the ball is in the "function moveball"...

all thoughts and ideas appreciated
David







Attach Code

var ball_mc:MovieClip= new ball;


ball_mc.fl=500;
var z:Number = 1;
var ball_timer:Timer = new Timer(3000, 999999);
var ballPy:Number;
var ballNumx:Number;
var ballNumy:Number;
var ballPx:Number;
var ballPolatityX:Number;
var ballPolatityY:Number;
var ballMovY:Number;
var ballMovX:Number;
var zincrease:Number =0;

ball_timer.addEventListener(TimerEvent.TIMER, generateball);
{

ball_timer.start();
};
ball_mc.addEventListener(Event.ENTER_FRAME,moveball);


function generateball(eventObj:TimerEvent):void {

//NOTE: there must be an MovieClip in the FLA Library with the linkage "ball"
//var ball_mc:MovieClip = new ball();
//start at top

ballNumx=randRange(0,10);
trace(ballNumx);
ballNumy=randRange(0,10);
trace(ballNumy);
ballPolatityX=randRange(1,2);
trace(ballPolatityX);
if (ballPolatityX==1) {
ballPx =-1;
} else {
ballPx =1;

}
var ballPolatityY:Number=randRange(1,2);
trace(ballPolatityY);
if (ballPolatityY==1) {
ballPy =-1;
} else {
ballPy =1;

}
// set a focal length

ball_mc.y = 200;
//randomize starty X
ball_mc.x = 275;
ballMovY =ballNumy*ballPy;
ballMovX=ballNumx*ballPx;

//add clip to this instance of balls
this.addChild(ball_mc);
//move
ball_mc.addEventListener(Event.ENTER_FRAME,moveball);

z=.01;
ball_mc.scaleX=0;
ball_mc.scaleY=0;


}
function moveball(e:Event):void {
ball_mc.visible=true;


//var scale:Number = ball_mc.fl-(flchange*1.1);
//z=z+(z*zincrease)*(flchange/ball_mc.fl);


zincrease =z++ ;
var flchange:Number = ball_mc.fl-z;


trace("zfactor ="+zincrease);
ball_mc.y = ball_mc.y+ballMovY;
//randomize starty X
ball_mc.x = ball_mc.x+ballMovX;
ball_mc.scaleX=(zincrease/8)*(flchange/ball_mc.fl);
ball_mc.scaleY=(zincrease/8)*(flchange/ball_mc.fl);

if (ball_mc.x+ball_mc.width<=0||ball_mc.x-ball_mc.width>=550) {
ball_mc.visible=false;
}
if (ball_mc.y+ball_mc.height<=0||ball_mc.y-ball_mc.height>=400) {
ball_mc.visible=false;
}
}

function randRange(min:Number, max:Number):Number {



var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;
}

Distance Formula Wrong?
everyone knows the distance formula in 3 dimensional
d = sqrt[(x1-x2)2 + (y1-y2)2 + (z1-z2)2]

but when i apply to flash


ActionScript Code:
rd = m.sqrt(m.pow((a.x-_root.o.x), 2)+m.pow((a.y-_root.o.y), 2)+m.pow((a.z-_root.o.z), 2))


and i make some changes

ActionScript Code:
m=Mathc = point1o = origin pointrx / ry = how much value to add//x rotation//new x anglevar ax2 = (m.atan2((c.z-o.z), (c.x-o.x)))+rx;//modifyc.x = o.x+(m.sin(ax2)*rd);c.z = o.z+(m.cos(ax2)*rd);//y rotation//new y anglevar ay2 = (m.atan2((c.y-o.y), (c.z-o.z)))+ry;//modifyc.z = o.z+(m.sin(ay2)*rd);c.y = o.y+(m.cos(ay2)*rd);


somehow the distance keeps increasing. even though i removed the rx and ry
is my distance formula wrong or is it my rotation wrong?
please reply asap.

Dynamic Layout Formula
hi. i'm trying to dynamically layout a calendar using actionscript and i'm no good at determining algorithms to quickly and efficiently lay things out. i was hoping for a little help with this one, please.

what i want to do is set it up per the image attached:

* where there are 7 columns and a varying number of rows.

* the top row has the 2 arrows and the month and year display.

* the second row has all the day headings, i.e. S, M, T, W, R, F, S

* and the rest of the rows will have the dates.

how do i come up with a nice clean formula to calculate the positions so all these elements align??

thanks. fumeng.

Voetsjoeba, Help With Golden Formula... ?
Bonjour...

I am in need of easing... and since your formula is so golden, Voetsjoeba, I'd like to ask... how do i apply it? if there a way you can create a sample .fla for me?

My goal is to movie a mask to a certain point with easing and when it has reached that destination, execute some other movieclips...

Any help would be greatly appreciated! And soon... I shall be calling you the golden child!

Devin

Interested In Slowing Down Formula
Hello,

I'm interested in adding a variable to this mathematic formula to slow the bounce down. Otherwise, my alternative is to reduce the frame rate.


Code:
onClipEvent(load){
bounce = 2.9; // the higher, the more bouncy

}
onClipEvent(enterFrame){
_yscale -= ((_yscale - target_yscale) * bounce) / 2;
_xscale -= ((_xscale - target_xscale) * bounce) / 2;
}

onClipEvent(load){
_parent.scaler.target_xscale = 300;
_parent.scaler.target_yscale = 300;
}
I've attached a file to illustrate the situation.
Thank you for any help.

Variable Loading And If Formula
Hey People,

How would I go about making:

If (flash.swf?name=something) equals "something"
Then change the brightness of a button object to 0, I.E. it's -62 when it's not being hovered over.
Oh, and I would like to know how to do the equivalent of a PHP "isset" function for the variable as well, so I could change the url of a link.

Thanks
Ben

Scroll Speed Formula
Hello again!

Im trying to create a formula for an scroll bar. The problem is, bigger the content to be scrolled, lesser the _y variation of the scroll.

Just see the example:
http://www.fonix.com.br/scroll.swf

The "LEFT SCROLL", has a big content, so the arrows (up, down) increase/decrease the bt_scroll, increasing or decreasing the content _y.

On the "RIGHT SCROLL", a small content just do the same thing, but should be bigger the jump of the bt_scroll to reach the end of content faster.

I cant figure out how to make this formula for any content height.

Distance Formula Wrong?
everyone knows the distance formula in 3 dimensional
d = sqrt[(x1-x2)2 + (y1-y2)2 + (z1-z2)2]

but when i apply to flash


ActionScript Code:
rd = m.sqrt(m.pow((a.x-_root.o.x), 2)+m.pow((a.y-_root.o.y), 2)+m.pow((a.z-_root.o.z), 2))


and i make some changes

ActionScript Code:
m=Mathc = point1o = origin pointrx / ry = how much value to add//x rotation//new x anglevar ax2 = (m.atan2((c.z-o.z), (c.x-o.x)))+rx;//modifyc.x = o.x+(m.sin(ax2)*rd);c.z = o.z+(m.cos(ax2)*rd);//y rotation//new y anglevar ay2 = (m.atan2((c.y-o.y), (c.z-o.z)))+ry;//modifyc.z = o.z+(m.sin(ay2)*rd);c.y = o.y+(m.cos(ay2)*rd);


somehow the distance keeps increasing. even though i removed the rx and ry
is my distance formula wrong or is it my rotation wrong?
please reply asap.

Dynamic Layout Formula
hi. i'm trying to dynamically layout a calendar using actionscript and i'm no good at determining algorithms to quickly and efficiently lay things out. i was hoping for a little help with this one, please.

what i want to do is set it up per the image attached:

* where there are 7 columns and a varying number of rows.

* the top row has the 2 arrows and the month and year display.

* the second row has all the day headings, i.e. S, M, T, W, R, F, S

* and the rest of the rows will have the dates.

how do i come up with a nice clean formula to calculate the positions so all these elements align??

thanks. fumeng.

Copyright © 2005-08 www.BigResource.com, All rights reserved