Getting Rid Of A Few Digits On An Integer
Hey guys, my flash skills are pretty limited, but i finally was succesful in displaying the elapsed time of a mp3 file that is playing in my flash mvie;;;Unfortunately, flash is returnong not only the seconds(ie, when 3 seconds of a file is played, it will display 3000; when 60 seconds have been played, i will see 60000);I am trying to get rid of the 3 last digits of this number .i Don't know how to achieve this; in other programming language that i've used, i was able to transform the number in a string & then get rid of a few characters???Can someone help please?? Thank's alot!!
Adobe > Flash General Discussion
Posted on: 11/18/2006 03:43:52 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Two Digits
This gives the remaining time in a song. I want the seconds to display as two digits 09 for example instead of 9 what is the easiest way to do that.
thanks alot
nbstot = (_level1._totalframes)/12;
nbseco = (_level1._currentframe)/12;
nbsleft = nbstot-nbseco;
time_left = int(nbsleft/60)+":"+int(nbsleft-(int(nbsleft/60))*60);
First Two Digits...
Hi there!
I manage a directory of former students of my school.
Users who want to register must indicate in the form the year they entered the school.
Alas, some of them enter bad years, like "0972" instead of "1972" or "0674" instead of "1974" !!!
Inside a general Validation function, I already have an Array using different validating functions (one for each Field) into which I use "push" to enumerate different mistakes and prevent them with warnings and disabling of the Register Button. Like this one:
validatePromo = function () {
if (_root.promoField.length<1) {
errors.push("- You MUST indicate the year you entered the school.");
}
if (_root. promoField.length<4) {
errors.push("- Year must be four digits long.");
}
if (promotion<1925) {
errors.push("- Enter 1925 as promotion year.");
}
}
What I don't know is how to write the if statement to force user to begin the year string with 19 or 20.
Could you please tell me ?
Many thanks in advance,
Regards
Sum Of The Digits
I have a variable and I want to find the sum of the digits. How do I do that?
I.e. I have
n = 273
And I want to find the sum: 2+7+3 = 12
Sum Of The Digits
I have a variable and I want to find the sum of the digits. How do I do that?
I.e. I have
n = 273
And I want to find the sum: 2+7+3 = 12
Two Digits Behind Point
Hi all,
I made a calculator where customers can can see how much a product is gonna cost. the totalprice can be 899.92378234 euro.
Is it possible to make this 899.92 euro or 900 euro?
You can see an example (in dutch) on http://www.jungleworld.nl/calculator.swf
thnx and sorry for bad english
asjbak
Significant Digits
i'm trying to get a dynamic text box to display a price, ie "$ 3.50"
the variable is added to or subtracted from, so sometimes its a whole number, in which case i need it to show the zero cents. I tried the C way of dividing by 1.00 or multiplying by 1.00, but no dice. Math.round didn't help either, so I'm always stuck with integers or only the ".5"
is there any way to set the variable or the text box to 2 decimal precision?
Last Two Digits Of A Variable
Hey!
I have a question, let's say I have a Variable, Variable A. Variable A is probably over 100. I want to take the last 2 digits of it (so it if was 117 it would be 17, 3415315 = 15 etc.) and make those last 2 digits into a new variable, variable B.
Is there a way to do this?
Thanks!
Getting Digits Of A Number
Hi, I do not have much experience with actionscripting but I have a quick question. All I want to do is have a number (which can be any number between 0 and 20 with one decimal place) and get the ones, tens and the tenth digit of the number separately.
so for example, if a number is 14.5:
ones = 4
tens = 1
tenth = 5
thanks for the help.
Animating Digits
Hi All,
how is everyone doing? Fantastic over here. AND even better if one of you could help me with the following. When looking at the attached, what I`m``trying to do is, animate some digits, which are randomly entering the screen from the left (maybe I can define an are with a mask), then in step two form a large digit (square quadrat) and after some time leave the srceen randomly again to the right. But when I mean randomly, it mustn`t necessarilly be random, important is that the digits come in consequently.
thanks for any advice in advance.
Best,
m.
Animating Digits
Hi All,
how is everyone doing? Fantastic over here. AND even better if one of you could help me with the following. When looking at the attached, what I`m``trying to do is, animate some digits, which are randomly entering the screen from the left (maybe I can define an are with a mask), then in step two form a large digit (square quadrat) and after some time leave the srceen randomly again to the right. But when I mean randomly, it mustn`t necessarilly be random, important is that the digits come in consequently.
thanks for any advice in advance.
Best,
m.
How To Generate Random # That Is Always 16 Digits
Hi,
I need to generate a random number that is always exactly 16 digits long.
I am familar with Random(), but I do not know how to make sure it is always 16 dgits.
Any ideas would be greatly appreciated.
Thanks.
nick
Truncate Output Digits
Hi all,
Here's my little problem. I'm doing some calculations in Action Script and output the results to the screen.
Now the results look like this:
23.263636453737383838383838
Where I would like only four digits behind the decimal point, so:
23.2636
Can anybody help me?
Dynamic Text In ONLY 1 Or 2 Digits
I made a dynamic text field that works like a timer, but it goes into decimals (ex: 50.5555) and I want it to only show 1 or two digits( ex: 50 ). Can anyone help?
Three Digits For Text Preloader...
Hi, I have a small question. In my preloader, I would like to have three digits (eg. 001, 002,...035,036,...099,100). How would I go about doing this? Right now my script contains:
code: bytes_loaded = Math.round(this.getBytesLoaded());
bytes_total = Math.round(this.getBytesTotal());
Percent_Loaded = bytes_loaded/bytes_total;
this.load_text = Math.round(Percent_Loaded*100);
if (Percent_Loaded >= 1) {
gotoAndPlay(37);
}
TIA
Show Score With 6 Digits?
I have a dynamic text box that updates with the player's score. Currently it starts at 0. I would like it to show as 000000 instead. Adding 110 points would show as 000110. How can this be done?
Thanks.
Extract Date With 2 Digits:
I've used a time stamp to get my date and then extracted it with the following:
var timeStamp = new Date().toString();
var today = new Date();
var timeNow = (today.getMonth() + 1) + "/" + today.getDate() + "/" + today.getFullYear();
this works but it gives me one digit results for the month and day such as:
2/2/2006
My customer needs 02/02/2006.
What the heck can I do?
[CS3] Round Numbers To 2 Digits
hi there... i have a dynamic textbox that is populated by the user selecting an item from a combobox... everything works fine except i would like my numbers to have 2 decimal places (like: 4.00, instead of just 4)
i see there's lots of stuff online concerning this and Actionscript 3, but i've coded the entire work in Actionscript 2 and can't change it...
the closest thing i have now that makes any sense to me (even though it doesn't work) is something like this:
Code:
_root.MC1.DynamicField = 9;
var num = _root.MC1.DynamicField;
var str = num.toFixed(2);
any thoughts?
Is It Possible To Have A Preloader That Has 8 Digits If Numbers?
Hello ,
i know this may sound a bit wacky but...
...I want to create a preloader that starts from the number 27658906 and ends at the number 70009803 . Is this in someway possible i cant figure this out cause im new in AS3 so if you have any suggestions that would be much appreciated... thanks..
Limit The Digits. 1.392846 To 1.392
I want to limit a numbers length without rounding cieling or flooring it. I want to cut off the last digits.
For example:
1.83251931
I want as:
1.83251
It's for a simple math game. The user must input an answer, and I will frustrate them if is I round the solution.
Math.round(number*1000)/1000;
is the closest I have to limiting the values, but round is bad.
Split Digits Of Array
Hi guys,
i got a serious problem here.
Tomorrow i got to deliver my project for school, but i got into a problem.
I have this array :
a[0] = _root.spelen22
a[1] = _root.boom49
a[2] = _root.huis6
etc
I want to split the digits off from this array. It can be 1 or 2 digits. so that i keep an array like this :
b[0] = _root.spelen
b[1] = _root.boom
b[2] = _root.huis
Hope that you can give me some help soon , im desperate
Thanx for the help !
Madthijs
Adding Two Numbers(digits)
Hello. I have to input text fields and third - dynamic. Also I have a button. I want that on button press in the dynamic field would be displayed the sum of two numbers entered in those input fields. First field: var1 Second: var2
and dynamic text: answer.
I wrote scipt but look what happens. For example I input to numbers: 5 and 6 I need to get answer 11 but the sum is shown: 56 . Any help? Thanks.
Math: Significant Digits
hey folks, I am trying to get the two significant digits of a value. Anyone know how to do this?
for example, 23900 =>24000
I was trying to write it out as
Math.round(Math.log(Math.abs(value))/Math.LOG10E);
I don't think it's right.
Set Number Of Digits For A Variable
I want to display:
Code:
spdDisplay.text = String(angle/2.1);
but I want it to always display 2 decimal places always. No more, no less.
Can anyone help me out with this?
Adding Two Numbers(digits)
Hello. I have to input text fields and third - dynamic. Also I have a button. I want that on button press in the dynamic field would be displayed the sum of two numbers entered in those input fields. First field: var1 Second: var2
and dynamic text: answer.
I wrote scipt but look what happens. For example I input to numbers: 5 and 6 I need to get answer 11 but the sum is shown: 56 . Any help? Thanks.
Displaying Value Of Variable As 7 Digits
I have made a simple counter in flash that updates live via a php-file that writes to a txt-file. The variable "count" is used to import the number from the txt-file into a dynamic textfield in flash with:
this.loadVariables("count.txt?num="+random(999));
The counter works fine but I want the counter to always display 7 digits, for example 0000025 instead of just 25. This should be fairly simple but I don't know how or if it should be done in flash or php as I am fairly new to both. I am working in flash 8 btw.
Can anyone lend a hand?
Checking Whether An Object Has Two Or Three Digits
hi forum...i have a question..
i duplicated a movieclip many times, and now i need to know how many digits are set at the end, because i use the endings of each movieclip to an array.
with two digits it works fine, i did it this way, but i wont work of course with three digits.
this is what i put on a button:
ActionScript Code:
_root.point1=this._name.substr(["box"+y+x]._name.length-2,1)
_root.point2=this._name.substr(["box"+y+x]._name.length-1)
_root.control.myArray[_root.point1][_root.point2]=0;
can anyone tellme how to do this?
the boxes are numbered from "box00" to "box063"
thanks
sinai
Length Of Digits After Decimal Place
Howdy everyone
I was just wondering how do I get the amount of digits after a decimal place?
for example
12.123456
The answer I would be looking for here would be 6
Thanx
Seperating Digits Using Flash Substrings
Hello All.
I am trying to retrieve data from a server and display it in a font that does not space dynamically the way that my boss, the art director wants it to look. The server will send me 2 and three digit numbers thaty need to be displayed, but because of graphical issues, each digit (first, second, or third) needs to be placed in different dynamic text boxes. I asked the programmer to break up the number in asp and send it as three different variables for me to rearrange in flash but this is a no go. SO i need someone to show me how to "seperate the digits using substings" any takers?
any help would be appreciated.
thanks.
[MX] Detecting 5 Digits In Input Field
Hi all,
I've been noticing users are submitting my form without entering information.
With my limited action scripting knowledge I've been unable to script in a way to check input fields before activating the submit button.
I searched all over google for tutorials and couldn’t find any that has answers to my problems.
If someone with a lot of time wants to help for free, thats always welcome
Edit by admin: no contact info permitted on the forum, thank you. If you want to hire someone, we will move to the freelance forum
MP3 Player, Trouble Displaying 2 Digits
Hi,
I'm new here so please go easy on me
I looked you up for a question regarding a Mp3 jukebox type thingie. It's going quite well (I'm redesigning it for educational purposes). But.. I'm having difficulties displaying two digits. You know, when Flash goes below 9 it's not 09 anymore..
I've tried other scripts and tutorials out there to fix it, but without luck. Any help would be appreciated.
The time related coding appears in three places:
ActionScript Code:
nbstot = (_level1._totalframes)/12;
nbseco = (_level1._currentframe)/12;
nbsleft = nbstot-nbseco;
time_left = int(nbsleft/60)+" : "+int(nbsleft-(int(nbsleft/60))*60)+" ";
ActionScript Code:
if (nbsleft == none) {
} else {
nbstot = (_level1._totalframes)/12;
nbseco = (_level1._currentframe)/12;
nbsleft = nbstot-nbseco;
time_left = int(nbsleft/60)+" : "+int(nbsleft-(int(nbsleft/60))*60)+" ";
}
ActionScript Code:
nbstot = (_level1._totalframes)/12;
nbseco = (_level1._currentframe)/12;
nbsleft = nbstot-nbseco;
time_left = int(nbsleft/60)+" : "+int(nbsleft-(int(nbsleft/60))*60)+" ";
if (cge == 1) {
if (loop == 0) {
unloadMovieNum(1);
loadMovieNum("./movie" + i +".swf", 1);
titre_chanson = eval ("titre" + i);
}
if (loop < 3) {
loop = loop + 1;
gotoAndPlay(21);
} else {
cge = 0;
loop = 0;
gotoAndPlay(20);
}
} else {
gotoAndPlay(20);
}
Best regards,
Marius.
Checking User Input To Limit To Certain Digits
I'm doing a simple binary converter where I want only the digits 1 and 0 input into a box.
Everything works great except I need to check the string (from the input text box) to make sure it's only 1's and 0's. The check is performed when they click on the convert button.
I can do this in other languages using regular expressions, which ActionScript doesn't seem to have, so what's the best way to check user input to limit it to specific characters?
Keep in mind the string can be up to 40 characters long, so manually checking each digit would probably be inefficient.
Do I need to use substring for this?
Thanks.
John
Setting Dynamic Number To 3 Digits? Hard To Explain...
Howdy howdy!
Quick and hopefully simple question. I've got a dynamic text box named "course" and this box is set at a certain number at the start of my movie. As the user hits buttons, this number increases or decreases.
I have on my buttons that if course > 359, it goes back to 0. (Can't have more than 360 degrees right?) This works fine.
Anyway, just found out this number can't go back to 0, it has to go to 000, and count up 001, 002, 003,... etc.
Is there a simple way to do this? I can't figure it out. I can't get it to display the three 0's at all.
Thanks so much in advance. Hope someone can help!
Index Xml Target.name.length And Double-digits Issue
I have an issue, I have about 25 mc's that are named carBtn1 through carBtn25 - the problem is when I index my array - its only taking the first number from the end of the carBtn, so carBtn1 is seen as the same as carBtn10. I tried taking the last 2 digits off which works for 2 digit numbers - but everything below 10 isnt working anymore. Im not sure what to do to get it working....
Here is my code:
Code:
// variables
var popInfo:popMc;
// load xml
var xml:XML = new XML();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("data/cities.xml"));
loader.addEventListener(Event.COMPLETE,
function(evt:Event):void {
xml = XML(evt.target.data);
//trace(xml.city[0].@weburl.toString());
var url:URLRequest = new URLRequest(xml.city[0].@weburl.toString());
}
);
// event listeners
stage.addEventListener(MouseEvent.CLICK, onClickStageRemove);
for (var j:int = 0; j < 11; j++)
{
getChildByName("carBtn" + j).addEventListener(MouseEvent.CLICK, onClickLoadData);
getChildByName("carBtn" + j).addEventListener(MouseEvent.MOUSE_OVER, onCarHover);
getChildByName("carBtn" + j).addEventListener(MouseEvent.MOUSE_OUT, onCarOut);
}
// button mode
buttonMode = true;
// functions
function onCarHover(event:MouseEvent):void
{
event.target.gotoAndPlay(11);
}
function onCarOut(event:MouseEvent):void
{
event.target.gotoAndPlay(10);
}
function onClickLoadData(event:MouseEvent):void
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
//better approach would be add separate classFile to haldle some popInfo's events
//such removing on stageClick in that file u could add those functions:
var index:Number=event.target.name.slice(event.target.name.length-1);
popInfo.carsizeText.text = xml.city[index].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[index].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[index].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[index].@name.toString();
addChild(popInfo);
}
function onClickRemove(event:MouseEvent):void
{
popInfo.closeBtn.removeEventListener(MouseEvent.CLICK, onClickRemove);
popInfo.nyopBtn.removeEventListener(MouseEvent.CLICK, onClickNYOP);
removeChild(popInfo);
}
function onClickStageRemove(event:MouseEvent):void
{
if(event.eventPhase == EventPhase.AT_TARGET) {
removeChild(popInfo);
}
}
function onClickNYOP(event:MouseEvent):void
{
//navigateToURL(url, "_blank");
// navigateToURL(urlNY, "_blank"); //trying to get this variable to work
ExternalInterface.call("selectNY");
}
// set button mode here
Index Xml Target.name.length And Double-digits Issue
I have an issue, I have about 25 mc's that are named carBtn1 through carBtn25 - the problem is when I index my array - its only taking the first number from the end of the carBtn, so carBtn1 is seen as the same as carBtn10. I tried taking the last 2 digits off which works for 2 digit numbers - but everything below 10 isnt working anymore. Im not sure what to do to get it working....
Here is my code:
Code:
// variables
var popInfo:popMc;
// load xml
var xml:XML = new XML();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("data/cities.xml"));
loader.addEventListener(Event.COMPLETE,
function(evt:Event):void {
xml = XML(evt.target.data);
//trace(xml.city[0].@weburl.toString());
var url:URLRequest = new URLRequest(xml.city[0].@weburl.toString());
}
);
// event listeners
stage.addEventListener(MouseEvent.CLICK, onClickStageRemove);
for (var j:int = 0; j < 11; j++)
{
getChildByName("carBtn" + j).addEventListener(MouseEvent.CLICK, onClickLoadData);
getChildByName("carBtn" + j).addEventListener(MouseEvent.MOUSE_OVER, onCarHover);
getChildByName("carBtn" + j).addEventListener(MouseEvent.MOUSE_OUT, onCarOut);
}
// button mode
buttonMode = true;
// functions
function onCarHover(event:MouseEvent):void
{
event.target.gotoAndPlay(11);
}
function onCarOut(event:MouseEvent):void
{
event.target.gotoAndPlay(10);
}
function onClickLoadData(event:MouseEvent):void
{
popInfo = new popMc();
popInfo.x = 100;
popInfo.y = 50;
addChild(popInfo);
popInfo.closeBtn.addEventListener(MouseEvent.CLICK , onClickRemove);
popInfo.nyopBtn.addEventListener(MouseEvent.CLICK, onClickNYOP);
//better approach would be add separate classFile to haldle some popInfo's events
//such removing on stageClick in that file u could add those functions:
var index:Number=event.target.name.slice(event.target.name.length-1);
popInfo.carsizeText.text = xml.city[index].bidlist.carsize.descendants().toXMLString();
popInfo.priceText.text = xml.city[index].bidlist.price.descendants().toXMLString();
popInfo.savingsText.text = xml.city[index].bidlist.savings.descendants().toXMLString();
popInfo.stateText.text = xml.city[index].@name.toString();
addChild(popInfo);
}
function onClickRemove(event:MouseEvent):void
{
popInfo.closeBtn.removeEventListener(MouseEvent.CLICK, onClickRemove);
popInfo.nyopBtn.removeEventListener(MouseEvent.CLICK, onClickNYOP);
removeChild(popInfo);
}
function onClickStageRemove(event:MouseEvent):void
{
if(event.eventPhase == EventPhase.AT_TARGET) {
removeChild(popInfo);
}
}
function onClickNYOP(event:MouseEvent):void
{
//navigateToURL(url, "_blank");
// navigateToURL(urlNY, "_blank"); //trying to get this variable to work
ExternalInterface.call("selectNY");
}
// set button mode here
Adding 3 Months To The Date Object (and GetFullYear Displaying Last Two Digits)
I'm currently working on a simple project displaying a date and I've got this so far:
myDate = new Date();
dd = myDate.getDate();
mm = myDate.getMonth() + 1;
yyyy = myDate.getFullYear();
textdate = (mm+"/"+dd+"/"+yyyy);
Works great. Displays proper date like 6/20/2006.
However, here's where things get interesting. Clients wants date to display 3 months into the future. Now sure, I could just use myDate.getMonth() + 4 and it'll work. Sort of. Of course, what if it's 3/31 and since there's no 6/31, that'll look kind of stupid. So what's the workaround for this? Got to be something.
Also, any idea how I can just make the year display as '06' instead of '2006'?
Integer Help
Hi! Need help on this script! How can I put the "media_ar" a integer number, without the decimals?
________________
tot_el = _root.myValue.length;
for(m=0 ; m < tot_el; m++){
valore = _root.myValue[m];
valore1 = new Number(valore);
valore2 = valore1.valueOf();
tot_ar += valore2;
media_ar = tot_ar/tot_el;
_root.media = "Média = <font color="#FFCC00">" + media_ar + "</font>";
}
_________________
Integer To Hex
Hey!
I need to convert an integer value to hex to use with the setRGB thingy. (I want a slide bar that controls the colour of a movie clip)
I know that you can use parseInt to get an integer from a hex value but how do you do the opposite?
Cheers
(feeling sick as a dog)
Integer To Hex
Hey!
I need to convert an integer value to hex to use with the setRGB thingy. (I want a slide bar that controls the colour of a movie clip)
I know that you can use parseInt to get an integer from a hex value but how do you do the opposite?
Cheers
(feeling sick as a dog)
How Do I Get A Random Integer < X?
This isn't really a Flash problem...
I need to get a random integer less than a specific number.
How would I do this...?
It's prob really simple... but I can't get my head round the problem!
Any help would be appreciated.
Thanks.
Jam
Integer Divide
Hi, If I do a division I can make the answer into an integer afterwards. But that seems kind of CPU intensive, I know they don't like floating point calculations much. So is there any way i can go easy on it and just come out with the integer in the first place? I figure Mod must do it at some point but of course it doesn't give me the answer because thats not what its for.
Failing that, is parseInt() the simplest way to go? The answer doesn't have to be too accurate.
Thanks you guys!
Integer Problem
Hi guys,
I need your help on this litle issue:
I have a script that is made to calculate the average and I get it from an example in flashkit. it's like this:
----------------------------
tot_el = _root.myValue.length;
for(m=0 ; m < tot_el; m++){
valore = _root.myValue[m];
valore1 = new Number(valore);
valore2 = valore1.valueOf();
tot_ar += valore2;
media_ar = tot_ar/tot_el;
_root.media = "Média = <font color="#FFCC00">" + media_ar + "</font>";
}
----------------------------
This works fine, but I need the integer value. I know that is made with Math.Round but I try diferent ways to implement it and I cannot do it.
Can you help me?
String Into An Integer
Hi,
Simple thing I think
I have movieclips with instance names 1,2,3 etc and need to grab their names ( this.name = this._name ) but this becomes a string.
How do you convert a string into an integer.
Thanks in advance
How Transform Var To Integer Var?
Hi,
I need make this:
var1 = 3;
var2 = 8;
var3 = var1 + var2;
its return var3 = 38 !!! Or, 3 contatened with 8.
How make var1 + var2 obtain 11 ?
Random Integer?
how do i create a random integer? and how do i set a range for it? for example a random integer between 1 and 10?
Variable And Integer
Hi, could someone please tell me what I'm doing wrong? It is not recognizing xmlArrayDate[i]
Here's my script:
i=1
xmlDate = xmlDay + xmlMonth + xmlYear;
xmlArray["xmlDate"] = xmlDate;
xmlArrayDate[i] = xmlArray["xmlDate"];
trace(xmlDate);
trace(xmlArray["xmlDate"]);
trace("Date: " + xmlArrayDate[i]);
Here's what I get for output:
1312004
1312004
Date:
String To Integer
I have the following readout from php
&id=1&name=jshpro2&score=2&max=11&level=1&connecte d=2
2
which works perfectly from flash, loads the variables and all but as strings, score+=5 for example when score=1 returns 15 when it should be 6 etc... how do i take a string and treat it as an integer?
Integer To Seconds
maybe i am going about this the wrong way, but im trying to do this quickly
theres this game that i am supposed to track how long someone was playing and display it on the screen
my current technique is using the setInterval for 1 second to add one to a counter
but how can i quickly format this to appear on the screen as 1:12?
i was looking into the date function a little, but it seems a little heavy to convert an integer into a time format
any suggestions?
thanks
|