Map With 'my Nearest'
Hi all... heres one for you...
Will defo need coding etc, but let me know your ideas:
I've got a database of shops with address's and postcodes. I want to have a system where the user would enter their post-code, and the map would show the nearest shops.
I know different websites do this, but I want it to go off my database.
It might not need flash, but any ideas would be appreciated.
Cheers, Andy
ActionScript.org Forums > Flash General Questions > Other Flash General Questions
Posted on: 07-21-2005, 04:22 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Distance To Nearest Anything...?
I would like to be able to have many instances of a movie clip symbol all over a large field, with each one making independent decisions according to the same rules.
I want it to only look at the symbols nearby, perform calculations based on
the distance to the nearby symbols and the frames they are on, and then either go to another frame or not. It doesn't matter which instance is nearby.
Is the only way I can do this really to measure the distance between every symbol to every other symbol, one at at time? That seems hopelessly clunky. (and exponentially more so as I add more copies...)
Next Nearest Birthday
Hey there,
I've been using the following code to obtain the next nearest birthday:
code:
// this is an array of three objects
// each object has a name and a bday
dbase = [{name:"John", bday:new Date(88, 7, 21)},
{name:"Mary", bday:new Date(88, 7, 29)},
{name:"Paul", bday:new Date(88, 7, 12)}];
today = new Date();
var year = today.getFullYear();
var closestBday = undefined;
var closestIdx = 0;
for (var i = 0; i<dbase.length; ++i) {
// for the person i
// get their birthday for this year
var nextBday = new Date(year, dbase[i].bday.getMonth(), dbase[i].bday.getDay());
// check if it already happened
if (nextBday.getTime()<today.getTime()) {
// if so, get their birthday for next year
// trace(dbase[i].name + ' already had a birthday this year');
nextBday = new Date(year+1, dbase[i].bday.getMonth(), dbase[i].bday.getDay());
}
// check if it's the closest birthday so far, if so, keep track of it
if (closestBday == undefined || nextBday.getTime()-today.getTime()<closestBday.getTime()-today.getTime()) {
closestBday = nextBday;
closestIdx = i;
}
}
trace('The next birthday belongs to '+dbase[closestIdx].name);
trace('who will be '+(closestBday.getYear()-dbase[closestIdx].bday.getYear())+' years old');
trace('on '+closestBday);
For some reason, the output is John (August 21), although it should be Paul (August 12).
I can't seem to find an error here, therefore any suggestions/thoughts are highly appreciated...
I desperately need your help here...
Rounding Up To Nearest 10
Hi everyone
I really hope someone can help me
I need to know how to use maths in Flash to convert my x & y coordinates to increments of 10
I have worked out how to remove the decimal points using the 'round' operator, but when I divide the number by 10, drop off the decimal point, then multiply it by ten, the decimal value returns.
here's my current code (where the initial value of 'positionx' might be something like 244.67):
Code:
trace(_root.mc.positionx); // number equals 244.67
trace(Math.round(_root.mc.positionx)); //number will equal 247
trace(_root.mc.positionx/=10); // number will equal 24.7
trace(Math.round(_root.mc.positionx)); // number will equal 25
trace(_root.mc.positionx * 10); // number will equal 247
the modified number I am after would be 250
I know I am probably doing this wrong - so if there's anyone who could put me straight that would be fantastic
thanks heaps
Rounding Off To Nearest 0.5
Hello guys
I need to do this ONE tiny bit before my app is complete.
Math.round lets me round off to the nearest integer, but now I really need to round off to the nearest 0.5 or whole number.
ie.
10.488889 ~ 10.5
16.9999555 ~ 17
4.9999999 ~ 5
11. 51111111 ~ 11.5
Yep the values are somewhat like those. It's really really close to the 0.5 or whole values. I've been racking my brains for the past 2 hrs and I really can't figure it out.
Will appreciated any help. Thanks a lot!!!!!!!!!!
Rounding Ot The Nearest Hundreth
I have a variable that is a number devided by a number. when its somethinglike 3 / 2 then I get a long repeating decimal. For instance:
var number=.3333333333333333333.......
how can I round it to the nearest hundreth, so it'll be
var number=.34
To The Nearest Half Metre
Hi, I am trying to do this efficienty - but I keep over complexifying things.
I have a room area calculator that returns a value in cm2.
I am trying to convert it to the nearest half metre.
For example.
8.55m2 will become 8.50m2
156.84m2 will become 157.00m2
101.12m2 will become 101.00m2
I've been up for a very long time and its now 2.23am in the uk.
But, I cannot turn in till this is done.
Any suggestions - I'm sure I'm missing something obvious.
M@?
How Do I Round A Number To The Nearest 5 Or 10?
I have the following numbers: 10.98, 1.23, 5.66.
I want to round the last digit to the nearest 5, to get: 11.00, 1.20, 5.70.
What's the best way of doing this?
Any help would be appreciated.
Thanks.
OM
Round To Nearest Multiple Of X?
Hi peeps,
One for the math code heads.
I have a scroll bar that is scolling a project list (each project being dynamically loaded). Currently the buttons at either end of the scroll bar shift the list by x amount (being the height of a project window) so that the projects are lined up neatly in the view. You can see what I mean on the site (navigate to recent work and scroll the projets with the buttons) http://www.mainframe.co.uk .
I am now adding drag function to the slider. This means the list moves freely in relation the slider being dragged. However, when the slider is released the project list won't be lined up correctly as it is dependant on the users final drag position.
So here is what I want to acheive. Say the list should move by 150 pixels each time so the projects stay lined up correctly. How do I find the nearest multiple of 150 to the new list position? Example, the user drags the slider and the list moves by 340 pixels. The list would need to move back to 300 and not forward to 450. Can I specify a multiple of 150 in the math.round script? Is this even possible?
Hope I've made my question clear enough.
Thanks for any input.
Regards, Carl
Best Way To Round A Value To Nearest 45 Degrees?
I just wrote this to return the nearest 45 degree angle. Like 0, 45, 90, 135...
It feels like there must be a better way of doing this though. This is working fine but it looks messy.
PHP Code:
public function nearestDeg(degs:int):int {
if (degs >= 0 && degs <= 45) {
if (degs <= 23) {
return 0;
}else {
return 45;
}
}
if (degs > 45 && degs <= 90) {
if (degs <= 68) {
return 45;
}else {
return 90;
}
}
if (degs > 90 && degs <= 135) {
if (degs <= 113) {
return 90;
}else {
return 135;
}
}
if (degs > 135 && degs <= 180) {
if (degs <= 158) {
return 135;
}else {
return 180;
}
}
if (degs > 180 && degs <= 225) {
if (degs <= 203) {
return 180;
}else {
return 225;
}
}
if (degs > 225 && degs <= 270) {
if (degs <= 248) {
return 225;
}else {
return 270;
}
}
if (degs > 270 && degs <= 315) {
if (degs <= 293) {
return 270;
}else {
return 315;
}
}
if (degs > 315 && degs <= 360) {
if (degs <= 338) {
return 315;
}else {
return 360;
}
}
return 0;
}
Rounding To The Nearest Tenth?
Hi guys,
I was just wondering if there was any way to round a number only to the first number beyond the decimal. I know that Math.round(X) rounds the whole number, but I'm not looking for that.
For example, with Math.round, 8.4345809 would go to 8, but I want it so it goes to 8.4.
Thanks a lot!
OnMovieFinished ? Or Nearest Function...
I am trying to tell a movie to play to the end of movie 1... once it has reached the end then play the next movie... basically I have
ActionScript Code:
mc_globe.gotoAndPlay("playEnd");
mc_globe.loadMovie("mapNewZealand.swf");
but the new movie is loaded before the last movie finishes playing. When tweening there is the function onMotionFinished... is there anything similar to say when a movie has finished playing then do x ?
Thanks in advance
Determining Nearest Number To Var
Trying to make a seek function for a video file. I want to be able to test the current time and determine the next closest number to jump to. (they are contained in vars from an xml file).
So if the time is 43 seconds, and I want to go forward, how would I say out of 91, 123 and 234 that 91 is the nearest neighbor. Or am I missing it all together and there is a better way?
Round To The Nearest Hundredth?
Hello,
I have a dynamic text box that increases its number by 0.08 every frame, for some reason however, when it reaches around 8, or 9, it starts displaying "9.04000000..." then at about 20, it says "23.529999999999999..." since these numbers extend out of the text box, i was wondering if I could round to the nearest hundredth. I cant use the normal Math.Round() because 0.08 rounds down to 0, and it just sticks at 0. So, is there a way I can round to the nearest hundredth??
Im using this actionscript:
--
_root.onEnterFrame = function() {
num = num + 0.08;
};
--
Thanks,
How Do I Round A Number To The Nearest 5 Or 10?
I have the following numbers: 10.98, 1.23, 5.66.
I want to round the last digit to the nearest 5, to get: 11.00, 1.20, 5.70.
What's the best way of doing this?
Any help would be appreciated.
Thanks.
OM
Nearest Face Of A Square.
Heyas
I've got a problem and I'm in like my 10th revision of code so maybe you all could help.
I am building a cut-down version of Visio so to speak, where you have shapes on the stage that allow you to connect between the two. So if you wanted to connect ShapeA(x:0,y:0) to Shape B (x:100, y:100) it is regarded as being in the TL corner. Thereby ShapeB's faces available are North and West which can be connected - resulting in no lines crossing over into a shapes inner region.
The concept i want to implement is that when you drag your line connector over your intended drop shape, it snaps to the nearest face (North,East,South,West) aswell as the nearest position you were draging over... ie if the end Line connector node is in the bottom left corner of your drop shape and the nearest face is West, it would then maintain the Nodes.y position but snap the Nodes.x position to the intended shapes x.postion - resulting in a snapping concept being in play.
I can get this happening on two variations. First being line Interesects, where i could determine which face has actual line intersection, based on that it determines the face.
I have also tried measuring the distance between two points, finding the shortest one and snapping to the appropriate face.
The problem with these two basically are this. If you drag your line in a 45 degree angle, so that its basically in the dead center of North/West it can't seem to determine the nearest face as its now either North/West?
I had implemented a Random Choice in the event this occures (ie randomly chooses between North or West).
Has anyone else done something of this nature? something along the lines of Line of Site mayabe?
How Do I Round A Number To The Nearest 5 Or 10?
I have the following numbers: 10.98, 1.23, 5.66.
I want to round the last digit to the nearest 5, to get: 11.00, 1.20, 5.70.
What's the best way of doing this?
Any help would be appreciated.
Thanks.
OM
Nearest Face Of A Square.
Heyas
I've got a problem and I'm in like my 10th revision of code so maybe you all could help.
I am building a cut-down version of Visio so to speak, where you have shapes on the stage that allow you to connect between the two. So if you wanted to connect ShapeA(x:0,y:0) to Shape B (x:100, y:100) it is regarded as being in the TL corner. Thereby ShapeB's faces available are North and West which can be connected - resulting in no lines crossing over into a shapes inner region.
The concept i want to implement is that when you drag your line connector over your intended drop shape, it snaps to the nearest face (North,East,South,West) aswell as the nearest position you were draging over... ie if the end Line connector node is in the bottom left corner of your drop shape and the nearest face is West, it would then maintain the Nodes.y position but snap the Nodes.x position to the intended shapes x.postion - resulting in a snapping concept being in play.
I can get this happening on two variations. First being line Interesects, where i could determine which face has actual line intersection, based on that it determines the face.
I have also tried measuring the distance between two points, finding the shortest one and snapping to the appropriate face.
The problem with these two basically are this. If you drag your line in a 45 degree angle, so that its basically in the dead center of North/West it can't seem to determine the nearest face as its now either North/West?
I had implemented a Random Choice in the event this occures (ie randomly chooses between North or West).
Has anyone else done something of this nature? something along the lines of Line of Site mayabe?
How Do I Round A Number To The Nearest 5 Or 10?
I have the following numbers: 10.98, 1.23, 5.66.
I want to round the last digit to the nearest 5, to get: 11.00, 1.20, 5.70.
What's the best way of doing this?
Any help would be appreciated.
Thanks.
OM
To The Nearest Half Metre
Last edited by gameon : 2003-09-26 at 01:36.
Hi, I am trying to do this efficienty - but tend to over complexify things.
I have a room area calculator that returns a value in cm2.
I am trying to convert it to the nearest half metre.
For example.
8.55m2 will become 8.50m2
156.84m2 will become 157.00m2
101.12m2 will become 101.00m2
Im tired, so this solution may not be great. But - it does the job.
To you pro-coders:
Can you do this better?
Am I formatting the script as it should be?
Am I using variables correctly?
Code:
//This is a sting of the length in cm, with the last two digits
//as the mm
//EG: 156.84m2 goes to 15684
//There will be no lengths uner 1m2 or over 100m2
var Cm2 = String("15684");
var SwitchNo = Cm2.length;
switch (SwitchNo) {
case 3:
//Convert to x.xxm
var TheTest = Cm2.substring(0,1)+"."+Cm2.substring(1,3);
break;
case 4:
//Convert to xx.xxm
var TheTest = Cm2.substring(0,2)+"."+Cm2.substring(2,4);
break;
case 5:
//Convert to xx.xxm
var TheTest = Cm2.substring(0,3)+"."+Cm2.substring(3,5);
break;
default:
//ERROR
var TheTest = "Do error";
}
//Get the last two digits
var LastTwo = TheTest.substring(TheTest.length-2,TheTest.length-1)+TheTest.substring(TheTest.length-1,TheTest.length);
//Covert them into a number
var LastTwoNum = Number(LastTwo);
//When this variable is true we will be adding a m on and setting the last
//two digits to '00' - this will be for anything above x.74m
var Add1=false;
//if the number is not greater than zero
//it is zero - so leave it alone
if(LastTwoNum>0){
//if the number is not 50 it must be lower or higher
if(LastTwoNum!=50){
//if taking off 26 makes it lower than 0 - its less than 25
//so we round down
if((LastTwoNum-26)<0){
LastTwoNum=0;
}
//if adding 26 takes it over 100
//we round up
else if((LastTwoNum+26)>100){
LastTwoNum=0;
Add1=true;
}
//this is a catch - set it to 50
else{
LastTwoNum=50;
}
}
}
//get the digits before the '.'
var FrontNumber = Number(TheTest.substring(0,TheTest.length-3));
//if 'Add1' is true : add 1
if(Add1){
FrontNumber+=1;
}
//turn LastTwoTest into a sting of LastTwoNum
var LastTwoTest = String(LastTwoNum);
//if LastTwoTest is a single digit (<10) add a zero infront
//(to make it 00)
if(LastTwoTest.length<2){
LastTwoNum+="0";
}
//output result!
TheTest = String(FrontNumber+"."+LastTwoNum+" m2");
trace("TheTest= "+TheTest);
Cheers if you have the time...
M@)
Round Up/down To Nearest 90 Degrees.
Hi guys.
I have a graphic (arrow) which spins round on the same spot pointing to wherever the mouse go's.
Instead of the arrow pointing to every single angle (360 degrees) I want it to either point up, down, left or right. I think it might need rounding up/down some how to the nearest 90 degrees?
Here's my code that I use just to spin the arrow graphic.
onClipEvent (load) {
_x += Number(2);
friction = .7;
speedratio = .2;
xspeed = 0;
yspeed = 0;
xgoal = this._x;
ygoal = this._y;
}
onClipEvent (enterFrame) {
// figure out our slope
var slope = (_root._ymouse-_y)/(_root._xmouse-_x);
// get it in usable form...
var radians = Math.atan(slope);
var theta = (radians*180)/Math.PI;
theta += (_root._xmouse<_x) ? 180 : 0;
// set the rotation
_rotation = theta;
}
Can anyone help?? Much appreciated.
Search Page For Nearest Dealer
I like to make a search page when u fill in a zip code [the place where you live]. The result will give a name and adress of a nearest dealer in that region.
Can please someone help me with a script or fla file.
ThanXs
Search For The Nearest Location By ZIP CODE
Greetings,
I am posting this to find suggestions for creating a flash script that will allow the user to enter their zip code and a potential radius to bring up results of the closest locations...
Thoughts, Suggestions, Rebukes welcome please and Thank You.
JH
How Do I Round A Number To The Nearest Hundreth
I am trying to round a number to the nearest hunredth. I use the Math.round() function, but it rounds to the whole number. How do I round to the nearest hundreth? Any help would be appreciated.
Rounding To Nearest Decimal Place
Hey Flash Family,
I am getting the correct output i want but is also giving me like 8 numbers after the decimal place...all i want is the numbers rounded to the nearest cent meaning only 2 numbers to the right of the decimal point....what do i need to add to the current code to correct this issue.
Thanks N Advance
Attach Code
onClipEvent(enterFrame) {
//Set all variables and text boxes for ROI
//final computations. Verify that data is
//acceptable, if not, show message box to
//tell user to adjust variables
//Establish val_tcost
_root.how.ROIM.val_tcost = (_root.how.ROIM.val_cph * _root.how.ROIM.val_homes) / _root.how.ROIM.val_uses;
//Set text box for tcost
this.txt_tcost.text = "$" + _root.how.ROIM.val_tcost;
//Establish val_savings
_root.how.ROIM.val_savings = (_root.how.ROIM.val_trepair - _root.how.ROIM.val_tcost) * (_root.how.ROIM.val_percent/100);
//Set text box for savings
this.txt_savings.text = "$" + _root.how.ROIM.val_savings;
//compute and post percentage
_root.how.ROIM.val_psavings = _root.how.ROIM.val_savings / _root.how.ROIM.val_trepair;
//Post
this.txt_psavings.text = int(_root.how.ROIM.val_psavings * 100)/100 + "%";
this.btn_placeorder.label = "Place order for " + int((_root.how.ROIM.val_tubs * _root.how.ROIM.val_homes)/_root.how.ROIM.val_uses) + " Tub Guards!";
}
Edited: 05/30/2007 at 07:16:44 AM by dabramshunt
Need To Find Nearest Movie Clips
Hi all,
I have an app which has between 30 and 200 nearly identical movie clips on the stage at any time.
I need to get an array of the top 10 movie clips which have the closest global position (X/Y) to any given clip.
Obviously I could do this with a lot of sorting. And I could do it with a server call, and use PHP, since it has advanced multidimensional array sorting methods. But I'd like to avoid server calls, as they will slow the app down.
Is there some high-level way to do this in Actionscript? I'm using Flash MX (6).
Perhaps collision detection methods can be used?
Thanks in advance!! Kindest regards,
-joshua
staff@dot-comet.com
Numerical Operation Rounding To Nearest 100's
I am trying to create a piece of logic to prevent me from doing tons of if statements. Basically, what I need to do is round to the nearest hundreds. For example, if the integer is 30 it will be rounded to 100; If the integer is 123 then it will be rounded to 200; and so forth.
I have been looking at the math functions but I can't find anything that will suit this logic because math.ceil will round to the nearest whole number (6.1 = 7)
Any suggestions or maybe I need to rethink the logic?
Thanks in advance.
How Do I Round A Number Up To The Nearest Integer? URGENT
Folks,
This is what I got into..
To send a package that weights from 0 to 25 kilos from X to Y costs USD 170. And my company charges 5 dollars for every kilo that's over 25 kilos.
The thing is, I couldn't figure out how to create something that calculates the final price of the shipment.
Example: 50 kilos
The actionscript needs to subtract 50 from 25, then we get 25 kilos over the limit and we would charge 5 dollars for every kilo.
Ok, that part has already been figured. The only problem is that sometimes people send 26.8 kilos (or anything heavier, but with decimals). That's 1.8 kilo over 25, isn't it?
In this case we would charge as of 2 kilos over.
Anything that's after the decimal (except zero) would have to be rounded up to the next number, then the actionscript calculates how many kilos we got over 25.
Did you understand the situation????
Quote:
if (varWeight<=25) {
price = "170.00";
total = "0";
} else if (varWeight>25) {
total = (((((int(((Number(varWeight-25))*5.00;
price = Number(170.00)+Number(total);
}
varWeight = Number(varWeight);
The action above just calculates how many kilos we have over 25, but it's not able to round the number up in case we have something after the decimal.
COULD YOU FIX MY FORMULA??
Tks a lot!!!
Find Nearest Theta(circle) Position
I have objects that fly around randomly.
When the objects come near to a ball they turn around the ball.
With this code:
ActionScript Code:
var degreeIncrement = rpm
theta += degreeIncrement;
theta %= 360;
const DEG_TO_RAD:Number = Math.PI / 180;
var radians:Number = DEG_TO_RAD*theta;
this.x += Math.cos(radians)*Pradius*Direction
this.y += Math.sin(radians)*Pradius
Because theta tells them where they should go they should go in the circle the object sometimes go right through the ball to get to this point. But I don't want the objects to go through the ball when they start to turn around. I want the objects to find the theta position nearest to them, so they won't go through the ball.
Anybody have an idea how to do that?
If my question isn't clear enough please tell me.
Math.floor? Round Down To Nearest 10th
Hi Folks, Math is not my friend so I need some help.
I want to round a whole number down to the nearest whole 10th.
Like 52, becomes 50. Or 49, becomes 40. Or 2005, becomes 2000.
Does that make sense? I imagine it has a math.floor approach, but I can not figure it out.
Thanks in advance for any help!!!
Store Locator To Search By Zip Code And Return 4 Nearest Stores
Hi,
I need to figure out the best way to add an approriate store locator to my site. The site is in flash. I am actually re-doing a site someone else did before me (I have no relationship with them though). and I see that they had a functioning script that searched by zip code in the usa and returned the 4 closest stores to that zip code. However they managed (or had to) to integrate an html form into an html page that looked the same dimensions as the flash movie (the user was redirected to this page when they had to visit the store locator section).
I have been looking online and see many scripts but none that return the four nearest stores, and many seem extremely expensive so although i'm willing to shell out, i'm nervous to do so incase its the wrong thing.
Also, i suppose the script shoudl have enough functionality so tah tif i like, i can search by city or state, since i just had a call from eth client who mentioned they may prefer this. Grrr.
many Thanks in advance of any help/advice/redirection : )
Cheska
|