Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-20-2002, 05:30 PM   #1
evworldeditor
Registered User
 
Join Date: Feb 2002
Posts: 41
Question Converting Variable String To Integer

I am now passing the variable ttldays into the Flash movie, but it appears to be converting it to a string instead of an integer.

The trace shows the value as "190"

How do I insure this value is passed as the integer 190?
Or is there a way to use actionscript to convert it back to a integer which is how is it is being passed to from ColdFusion?


Bill
evworldeditor is offline   Reply With Quote
Old 03-20-2002, 05:37 PM   #2
mad_A
The Zen of ActionScript
 
mad_A's Avatar
 
Join Date: Mar 2001
Location: Dublin, Ireland
Posts: 713
Default

Bit of a simple one...

try this -
temp="120";
temp2="140";
temp3=int ( temp );
temp4=int ( temp2 );
temp5=temp4+temp3;
trace(temp5);

so, all you need is...

int("190");
mad_A is offline   Reply With Quote
Old 03-20-2002, 06:19 PM   #3
evworldeditor
Registered User
 
Join Date: Feb 2002
Posts: 41
Default In("ttldays") Not working

Well, I tried the int("ttldays") approach and the variables debug shows the following:

Level #0:
Variable _level0.$version = "WIN 5,0,30,0"
Variable _level0.ttldys = 0
Variable _level0.time = [object #1] {}
Variable _level0.sec = 16
Variable _level0.hr = 12
Variable _level0.min = 14
Variable _level0.bph = 381060
Variable _level0.bpm = 95100
Variable _level0.bps = 105.85
Variable _level0.cdt = 5905813.6
Variable _level0.ttloil = 0
Variable _level0.bcount = 5905813.6
Variable _level0.brlcnt = 5908036.45
Variable _level0.seconds = [object #2] {}
Variable _level0.secs = 21
Variable _level0.ttldays = "190"
Variable _level0.



I tried converting the "190" using the following ActionScript:


ttldys = int("ttldays") and get a value of 0.


So, anyone else have a suggestion?

Bill


BELOW IS CF CODE FOR CREATING TTLDAYS variable
-----------------------------------------------------

<cfsetting enablecfoutputonly="yes" showdebugoutput="no">
<cfset startdate = createodbcdate("11-SEP-2001")>
<cfset ttldays = datediff('d',startdate,now())>
<cfset ttldays = val(ttldays)>
<cfoutput>&ttldays=#ttldays#&
</cfoutput>
evworldeditor is offline   Reply With Quote
Old 03-20-2002, 06:22 PM   #4
mad_A
The Zen of ActionScript
 
mad_A's Avatar
 
Join Date: Mar 2001
Location: Dublin, Ireland
Posts: 713
Default

if ttldays is a variable you want..

int(ttldays);
mad_A is offline   Reply With Quote
Old 03-20-2002, 06:55 PM   #5
evworldeditor
Registered User
 
Join Date: Feb 2002
Posts: 41
Unhappy Nope.... still not working

Sorry but int(ttldays) does NOT convert "190" to 190 either.

Any other suggestions?

Bill

Last edited by evworldeditor; 03-20-2002 at 06:59 PM.
evworldeditor is offline   Reply With Quote
Old 03-20-2002, 07:22 PM   #6
tg
done
 
Join Date: Jun 2001
Location: portland, or
Posts: 8,106
Default

flash will always import your var as a string... at least with f5. once the var is in flash you can do this:

ttldays=parseInt(ttldays);

this will convert it to an integer.
do this as soon as you var is loaded.
here is a test to check out how it works
Code:
var myInt="15";
var tot;

tot=myInt+10;
trace(tot);

tot=0;
myInt=parseInt(myInt);
tot=myInt+10;
trace(tot);

mad_a's method with int() would work if you did
ttldays=int(ttldays);
or
everywhere you want to use ttldays you instead use int(ttldays);
__________________
tg
---
what the hell was i thinking?
tg is offline   Reply With Quote
Old 03-20-2002, 08:06 PM   #7
evworldeditor
Registered User
 
Join Date: Feb 2002
Posts: 41
Cool Plan B

I tried ttldays=parseInt(ttldays); and still ended up with a string, i.e "190"...

So.... I went to Plan B...



time1 = new Date();
cur_mnth = time1.getMonth();
cur_date = time1.getDate();

if (cur_mnth == 0) {
m = 0;
}
if (cur_mnth == 1) {
m = 31;
}
if (cur_mnth == 2) {
m = 59;
}
if (cur_mnth == 3) {
m = 90;
}
if (cur_mnth == 4) {
m = 120;
}
if (cur_mnth == 5) {
m = 151;
}
if (cur_mnth == 6) {
m = 181;
}
if (cur_mnth == 7) {
m = 212;
}
if (cur_mnth ==8) {
m = 273;
}
if (cur_mnth == 9) {
m = 304;
}
if (cur_mnth == 10) {
m = 334;
}
if (cur_mnth == 11) {
m = 365;
}

ttldays = 111 + m + cur_date;


Now I have a display showing the total US Oil Imports since 9/11 that will always be current to the second, which I think is pretty cool, especially since my web site is about vehicles that use less petroleum and in some cases, no petroleum.

Check it out at http://evworld.com


Anyway, this should work through the rest of year. I hope to have MX running before 2003. I am told that it will have considerably better development capabilities than Flash 5.

Bill
evworldeditor is offline   Reply With Quote
Old 03-20-2002, 10:43 PM   #8
tg
done
 
Join Date: Jun 2001
Location: portland, or
Posts: 8,106
Default

i'ld like to see your original code, cause i think there is something fundamentally wrong... the code i gave you does convert a numeric string to a number.

if you run the test code i posted, the first trace will give you "1510" because adding a string (15) to a number (10) will concatenate the 2 together. but the second trace will give you 25 cause they are both numbers now and are added together.
__________________
tg
---
what the hell was i thinking?
tg is offline   Reply With Quote
Old 03-21-2002, 10:12 AM   #9
mad_A
The Zen of ActionScript
 
mad_A's Avatar
 
Join Date: Mar 2001
Location: Dublin, Ireland
Posts: 713
Default

Like tg said - stick up a source file and one of us will fix it.

A
mad_A is offline   Reply With Quote
Old 01-26-2006, 07:32 PM   #10
omnivore
Registered User
 
omnivore's Avatar
 
Join Date: Oct 2005
Posts: 39
Default

[I hate when I search for a solution to a problem and find threads about the same problem but the solutions was naver posted. So I'm posting a solution in case it helps someone else.]
Quote:
Originally Posted by evworldeditor
I tried ttldays=parseInt(ttldays);
ttldays = 111 + m + cur_date;
Bill
I just had the same problem (Although it's four years later and I'm using Flash 8).
If I mulitplied my var by 1 it would parse as a number instead of concatenating.
Quote:
ttldays = 111 + (m*1) + (cur_date*1)
]
Hope this helps someone.
--
Pete
omnivore is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining variable and string to form a variable name Thunderhawk ActionScript 1.0 (and below) 3 07-22-2003 10:09 PM
Help: I can build the string but not access the variable CarlBanks Simple Stuff (Newbies) 2 01-08-2002 11:40 AM
loading a string into a variable from the web marev Simple Stuff (Newbies) 2 11-09-2001 12:07 AM
Writing to a file (locally only) isleshocky77 ActionScript 1.0 (and below) 13 08-23-2001 03:43 AM


All times are GMT. The time now is 03:41 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.