Math : Calculate The Length Of A Curve In Pixels ?
I need to calculate the length of a curved line in pixels.
I'm drawing a curved line using the MovieClip.curveTo() and then have the same line followed by another Mc, just as if the line were it's path. The size of the Mc that's following however is determined by the percentage of the line it's following (or actually, how much percent is already covered)
Anyone out there who knows how to do that ? I don't remember having learned that in high school ...
--Edit--
I found the following formula on the internet on how to calculate a segment of a parabola, but I don't understand everything (I don't know the syntax of math )
Quote:
Segment of a Parabola
Height: h
Chord length: c
Area: K
Length: s
s = c[1+2(2h/c)2/3-2(2h/c)4/5+...]
s = sqrt[4h2+c2/4]+[c2/(8h)]
ln[(2h+sqrt[4h2+c2/4])/(c/2)]
Some of the variables are described, like h and c, but what about ln ? I'm assuming it's a constant in the world of math ?
ActionScript.org Forums > Flash General Questions > Other Flash General Questions
Posted on: 07-27-2005, 05:58 PM
View Complete Forum Thread with Replies
Sponsored Links:
Calculate How Much Pixels The Stage Resized.
How can I calculate how much pixels the Stage resized?
What I want to do is this:
ActionScript Code:
var stageListener = {};
Stage.addListener(stageListener);
stageListener.onResize = function():Void {
var dif:Number = //how much pixels the stage resized
//
this.myMC._width = Stage.width - 70 - dif;
};
Can anyone help? Pleeeeaaassseee...
View Replies !
View Related
Calculate The Length Of A Spiral
I need to find an equation that gives me the length of a spiral from its point of origin to its center. Trigonometry is really not my forte, and searching through the internet has led me to find there's tons of different types of spirals as there are equations for them. The effect I'm looking for is the following:
A big circle starts moving towards the center of a spiral it stops once its edge touches its starting point (starting point of the circle towards the center of the spiral. After a small distance (5 px in the example below), another smaller circle continues towards the center of the spiral, it stops as soon as te edge of its circumference (its radius) equals the distance it has crossed.
I rougly managed to plot the desired effect
across a straight line on the x axis:
Code:
var i=1;
var endpoint = 550;
var animate_id;
sx = _root.m1._x = 0;//starting point
sy = _root.m1._y = Stage.height/2; //starting point
lr = _root.m1._width; // "last" radius is the diamater, could be any value higher than the radius
function moveMovieClip(){
// upgrade current x by 2 everytime function is called
cx = _root["m"+i]._x += 2;
_root["m"+i]._y = sy;
// radius of current
cr = _root["m"+i]._width/2;
xd = cx-sx; // current x minus last starting point
yd = sy-sy;
d = Math.sqrt(xd*xd+yd*yd); // distance between starting point and current point
// if the value of d is larger than the sum of last radius (lr) and current radius (cr)
// plus 5px(space in between)
if(d >=lr+cr+5)
{
// make current radius las radius
lr = cr;
// make new starting point the current point
sx = cx;
i++;
_root["m"+i]._x = sx;
_root["m"+i]._y = sy;
if(i>5){
clearInterval(animate_id);
}
}
updateAfterEvent();
}
animate_id= setInterval(this, "moveMovieClip", 20)
stop();
this is my spiral equation, i've been on this all day and I have to deliver tomorrow, my brain is not working its best...
Code:
_root.s0.angle = 0;
// initialize first movieClip (m0)
_root.m0.angleChange = 20;
//the radius of the circle
_root.m0.radius = 100;
// the point around which the satellite will orbit
_root.m0.centerX = Stage.width / 2;
_root.m0.centerY = Stage.height / 2;
_root.["m"+i].onEnterFrame = animateSpiral;
m_radius = _root.["m"+i]._width/2
length_of_spiral = ???;
function deg2rad(degree) {
return degree * (Math.PI / 180);
}
function animateSpiral() {
var radian = deg2rad(this.angle);
this._x = this.centerX + this.radius * Math.cos(radian);
this._y = this.centerY + this.radius * Math.sin(radian);
//add the angle change to the master angle for this clip with each
// iteration, so we know how to determine the next x,y point.
this.angle += this.angleChange;
//use modulus to determine the correct angle for any angle greater
// than 360-degrees.
this.angle %= 360;
}
Even if you don't know how to go about it, any advice on coding style is greatly appreciated, i still consider myself a young grasshopper.
Thanks for reading
View Replies !
View Related
Calculate The Length Of A Streaming Mp3. Easy.
Hi,
Flash is funny.
When you stream an mp3 and try to get the duration of the song, you only get the duration of the part of the song that has been loaded thus far, but not the entire length of the song! This can be troublesome when making an mp3player. Actually if you ever try exporting (using the bandwidth simulator) the example code in the help files under "sound.duration", its all messed up because the calculation for finding the sound played/the sound total is not using the time played/length of the entire song. But rather its using the time played/the length of the PART of the song that has been downloaded.
So how do we find out how long a song will play without downloading the entire thing first? EASY!
Code:
determineTime = function () {
soundInterval = setInterval(function () {
var loaded = sound.getBytesLoaded();
var duration = sound.duration;
kbps = ((loaded/1000)/(duration/1000));
//trace(kbps);
var total = sound.getBytesTotal()/1000;
timeTotal = (total/kbps)/60;
//trace(timeTotal)
clearInterval(soundInterval);
}, 4000);
};
So what happens here is totally simple. We first determine the kbps of the mp3. Then we use that to find the total length of the song.
Is it perfect? Nope. But good enough for me if I don’t have to specify length of every mp3 that I put into my player.
So there you go.
Hope someone finds that useful. I haven’t seen it before but who knows. Maybe it's old news.
oh yeah and check your publish settings if you keep getting 16kbs and that wasnt the sample rate of your mp3. Shouldn't effect the calculation for the time though.
View Replies !
View Related
Length Of Quadratic Curve?
Calculating the length of a a straight line is simple, using ol Pythagoras theorem.
But how do you calculate the length of a quadratic curve? I've searched around quite a lot for this on google and forums but haven't found anything useful yet..
I don't need it to be 100% accurate, mainly I want to use it to draw a shape consisting of both straight lines and curves, but I want to draw it all in a consistent speed, at least so the viewer doesn't see that the speed changes.
Thanks in advance..
View Replies !
View Related
Getting The Length In Pixels Of Dynamic Text
Hi there,
I can get the length of a static piece of text in pixels using getProperty("MovieName",_width).
For example "me" might be 20 pixels long, whereas "him" might be 30 pixels long.
However if the text is dynamically put in a text field, then the length of the movie is not updated.
Any advice please?
Thanks, Kevin.
View Replies !
View Related
[PROBLEM] CurveTo - Calculate Length Of Path
Hi there...
how can you calculate the length of a path/curve dynamically created with AS. Example:
Code:
this.curveTo(mc1._x, mc1._y, mc2._x, mc2._y);
I found several complex formulas on math-dedicated websites though. But I'm not smart enough to adapt these to my AS-Code Hopefully someone in this forum has the answer!?
View Replies !
View Related
FMX- Determine Real Length Of Phrase In Pixels
Hello!
I am wondering if anyone knows a way to determine the real length in pixels that a phrase uses.
The problem lies on the fact that every character does not take the same space (x pixels).
Let's say I have a dynamic text field and I want to know how many pixels does the sentence use.
i.e:
is not the same to have:
phrase #1 =iiiiiiiiii
than
phrase #2 =wwwwwwwwww
even though both are using 10 characters.
What is the most precise way to find this out?
thanks.
View Replies !
View Related
FMX- Determine Real Length Of Phrase In Pixels
Hello!
I am wondering if anyone knows a way to determine the real length in pixels that a phrase uses.
The problem lies on the fact that every character does not take the same space (x pixels).
Let's say I have a dynamic text field and I want to know how many pixels does the sentence use.
i.e:
is not the same to have:
phrase #1 =iiiiiiiiii
than
phrase #2 =wwwwwwwwww
even though both are using 10 characters.
What is the most precise way to find this out?
thanks.
View Replies !
View Related
Math Pixels To Inches Problem
Hey all,
I'm almost done with a big project I've been doing in MX. It's a T-shirt designer that allows users to select an image from an html table, imports that into a MC, and from there allows the user to manipulate it. I've written an actionscript that converts the pixel dimensions of the image into inches (so the user can change the size by entering inches). As there are multiple shirt sizes available, this formula changes based on the shirt size selected.
Once the user is done, they then click a "purchase" button which passes all the variables to a php script which summarizes their purchase. The pixels-to-inches translates fine as long as the shirt size selected is XL. If you choose any other size, it spits out all kind of skewed numbers. The php script just grabs whatever variable Flash hands it, and rounds it to the nearest integer, so this is not a php issue. For instance, if I set the height of the image on a L-sized shirt to 5 inches, it keeps outputting as 1 inch high.
For a clearer idea of what I'm talking about, check it at:
http://www.designoneshirt.com/Aliens/index.php
Select an image to enter the Flash.
And finally, the actionscript:
on (release) {
selectedSize = _root.sizeBox.getSelectedItem().label;
if(selectedSize == "XL" && _root.value > 14){
_root.value = 14;
}
if (selectedSize == "L" && _root.value > 13){
_root.value = 13;
}
if (selectedSize == "M" && _root.value > 12){
_root.value = 12;
}
if (selectedSize == "S" && _root.value > 10){
_root.value = 10;
}
initHeight = _root.dimH;
hStrL = (initHeight.length -1 );
shirtHeight = initHeight.substr(0, hStrL);
converted = (250 / shirtHeight);
inputConverted = (_root.value * converted);
setProperty("_root.dynamicImage", _height, inputConverted);
_root.heightBox.text = inputConverted;
}
The above is for the "height" button only. The width button is identical, save different variables. The number 250 is a set value, the width of the available space on the shirt. "_root.value" is the user's input, and "_root.dimH" is the height of the shirt (in inches).
If anyone has any ideas or suggestions, please reply. Pulling my hair out here. Thanks.
If anyone wants to see .fla, you can get it here:
http://www.designoneshirt.com/flas/shirtDesign.fla
View Replies !
View Related
Math Help: Smooth Curve Through 2D Points
Okay so I'm working on understanding blob detection. I've used the Marching Square algorithm on a bitmap to find the edge pixels of the shapes. But when I string those together and draw it I get a very jaggy stair step shape.
So I'm wondering how to take a set of 2D points that describe a closed curve and use that data to generate a smooth(er) curve that could then be stored and used for various purposes.
I found this sample code but it seems to be for Cubic Bezier curves and Flash uses Quadratic Bezier curves. And when you combine my C# knowledge with my math kung-fu I come up very short of being able to understand it and convert it to actionscript. (Plus I'm not even sure it works for closed paths?)
So if anybody (and I guess that really means Kglad) has any understanding or pointers that would be great.
View Replies !
View Related
Plotting On A Curve.. I Need A Math Genius
Hi All
Great forum! I have a problem you might be able to help me with.
I have a curveTo – an anchor point and a control point.
Then I have a function that will return the x and y of a point along that curve if I give it a number as a percentage of the curve (0 to 1).
It looks like this, and works perfectly..
Code:
function drawOnCurve( interval:Number, x0,y0,x1,y1,x2,y2)
{
interval = Math.max( Math.min( 1, interval ), 0 );
var intervalSq:Number = interval * interval;
var difference:Number = 1 - interval;
var differenceSq:Number = difference * difference;
var _obj = new Object();
_obj.x = differenceSq * x0 + 2 * interval * difference * x1 + intervalSq * x2;
_obj.y = differenceSq * y0 + 2 * interval * difference * y1 + intervalSq * y2;
return _obj;
}
// x0,y0 are the start point, x1,y1 the control point and x2,y2 the final anchor point
But… I want to give it a _y value instead of a percentage (interval) and it return where on the curve that would intersect. Is that possible??
What r your thoughts, how should I do this?
Many Thanks
Nic
View Replies !
View Related
Math Related - How Do I Calculate If Rotation Should Be Poisitive Or Negative?
Haven't had a math class in years, so I'm stuck on this one:
In my .fla I have a lever that is attached on one end - the user should be able to grab it and rotate it with the mouse around it's pivot.
I couldn't think of a better way to do this, so I placed a movieclip B at the tip of lever movieclip A. I then use the acos (arc cosine) function between A's registration point, B's registration point and the mouse to find the angle of rotation when the user drags the lever with the mouse:
Code:
function findAngle(a:Number, b:Number, c:Number):Number {
return Math.acos((sqr(b) + sqr(c) - sqr(a)) /( 2 * b * c));
}
However, this only works in one direction, because the inverse of cosine is always positive. I can't seem to figure out what function to use to determine whether the rotation should be positive or negative. Any ideas?
View Replies !
View Related
Bell/Average Curve (Math & Drawing)
I'm trying to draw a curve based on 24 data points. I want to draw a curved line based on the average of these 24 points. I can draw a line from point to point no problem, but would like a smooth curve.
Can someone help me with the equations and code to do this?
The white dashed line is what I'm trying to achieve:
Thanks!
View Replies !
View Related
Calculate Size Based On Aspect Within Constraint Math Question
Hi all!
Since I'm mathematically challenged, could someone please help me with this?
Given a MCs size (say 360 x 240), how would I calculate the maximum size a shape inside that MC could be given the shapes aspect ratio?
In other words, given the MC dimensions above:
a 2:2 ratio would result in a 240x240 max size (within the MC).
a 9:2 ratio would result in a 360x80 max size (within the MC).
a 1.5:4 ratio would result in a 90x240 max size (within the MC).
I can do this in my head but I can't seem to write it down/ code it.
Ideally, I'd just pass the 4 vars to a function like so:
function(mc._width, mc._height, x-aspect, y-aspect)
and then output result_width and result_height
Thanks for any help!
View Replies !
View Related
I Need Some Simple Math Help: Want To Make A Sinus Curve Motion
I want to make an MC rise in a slow sinus curve motion, sort of like a leaf falling the wrong way.
This is what I have done but it doesn't seem to work properly and I am crap at math so please help me. I did some searching in both forum and tutorials but couldn't find anything useful.
Code:
onClipEvent (enterFrame) {
if (_y >0){
_y-=3;
_x += 5*Math.sin(_y);
} else{
this.removeMovieClip();
}
}
View Replies !
View Related
3D Math: Perspective And Focal Length
I am trying to convert this example code to AS3
Orginal source for code:
http://www.kirupa.com/developer/mx/perspective.htm
Code:
onClipEvent (load)
{
z=0;
zspeed=5;
fl=300;
}
onClipEvent(enterFrame)
{
scale=fl/(fl+z);
_xscale=_yscale=100*scale;
z+=zspeed;
}
MY code:
Code:
import flash.events.Event
import flash.display.Graphics
var _z:Number = new Number()
var _zSpeed:Number = new Number()
var _fl:Number = new Number()
var _scale:Number = new Number()
_z = 0
_zSpeed = 5
_fl = 300
var _ball:MovieClip = new MovieClip()
_ball.graphics.beginFill(0xff0000)
_ball.graphics.drawCircle(0,0,200)
_ball.graphics.endFill()
_ball.x = _ball.y = 250
addChild(_ball)
_ball.addEventListener(Event.ENTER_FRAME, zoomOut)
function zoomOut(evtObj:Event):void
{
_scale = _fl/(_fl + _zSpeed)
evtObj.target.scaleX = scaleY = 100*_scale
_z+=_zSpeed
}
Any ideas?
Alan
View Replies !
View Related
AS3 - Math Issue In Displaying Video Length
I am using the code below to display the time of a video. The problem I am having is that it is displaying the hours, minutes and seconds (00:00:00) I only need it to display the minutes and seconds (00:00). How would I go about doing that?
ActionScript Code:
var totalLength:uint;
var nowSecs:Number = Math.floor(stream.time);
var totalSecs:Number = Math.round(totalLength);
View Replies !
View Related
Video Length Does Not Match Music Length
I want to have a 3 minute wav file loop infinitely over a 20 second flash video which also loops infinitely. The only way I have found to do this is to copy and paste the video so it repeats itself for 3 minutes, then the whole thing loops. Is there a way to run my 3 minute wav file in the background of my 20 second video conveniently?
Here is an example of what I have already made:
http://www.limdallion.com/Characters/Pyk/Pyk.shtml
View Replies !
View Related
Mp3 Sound Length And Played Length
hey i have an mp3 players, is a lot of code so im not going to post it all at.
but what i want is something to tell me the length of the sound and the current playing time..
well i will post this much of the code that i made i just don't know how to turn it into minutes and seconds.
Code:
private function onEnterFrame(event:Event):void
{
// this is the total estimated time
estimatedTotal = Math.ceil(snd.length / (snd.bytesLoaded / snd.bytesTotal));
// this is how much the sound played in %
position = Math.round(100 * (sc.position / e));
// i was just testing with aprogress bar
run.setProgress(p, 100);
}
so how i turned this code that works into minutes and seconds.
View Replies !
View Related
Mp3 Length Don't Match Timeline Length
I got myself a simple setup - an animation playing against an audio track. I've used 'use imported mp3 quality' in the export dialogue box. I've got a root timeline of 814 frames long. At 25 fps this gives me a timeline length of 32.5 seconds - this should be the same length as the mp3.
however the mp3 finishes about 5 seconds before the timeline?
How are you meant to sync audio to animation if there is that much discrepency? I haven't got anything processor intensive on the timeline.
View Replies !
View Related
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");
View Replies !
View Related
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
View Replies !
View Related
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,
View Replies !
View Related
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.
View Replies !
View Related
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?
View Replies !
View Related
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
View Replies !
View Related
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.
View Replies !
View Related
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
View Replies !
View Related
Calculate FPS
Does anyone know how to calculate what your FPS(Frames per second) from an MP3 file? Here are some properties
Stream: MPEG Layer 3
File Size: 234,057 Bytes
Duration: 00:14.628
Buffer Time: 1.0 seconds
Max Bit Rate: 128.0 Kbps
Max Stream Bit Rate: 128.0 Kbps
View Replies !
View Related
HOW TO ADD N CALCULATE Accordingly
Hi pple,
I have this input text for my client to input the quantity for the different items that they want.
Each items cost differently. Eg. 3 items: Bananas selling at $0.30/ each, Apples at $0.50/each & Durian at $1 each.
If my client select that he wants to buy 3 Durians, he would type 3 in the 'QUANTITY' Box and under the combo box, place "DURIAN".
What I intended is to also show him the total cost of the fruits at the bottom. Labelled the box at "total cost".
Can anyone advise me how to do so because I dont really know bout actionscripting.
Pls advise
View Replies !
View Related
Is This Possible To Calculate?
Hi
I was wondering if anyone had any ideas as to how to do this...
I would like to calculate how long in time it will take a movie clip to go from point A to point B.
Like Example:
thisclip._x=0;
on enterframe
{
thisclip._x += 2;
}
If the destination is 100 for _x, how can I calculate how long it will take for thisclip to go from _x (0) to _x (100)????
I hope you guys know what I mean... I'd really appreaciate any info.
Thanks!
View Replies !
View Related
Will This Calculate?
hey guys...I dont usually do web stuff...but after a question I saw here a while ago thought I'd try preloding...anyways...I bin trying thiscode together...but cant test it as its not online so I dont know if it will work or not...
I'm trying to calculate the percentage of the main movie on _level0 and the swf loding into _level3 combined and play the two movies once 100%of both are loaded - whilst showing the combined percentageas of the 2 moviesas it loads...
so can anyone tell me...would this work??? I'm fairly sure it would if I just did it for the main movie(this) as I tested that with the show streaming in the test movie - but that wont test a external movie...
if ((_level3._framesloaded+this._framesloaded)>0 &&
(_level3._framesloaded+this._framesloaded)==
(_level3._totalframes+this._totalframes)) {
_level3.gotoAndPlay("go");
_level0.gotoAndPlay("go");
} else {
percentage = int((100/(_level3.getBytesTotal+this.getBytesTotal()))*(_level3.getBytesLoaded+this.getBytesLoaded()));
_level0.output=percentage+"%";
}
Thanks for checking it over...
View Replies !
View Related
Calculate A String
Hi,
I have a string with a calculation in it "((20+10)/10)*100"
Is there anyway you can evaluate the string to get the actual answer of the calculation which would be 300?
Leah
View Replies !
View Related
How To Calculate This Score?
Hi guys!
I'm trying to make a score algorithm but I'm stuck. Please help!
So I have a picture that the user can rotate and then take a screenshot. There is an ideal rotation, let's say 11° for instance, and he only can rotate the picture to 45° from each side, so 45° and -45°.
I want to give him a score based on that. So 11° is the ideal value, he will obtains a score of 100. -45° is the worst value that will get him 0. Yes, I would like the score to be a number from 0 to 100.
I was wondering if anyone could help me, or offer me an advice!
Thanks!
View Replies !
View Related
Calculate With Flash
I want to make to textboxes so when I type in some numbers in one of them the other multiply it with for example 2. So I type 3 click on a button and get 6 in another box. What code do I have to use?
View Replies !
View Related
Calculate Acceleration
Hi I'm looking for a formula to calculate the rate of Acceleration from given coordinates
Say i have a car travelling 50 metres in 40 seconds
At the start, the car is at 4.5 metres
10 seconds of the way (1 quarter of the way) the car is 5.5 metres
20 seconds of the way (1 half of the way) the car is 9 metres
30 seconds of the way (3 quarters of the way) the car is 25 metres
40 seconds of the way (at the end) the car is 55.5 metres
is there a way i can calculate the inbetween segments, for example what distance the car would be at 15 seconds?
any help appreciated. Thanks
View Replies !
View Related
[CS3] How To Calculate The Fastest Way
Dear Flashkitters,
I'd like to make a game. A strategy game actually.
But for this, I need to figure out the fastest way for a non playable character (NPC) to get somewhere. I hope you'll understand what I mean by checking the following example:
The field of the game is defined by array's. In these arrays, the NPC is shown as an 'O'. All the obstacles are shown as 'X's and just empty (walkable) field is shown as '_'. The place where the NPC has to go, is shown as an 'F'.
The field:
field1 = Array('_','_','_','_','_','_','_','_','_','_');
field2 = Array('_','_','_','_','O','_','_','_','_','_');
field3 = Array('_','_','_','_','_','_','_','_','_','_');
field4 = Array('_','_','_','X','X','X','X','_','_','_');
field5 = Array('_','_','_','_','_','_','_','_','_','_');
field6 = Array('X','X','X','_','X','_','X','X','X','X');
field7 = Array('_','_','_','_','_','_','_','_','_','_');
field8 = Array('_','_','_','X','X','X','X','X','_','_');
field9 = Array('_','_','_','_','_','_','_','_','_','_');
field0 = Array('_','_','_','_','_','_','_','F','_','_');
So, how can I with actionscript, calculate the fastest way to F for the NPC (O)
Thanx in advance.
View Replies !
View Related
Calculate Two Numbers
Hi, I have put this code on a button so when it is pushed it should subtract the two values inserted into the input box
on (release) {
equals = input1 - input2;
}
What comes into the dynamic text box instead of the answer is 'NaN'
Do I need another code on an actions layer or something?
Thanks
View Replies !
View Related
Calculate Two Numbers
Hi, I have put this code on a button so when it is pushed it should subtract the two values inserted into the input box
on (release) {
equals = input1 - input2;
}
What comes into the dynamic text box instead of the answer is 'NaN'
Do I need another code on an actions layer or something?
Thanks
View Replies !
View Related
Calculate Angles
Hi all,
Im facing a problem with the angles calculation. I searched through actionscript.org and found the AS to calculate angles in relative to the mouse cursor.
That is only part of what I want to achieve. As Im doing a Maths activity, I need to be able to draw the angle that the 2 lines have created. But I have no idea how?
I thought of masking, but is there a better way? As I drafted out, it seems messy. Any ways that AS can achieve? The script is as follows:
There are 2 lines. One is static horizontal, one is an MC called arrow.
onClipEvent (mouseMove) {
trace(this._xmouse);
x=this._xmouse;
y=this._ymouse*-1;
angle = Math.ceil(Math.atan(y/x)/(Math.PI/180));
if(x<0){angle+=180}
if(x>=0&&y<0){angle+=360}
_root.angletext=angle;
_root.arrow._rotation=angle*-1;
updateAfterEvent();}
How do I draw the angle that these 2 lines have created? Hope anyone can give me some enlightenments. Thanks a million.
View Replies !
View Related
How To Calculate An Intercept Course?
Hi all, I've been trying to crack this problem for more than two days now, and it's starting to frustrate me.
Here's the situation. I'm working on a game which will involve space battles, and automated turrets. The turrets are giving me the headache right now. Here's what I got so far.
http://home.planet.nl/~bogaa096/Starfight/Alpha22.html
The problem is, that the turrets aim at the center of their target, instead of aiming in front of their target to compensate for their movement. I can't seem to crack the equations needed to get the right rotation, for the turret to fire from.
The data the turret has avaible, or that I could easily make avaible to it, are:
- The distance to the target (and it's x and y components)
- The current speed vector (the size and rotation)
- The angle between the heading of the target and the turret's location
- The speed of the turret's shot (fixed speed)
If anyone here could help, I'd much aprecciate it!
View Replies !
View Related
How To Calculate The Bytecode?
http://www.gotoandplay.it/_articles/...Protection.php
i saw this page said that the bytecode can protect our swf, and i use ASV4 tried it, it successful...
but the important thing is how to calculate out the bytecode?
i convert those ascii to string, it just can read some of the string...
can anyone teach me??
View Replies !
View Related
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?
View Replies !
View Related
Calculate Score
Can someone pls help.
Script suppose to write correct and incorrect answers and then display in summary, but not working.
Below is main script and script for summary.
main script:
function QuizItem(question)
{
this.question=question;
this.answers=new Array();
//reset stats
this.numOfAnswers=0;
this.correctAnswer=0;
//returns question of this item
this.getQuestion=function()
{
return this.question;
}
// add answer to multiple choice items
this.addAnswer=function(answer, isCorrectAnswer)
{
this.answers[this.numOfAnswers]=answer;
if (isCorrectAnswer)
this.correctAnswer=this.numOfAnswers;
this.numOfAnswers++;
}
// this function returns the n-th answer
this.getAnswer=function(answerNumberToGet)
{
return this.answers[answerNumberToGet];
}
// returns index of corret answer
this.getCorrectAnswerNumber=function()
{
return this.correctAnswer;
}
// checks if the passed number is the correct answer index
this.checkAnswerNumber=function(userAnswerNumber)
{
if (userAnswerNumber==this.getCorrectAnswerNumber())
gotoAndPlay("Correct");
//Correct_Incorrect.text = "Correct";
else
gotoAndPlay("Incorrect");
//Correct_Incorrect.text = "Incorrect";
}
this.getNumOfAnswers=function()
{
return this.answers.length;
}
}
//this function parses the XML data into our data structure
function onQuizData(success)
{
var quizNode=this.firstChild;
var quizTitleNode=quizNode.firstChild;
title=quizTitleNode.firstChild.nodeValue;
var i=0;
// <items> follows <title>
var itemsNode=quizNode.childNodes[1];
// go thru every item and convert it into our data structure
while (itemsNode.childNodes)
{
var itemNode=itemsNode.childNodes;
// <item> consists of <question> and one or more <answer>
// <question> always comes before <answer>s
// (Ie: <question> is the node 0 of <item>
var questionNode=itemNode.childNodes[0];
quizItems=new QuizItem(questionNode.firstChild.nodeValue);
var a=1;
//Go thru every answer and add to data structure
// <answer> follows <question>
var answerNode=itemNode.childNodes[a++];
while (answerNode)
{
var isCorrectAnswer=false;
if (answerNode.attributes.correct=="y")
isCorrectAnswer=true;
quizItems.addAnswer(answerNode.firstChild.nodeValue, isCorrectAnswer);
// goto the next <answer>
answerNode=itemNode.childNodes[a++];
}
i++;
}
//decoding complete, start now
gotoAndStop("Start");
}
var quizItems=new Array();
var myData=new XML();
myData.ignoreWhite=true;
myData.onLoad=onQuizData;
myData.load("quiz.xml");
stop(); //continue when xml is loaded
summary script:
userScore=(numOfQuestionsAnsweredCorrectly*100)/(numOfQuestionsAnsweredIncorrectly+numOfQuestionsAnsweredCorrectly);
stop();
thanks,
alex
View Replies !
View Related
|