[Flashcoders] [AS in general] Question corcerning a math formula
Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] [AS in general] Question corcerning a math formula
Hi Jim, In the Number class there is are a couple of functions to help you. You want a function called toFixed(). so if you do Number(total).toFixed(2); You get the result you want :) This is pure AS3 though, Hope this helps, Sid On Jan 27, 2009, at 9:45 AM, jimmi wrote: Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] [AS in general] Question corcerning a math formula
That would be: num.toFixed(2)); HTH Cor -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of jimmi Sent: dinsdag 27 januari 2009 9:45 To: Flash Coders List Subject: [Flashcoders] [AS in general] Question corcerning a math formula Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.10.14/1917 - Release Date: 26-1-2009 18:37 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] [AS in general] Question corcerning a math formula
Ah snap, i need it for AS2, is there any alternative for that? Best regards, Jim On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning sid...@funky-monkey.nl wrote: Hi Jim, In the Number class there is are a couple of functions to help you. You want a function called toFixed(). so if you do Number(total).toFixed(2); You get the result you want :) This is pure AS3 though, Hope this helps, Sid On Jan 27, 2009, at 9:45 AM, jimmi wrote: Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] [AS in general] Question corcerning a math formula
you need to add it to a string and work out if the extra 0 is needed (maybe with the modulo (%) comparison operator), in as2, and then manually add the zero to the string when you output to your textfield do a search for as2 timers / digital clocks and you'll come across the technique a On Tue, Jan 27, 2009 at 9:05 AM, jimmi cho...@gmail.com wrote: Ah snap, i need it for AS2, is there any alternative for that? Best regards, Jim On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning sid...@funky-monkey.nl wrote: Hi Jim, In the Number class there is are a couple of functions to help you. You want a function called toFixed(). so if you do Number(total).toFixed(2); You get the result you want :) This is pure AS3 though, Hope this helps, Sid On Jan 27, 2009, at 9:45 AM, jimmi wrote: Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] [AS in general] Question corcerning a math formula
Hi Jimmi, Look at this then, To truncate Numbers in Actionscript: Three decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *1000)/1000; // Outputs 23.263 Two decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *100)/100; // Outputs 23.26 One decimal: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *10)/10; // Outputs 23.2 and if you want to do it even nicer you do it like this: function round(number:Number, precision:Number):Number { var decimalPlaces:Number = Math.pow(10, precision); trace(Math.round(decimalPlaces * number) / decimalPlaces) return Math.round(decimalPlaces * number) / decimalPlaces; } round(2.5678, 2); Hope this helps, Sid On Jan 27, 2009, at 10:05 AM, jimmi wrote: Ah snap, i need it for AS2, is there any alternative for that? Best regards, Jim On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning sid...@funky-monkey.nl wrote: Hi Jim, In the Number class there is are a couple of functions to help you. You want a function called toFixed(). so if you do Number(total).toFixed(2); You get the result you want :) This is pure AS3 though, Hope this helps, Sid On Jan 27, 2009, at 9:45 AM, jimmi wrote: Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] [AS in general] Question corcerning a math formula
Or, split the string on the last '.', look at the length of the string after the dot, add 0s until it has a length of 2... Ian On Tue, Jan 27, 2009 at 10:12 AM, allandt bik-elliott (thefieldcomic.com) alla...@gmail.com wrote: you need to add it to a string and work out if the extra 0 is needed (maybe with the modulo (%) comparison operator), in as2, and then manually add the zero to the string when you output to your textfield do a search for as2 timers / digital clocks and you'll come across the technique a On Tue, Jan 27, 2009 at 9:05 AM, jimmi cho...@gmail.com wrote: Ah snap, i need it for AS2, is there any alternative for that? Best regards, Jim On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning sid...@funky-monkey.nl wrote: Hi Jim, In the Number class there is are a couple of functions to help you. You want a function called toFixed(). so if you do Number(total).toFixed(2); You get the result you want :) This is pure AS3 though, Hope this helps, Sid On Jan 27, 2009, at 9:45 AM, jimmi wrote: Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] [AS in general] Question corcerning a math formula
would that work for the number 2:20 tho? doesn't flash remove zeros at the end of decimal values? a On Tue, Jan 27, 2009 at 10:20 AM, Sidney de Koning sid...@funky-monkey.nlwrote: Hi Jimmi, Look at this then, To truncate Numbers in Actionscript: Three decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *1000)/1000; // Outputs 23.263 Two decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *100)/100; // Outputs 23.26 One decimal: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *10)/10; // Outputs 23.2 and if you want to do it even nicer you do it like this: function round(number:Number, precision:Number):Number { var decimalPlaces:Number = Math.pow(10, precision); trace(Math.round(decimalPlaces * number) / decimalPlaces) return Math.round(decimalPlaces * number) / decimalPlaces; } round(2.5678, 2); Hope this helps, Sid On Jan 27, 2009, at 10:05 AM, jimmi wrote: Ah snap, i need it for AS2, is there any alternative for that? Best regards, Jim On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning sid...@funky-monkey.nl wrote: Hi Jim, In the Number class there is are a couple of functions to help you. You want a function called toFixed(). so if you do Number(total).toFixed(2); You get the result you want :) This is pure AS3 though, Hope this helps, Sid On Jan 27, 2009, at 9:45 AM, jimmi wrote: Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] [AS in general] Question corcerning a math formula
cheers fella a On Tue, Jan 27, 2009 at 10:39 AM, Sidney de Koning sid...@funky-monkey.nlwrote: Hi allandt, 2:20 is not a number :) its a string. i think what flash tries to do is convert it to a number but fails and convert it to a string what you could do is strip out any : or , and replace it with a . (dot) and then pass it to the round function. You can use this class for it, its AS2: http://www.funky-monkey.nl/blog/2006/10/29/replace-string-class/ Have fun with it! Sid On Jan 27, 2009, at 11:26 AM, allandt bik-elliott (thefieldcomic.com) wrote: would that work for the number 2:20 tho? doesn't flash remove zeros at the end of decimal values? a On Tue, Jan 27, 2009 at 10:20 AM, Sidney de Koning sid...@funky-monkey.nlwrote: Hi Jimmi, Look at this then, To truncate Numbers in Actionscript: Three decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *1000)/1000; // Outputs 23.263 Two decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *100)/100; // Outputs 23.26 One decimal: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *10)/10; // Outputs 23.2 and if you want to do it even nicer you do it like this: function round(number:Number, precision:Number):Number { var decimalPlaces:Number = Math.pow(10, precision); trace(Math.round(decimalPlaces * number) / decimalPlaces) return Math.round(decimalPlaces * number) / decimalPlaces; } round(2.5678, 2); Hope this helps, Sid On Jan 27, 2009, at 10:05 AM, jimmi wrote: Ah snap, i need it for AS2, is there any alternative for that? Best regards, Jim On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning sid...@funky-monkey.nl wrote: Hi Jim, In the Number class there is are a couple of functions to help you. You want a function called toFixed(). so if you do Number(total).toFixed(2); You get the result you want :) This is pure AS3 though, Hope this helps, Sid On Jan 27, 2009, at 9:45 AM, jimmi wrote: Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] [AS in general] Question corcerning a math formula
Oh Allandt i misread, sorry. Yes flash does remove the zero at the end of decimal values. But then you only want to use this function to display (in a textfield or something) and not to calcualte with it, because calculating with double zeroes is the same calucalting with a zero :) ie 4 * 2.0 == 4 *2. To fix it do this (AS3 code): function round(pValue:Number, precision:int):String { var intVal:Number = Math.floor(pValue); var finalLength : int = intVal.toString().length + 1 + precision; var baseString : String = pValue.toString().substr(0, finalLength); if(baseString.length == intVal.toString().length) { baseString += .; } while(baseString.length finalLength) { baseString += 0; } return baseString; } If there is someone on this list who would like to convert this function to AS2 to help Jimmi that would be awesome :) Cheers, Sid On Jan 27, 2009, at 11:26 AM, allandt bik-elliott (thefieldcomic.com) wrote: would that work for the number 2:20 tho? doesn't flash remove zeros at the end of decimal values? a On Tue, Jan 27, 2009 at 10:20 AM, Sidney de Koning sid...@funky-monkey.nlwrote: Hi Jimmi, Look at this then, To truncate Numbers in Actionscript: Three decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *1000)/1000; // Outputs 23.263 Two decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *100)/100; // Outputs 23.26 One decimal: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *10)/10; // Outputs 23.2 and if you want to do it even nicer you do it like this: function round(number:Number, precision:Number):Number { var decimalPlaces:Number = Math.pow(10, precision); trace(Math.round(decimalPlaces * number) / decimalPlaces) return Math.round(decimalPlaces * number) / decimalPlaces; } round(2.5678, 2); Hope this helps, Sid On Jan 27, 2009, at 10:05 AM, jimmi wrote: Ah snap, i need it for AS2, is there any alternative for that? Best regards, Jim On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning sid...@funky-monkey.nl wrote: Hi Jim, In the Number class there is are a couple of functions to help you. You want a function called toFixed(). so if you do Number(total).toFixed(2); You get the result you want :) This is pure AS3 though, Hope this helps, Sid On Jan 27, 2009, at 9:45 AM, jimmi wrote: Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] [AS in general] Question corcerning a math formula
Thanks guys, i now have some more insight into this matter. Best regards, Jim On Tue, Jan 27, 2009 at 12:01 PM, allandt bik-elliott (thefieldcomic.com) alla...@gmail.com wrote: cheers fella a On Tue, Jan 27, 2009 at 10:39 AM, Sidney de Koning sid...@funky-monkey.nlwrote: Hi allandt, 2:20 is not a number :) its a string. i think what flash tries to do is convert it to a number but fails and convert it to a string what you could do is strip out any : or , and replace it with a . (dot) and then pass it to the round function. You can use this class for it, its AS2: http://www.funky-monkey.nl/blog/2006/10/29/replace-string-class/ Have fun with it! Sid On Jan 27, 2009, at 11:26 AM, allandt bik-elliott (thefieldcomic.com) wrote: would that work for the number 2:20 tho? doesn't flash remove zeros at the end of decimal values? a On Tue, Jan 27, 2009 at 10:20 AM, Sidney de Koning sid...@funky-monkey.nlwrote: Hi Jimmi, Look at this then, To truncate Numbers in Actionscript: Three decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *1000)/1000; // Outputs 23.263 Two decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *100)/100; // Outputs 23.26 One decimal: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *10)/10; // Outputs 23.2 and if you want to do it even nicer you do it like this: function round(number:Number, precision:Number):Number { var decimalPlaces:Number = Math.pow(10, precision); trace(Math.round(decimalPlaces * number) / decimalPlaces) return Math.round(decimalPlaces * number) / decimalPlaces; } round(2.5678, 2); Hope this helps, Sid On Jan 27, 2009, at 10:05 AM, jimmi wrote: Ah snap, i need it for AS2, is there any alternative for that? Best regards, Jim On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning sid...@funky-monkey.nl wrote: Hi Jim, In the Number class there is are a couple of functions to help you. You want a function called toFixed(). so if you do Number(total).toFixed(2); You get the result you want :) This is pure AS3 though, Hope this helps, Sid On Jan 27, 2009, at 9:45 AM, jimmi wrote: Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] [AS in general] Question corcerning a math formula
If it works, it works :) Try converting it to a function so you can reuse it later. Happy coding :) Sid On Jan 27, 2009, at 12:29 PM, jimmi wrote: I now have this : total= String(Number(600) / 100 * Number(5.1)); cash = newArray; cash = total.split(.); if (cash.length == 1) { total+= .00; } else if (cash[cash.length - 1].length == 1) { total+= 0; } It's doing the job. On Tue, Jan 27, 2009 at 12:14 PM, Sidney de Koning sid...@funky-monkey.nl wrote: Oh Allandt i misread, sorry. Yes flash does remove the zero at the end of decimal values. But then you only want to use this function to display (in a textfield or something) and not to calcualte with it, because calculating with double zeroes is the same calucalting with a zero :) ie 4 * 2.0 == 4 *2. To fix it do this (AS3 code): function round(pValue:Number, precision:int):String { var intVal:Number = Math.floor(pValue); var finalLength : int = intVal.toString().length + 1 + precision; var baseString : String = pValue.toString().substr(0, finalLength); if(baseString.length == intVal.toString().length) { baseString += .; } while(baseString.length finalLength) { baseString += 0; } return baseString; } If there is someone on this list who would like to convert this function to AS2 to help Jimmi that would be awesome :) Cheers, Sid On Jan 27, 2009, at 11:26 AM, allandt bik-elliott (thefieldcomic.com) wrote: would that work for the number 2:20 tho? doesn't flash remove zeros at the end of decimal values? a On Tue, Jan 27, 2009 at 10:20 AM, Sidney de Koning sid...@funky-monkey.nlwrote: Hi Jimmi, Look at this then, To truncate Numbers in Actionscript: Three decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *1000)/1000; // Outputs 23.263 Two decimals: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *100)/100; // Outputs 23.26 One decimal: var yourNumber:Number = 23.263636453737383838383838; yourNumber = Math.round(yourNumber *10)/10; // Outputs 23.2 and if you want to do it even nicer you do it like this: function round(number:Number, precision:Number):Number { var decimalPlaces:Number = Math.pow(10, precision); trace(Math.round(decimalPlaces * number) / decimalPlaces) return Math.round(decimalPlaces * number) / decimalPlaces; } round(2.5678, 2); Hope this helps, Sid On Jan 27, 2009, at 10:05 AM, jimmi wrote: Ah snap, i need it for AS2, is there any alternative for that? Best regards, Jim On Tue, Jan 27, 2009 at 9:53 AM, Sidney de Koning sid...@funky-monkey.nl wrote: Hi Jim, In the Number class there is are a couple of functions to help you. You want a function called toFixed(). so if you do Number(total).toFixed(2); You get the result you want :) This is pure AS3 though, Hope this helps, Sid On Jan 27, 2009, at 9:45 AM, jimmi wrote: Goodmorning, i am trying to make a formula that makes for example 30.60 of 30.6. So I need it to add a 0. This is the formula I am using now. total = Number(Number(600) / 100 * Number(5.1)) I have tried all sorts of additions to the formula to try to get it to make 30.60 of 30.6. But no luck Anyone here who knows how to make the formula add a 0? Best regards, Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @ www.funky-monkey.nl Technical Writer @ www.insideria.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Sidney de Koning - be a geek, in rockstar style! Flash / AIR Developer @
RE: [Flashcoders] Garbage Collection difficulty
Thnx for the links... tried some, but still with no success... I now have the following: public class Image extends MovieClip { private var _thumbLoader:Loader; private var _largeLoader:Loader; private var _thumb:Bitmap; private var _large:Bitmap; public function loadThumb() :void { _thumbLoader = new Loader(); _thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded, false, 0, true); _thumbLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorOccured, false, 0, true); _thumbLoader.load(new URLRequest(_tu)); } private function thumbLoaded( e :Event ) :void { _thumb = Bitmap(e.currentTarget.content); _thumb.smoothing = true; addChild(_thumb); _thumbLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, thumbLoaded); _thumbLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, errorOccured); _thumbLoader = null; dispatchEvent(new Event(Image.IMG_LOADED)); } public function loadLarge() :void { _largeLoader = new Loader(); _largeLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, largeLoaded, false, 0, true); _largeLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorOccured, false, 0, true); _largeLoader.load(new URLRequest(_lu)); } private function largeLoaded( e :Event ) :void { _large = e.currentTarget.content; _large.smoothing = true; addChild(_large); _largeLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, largeLoaded); _largeLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, errorOccured); //_largeLoader.content.dispose(); _largeLoader = null; dispatchEvent(new Event(Image.IMG_LOADED)); } public function disposeLarge() :void { if (_large) { removeChild(_large); _large.bitmapData.dispose(); _large = null; } } public function dispose() :void { disposeLarge(); removeChild(_thumb); _thumb.bitmapData.dispose(); _thumb = null } } Anyone some tips? The large bitmap stays in memory... -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Glen Pike Sent: Wednesday, 21 January 2009 21:18 To: Flash Coders List Subject: Re: [Flashcoders] Garbage Collection difficulty Hi, I think if you use it locally, you still have to dispose of it: http://www.bartclaessens.com/tag/memory-management/ http://labs.bigspaceship.com/2007/02/28/flash-performance-tips-part-ii/ http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html Search for dispose in some of these - also, one of the comments in Grant's article mentions testing in the IDE vs testing in the browser gives different results for loaded images. HTH Glen Sander Schuurman wrote: That's a local variable right? Doesn't it happen automatic? I must concentrate on the _large Sprite, isn't it? -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Glen Pike Sent: Wednesday, 21 January 2009 12:20 To: Flash Coders List Subject: Re: [Flashcoders] Garbage Collection difficulty Hi, Do you have to destroy the Bitmap you create in the largeLoaded function??? Glen Sander Schuurman wrote: Hi cool list, I'm struggling with my Image class. It's supposed to load and unload different sized images dynamicly; but I can't seem to get it to work properly. The loading works fine, but the unloading not for the full 100%. It visually unloads the image, but it remains in the memory. I have tried several different things; I'm a bit stuck now. Here is a stripped class: public class Image extends MovieClip { ... private var _largeLoader:Loader; private var _large:Sprite; ... public function Image( thumbUrl :String, normalUrl :String, largeUrl :String ) { _tu = thumbUrl; _nu = normalUrl; _lu = largeUrl; } ... public function loadLarge() :void { _largeLoader = new Loader(); _largeLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, largeLoaded, false, 0, true);
[Flashcoders] instancing my own components (still new to AS3)
Hi list... What exactly is the AS3 equivalent of making a simple component, creating a component definition, and attachMovie with the {} holding the params? I can't get this to work: package { import flash.display.MovieClip; import flash.text.*; public class MyButton extends MovieClip{ public var buttonLabel:String; public function MyButton (buttonLabel:String){ this.buttonLabel = buttonLabel; btnLabel.text = buttonLabel; } } } The component definition has one parameter: Var: buttonLabel, default value:Go, type:list I'm trying to instance a movie clip that contains instances of this variable. I get various compiler errors when that parent clip is on the stage. Argument Error 1063 (Argument Count Mismatch) expected 1, got 0, when instancing a movieclip that contains these components. But in parent movie clip, I am setting the params on the stage. Thanks, - Michael M. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] inserting an MC in a TextField (and speaking to it)
So I want to do a dynamic drop cap in a text field, and I know I can do this: var tString:String = img src='com.myclasses.DropCap' style='padding:0px;margin:0px'/ Cras sit amet arcu. Vestibulum condimentum risus ac metus. Vivamus in purus id leo molestie convallis. Donec ipsum. Sed vulputate urna sed erat. Vivamus tellus elit, accumsan non, sodales quis, semper sit amet, risus. Phasellus eu augue sit amet libero facilisis pretium. Nullam urna massa, adipiscing a, lobortis nec, vehicula ut, lorem. Ut imperdiet elit nec sapien. In hac habitasse platea dictumst. Quisque congue. In a velit. Praesent interdum purus a diam. Ut turpis justo, viverra quis, dignissim at, aliquam sit amet, turpis. Morbi non lacus at lacus commodo dignissim. Nulla in quam eu massa scelerisque elementum. Curabitur mollis egestas leo. Morbi pulvinar nisl sed lacus. Quisque eu orci.; myTextField.htmlText = tString; In which DropCap is an MC in the library with a Class of com.myclasses.DropCap. What I cant figure out is, how (if its even possible) can I speak to that Movieclip once its in the Textfield? I want to set the character that appears in the DropCap, so do something like DropCap.txt.text = Z, but if I try that it throws an error. Does anyone know of a way to make this work? tia, .matt ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
[Flashcoders] Error Instantiating Object
Hello, I am new to Action Script 3. I am used to Java, Perl, Python. I am receiving the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at Slide$iinit() at PondoShow$iinit() All I have a PondShow class that extends Sprite. then I have a Slide class. I am trying to instantiate an array for Slide objects. import flash.display.Sprite; import flash.events.*; import flash.text.*; import flash.net.URLRequest; import flash.utils.*; public class PondoShow extends Sprite { private var slides:Array; private var slideCounter:int; private var myTimer:Timer; public function PondoShow() { myTimer = new Timer(3000); slides = new Array(4); slides[0] = new Slide(This is a test, this is only a test, img/food_array.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slides[1] = new Slide(This is a test, this is only a test, img/food_array2.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slides[2] = new Slide(This is a test, this is only a test, img/food_array3.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slides[3] = new Slide(This is a test, this is only a test, img/get_it_to_go_logo.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slideCounter = 0; trace(before adding slides); while(true) { if (slides[slideCounter].imgload) { addChild(slides[slideCounter].loader.content); break; } } Error occurs when instantiating the first Slide object. It also fails when I do not use an array and all I do is try to create a single object. My slide class has a constructor: public function Slide(primaryText:String, secondaryText:String, imagePathString:String, slideLinkText:String, slideLink:String, primaryTextX:int, primaryTextY:int, secondaryTextX:int, secondaryTextY:int, linkX:int, linkY:int) { Thanks for any help. I am new to AS 3. Kevin ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Error Instantiating Object
Hmmm... what's the rest of the Slide constructor? It sounds like maybe that's where the error is... Also, if you try running your Flash file in debug mode (Hit Ctrl-Shift-Enter), the debugger will take control at the moment when you're trying to access a null object, which usually helps you figure out what's causing these kinds of problems. --T On Tue, Jan 27, 2009 at 4:40 PM, K-Dawg kdaw...@gmail.com wrote: Hello, I am new to Action Script 3. I am used to Java, Perl, Python. I am receiving the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at Slide$iinit() at PondoShow$iinit() All I have a PondShow class that extends Sprite. then I have a Slide class. I am trying to instantiate an array for Slide objects. import flash.display.Sprite; import flash.events.*; import flash.text.*; import flash.net.URLRequest; import flash.utils.*; public class PondoShow extends Sprite { private var slides:Array; private var slideCounter:int; private var myTimer:Timer; public function PondoShow() { myTimer = new Timer(3000); slides = new Array(4); slides[0] = new Slide(This is a test, this is only a test, img/food_array.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slides[1] = new Slide(This is a test, this is only a test, img/food_array2.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slides[2] = new Slide(This is a test, this is only a test, img/food_array3.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slides[3] = new Slide(This is a test, this is only a test, img/get_it_to_go_logo.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slideCounter = 0; trace(before adding slides); while(true) { if (slides[slideCounter].imgload) { addChild(slides[slideCounter].loader.content); break; } } Error occurs when instantiating the first Slide object. It also fails when I do not use an array and all I do is try to create a single object. My slide class has a constructor: public function Slide(primaryText:String, secondaryText:String, imagePathString:String, slideLinkText:String, slideLink:String, primaryTextX:int, primaryTextY:int, secondaryTextX:int, secondaryTextY:int, linkX:int, linkY:int) { Thanks for any help. I am new to AS 3. Kevin ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Error Instantiating Object
Something in your Slide.iinit() function does not exist at the time it is running. On Tue, Jan 27, 2009 at 7:40 PM, K-Dawg kdaw...@gmail.com wrote: Hello, I am new to Action Script 3. I am used to Java, Perl, Python. I am receiving the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at Slide$iinit() at PondoShow$iinit() All I have a PondShow class that extends Sprite. then I have a Slide class. I am trying to instantiate an array for Slide objects. import flash.display.Sprite; import flash.events.*; import flash.text.*; import flash.net.URLRequest; import flash.utils.*; public class PondoShow extends Sprite { private var slides:Array; private var slideCounter:int; private var myTimer:Timer; public function PondoShow() { myTimer = new Timer(3000); slides = new Array(4); slides[0] = new Slide(This is a test, this is only a test, img/food_array.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slides[1] = new Slide(This is a test, this is only a test, img/food_array2.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slides[2] = new Slide(This is a test, this is only a test, img/food_array3.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slides[3] = new Slide(This is a test, this is only a test, img/get_it_to_go_logo.jpg, Click here to find out more, more.html, 100, 100, 50, 50, 200, 200); slideCounter = 0; trace(before adding slides); while(true) { if (slides[slideCounter].imgload) { addChild(slides[slideCounter].loader.content); break; } } Error occurs when instantiating the first Slide object. It also fails when I do not use an array and all I do is try to create a single object. My slide class has a constructor: public function Slide(primaryText:String, secondaryText:String, imagePathString:String, slideLinkText:String, slideLink:String, primaryTextX:int, primaryTextY:int, secondaryTextX:int, secondaryTextY:int, linkX:int, linkY:int) { Thanks for any help. I am new to AS 3. Kevin ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders -- --Joel Stransky stranskydesign.com ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Error Instantiating Object
I am an idiot! The debug mode did just what I needed! I was trying to add an event listener on a loader the line before doing the loader = new Loader(). Once solved that, now it is running (not correctly but that is another issue!). Thanks for responding so quickly and being so helpful. You never know when you get to a newsgroup whether people are good like the python newsgroup or awful like the comp.lang.javascript newsgroup. Thanks very much. I am sure you will hear more from me! Kevin ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] inserting an MC in a TextField (and speaking to it)
Matt, I s'pose I focused too much on the second part of your question in my previous message. So anyway, if this src='com.myclasses.DropCap' actually works then more power to ya! If not: ActionScript 3.0 Language and Components Reference: src: Specifies the URL to an image or SWF file, or the linkage identifier for a movie clip symbol in the library. So, if you have a movieclip in your library with a linkage identifier of 'DropCap' (associated with a class 'com.myclasses.DropCap') you would use: var tString:String = img src='DropCap' id=DC0 style='padding:0px;margin:0px'/Lorem ipsom yadda yadda...; myTextField.htmlText = tString; myTextField.DC0.txt.text = Z; Regards, -Keith http://keithreinfeld.home.comcast.net ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders