Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

TLF Text

Guest
Aug 23, 2010 Aug 23, 2010
I'm new at creating ActionScripts in Flash - and especially new with using Flash CS5 and ActionScript 3. The last time I touched Flash was CS3, and only dealt with animation-related scripts.
I have a project where I need to create a simple calculation of user-input information. I was able to figure out the script for that but there are still a couple of gaps I'm working on and I'm getting close to being frustrated. I'm sure these problems are very basic for a Flash programmer, but I'm not that. 😞
1. My TLF input text does not keep the font style I selected in the properties section. It keeps saying, "Embed the Font Style" and I thought I did this besides, I don't see the error anymore - but my output still defaults to a Times New Roman font instead of the Myriad Pro that I selected.
2. I'd like to format the input text numbers as amounts - with only two decimal places and a dollar sign, how do I do this?
I'd appreciate any help!
Thanks in advance!
TOPICS
ActionScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 23, 2010 Aug 23, 2010

1.  use classic text.

2:  you can use formatF() below to convert your textfield's text property to the format you want:

function formatF(s:String):String{

var n:Number=Number(s);

n = Math.round(n*100)/100;

var s1:String = n.toString();

var a:Array = s1.split(".");

while(a[1].length<2){

a[1] = a[1]+"0";

}

return "$"+a[0]+"."+a[1];

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 24, 2010 Aug 24, 2010

1. I actually figured this out - I had to embed the font in every instance and it finally worked.

2. Sorry, I don't understand where I'm supposed to add this function. If you can post an example, that would be great - maybe it's just a matter of me not understanding which parts need to be substituted.

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2010 Aug 24, 2010

copy and paste the code for that function anywhere that executes before calling it.  you can call it like:


yourTF.text = formatF(yourTF.text);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 24, 2010 Aug 24, 2010

It keeps giving me this output error: TypeError: Error #1010: A term is undefined and has no properties. at Calc_fla::MainTimeline/formatF()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2010 Aug 24, 2010

use:


function formatF(s:String):String{

var n:Number=Number(s);

n = Math.round(n*100)/100;

var s1:String = n.toString();

if(s1.indexOf(".")==-1){

return s1+".00";

}

var a:Array = s1.split(".");

while(a[1].length<2){

a[1] = a[1]+"0";

}

return "$"+a[0]+"."+a[1];

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 24, 2010 Aug 24, 2010

Yay! No more errors!

The decimal point and decimal places work but I don't see commas or the dollar sign.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2010 Aug 24, 2010

you'll need to format the commas.  here's the dollar sign:

kglad wrote:

use:


function formatF(s:String):String{

var n:Number=Number(s);

n = Math.round(n*100)/100;

var s1:String = n.toString();

if(s1.indexOf(".")==-1){

return "$"+s1+".00";

}

var a:Array = s1.split(".");

while(a[1].length<2){

a[1] = a[1]+"0";

}

return "$"+a[0]+"."+a[1];

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2010 Aug 25, 2010

Okay, the dollar sign works now and I figured out the comma! So happy!

But there seems to be a problem, it works great in my local machine but when i upload it to our website, all the formatting drops! No decimal point, no comma, no $.

[as]

function formatF(s:String):String
{
var n:Number=Number(s);
n = Math.round(n*100)/100;
var s1:String = n.toString();
if(s1.indexOf(".")==-1)
var rgx:RegExp = /(\d+)(\d{3})/;
    while (rgx.test(s1)) {
    s1 = s1.replace(rgx, "$1" + "," + "$2");
}
{
return "$"+s1+".00";
}
var a:Array = s1.split(".");
while(a[1].length<2){
a[1] = a[1]+"0";
}
return "$"+a[0]+"."+a[1];
}

[as]

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 25, 2010 Aug 25, 2010

there's nothing in formatF() that would make any difference when executed in an online vs local swf.

on the other hand, there are quite a few things that do change when executed in an online vs local swf.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2010 Aug 25, 2010
LATEST

That's what I thought... Anyway, I made different computations and I've narrowed the instance when the uploaded version drops the currency formatting - it only happens when I have an input text that has a decimal point in it. It works great in the local version but not the uploaded version. The uploaded version works fine as long as the numbers I use are whole numbers.   

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines