Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 06-07-2010, 11:58 AM   #1 (permalink)
Wise Old Owl
 
Cool Buddy's Avatar
 
Join Date: Mar 2006
Location: Milky way
Posts: 1,487
Default Calculator in Flash (action Script 2.0)


I am making a calculator in flash. I am able to design the basic interface & all the basic functions. But now i figured out that if I have say "2.1" displayed and I press the "." button, it becomes "2.1.". how to prevent this, Can anyone help?

Now, i figured out there are multiple ways in which a calculator can be made in flash. So i am giving an idea of how the numbers are displayed in my program

first I check if a calculation is to be performed
if yes
  • I first check if dot is displayed, if yes the number gets added as a string to the number already displayed
  • then I check if the number displayed is 0, if yes then the number pressed is displayed
  • if both of the above are false, the number is added as a string to the number already displayed.
if a calculation is to be performed
  • then the number pressed is displayed
Quote:
function putnum(i) {
if (disp_num.length == 10 && calc == 0) { //checks the length, 10 digit calculator
}
else {
if (calc == 0) { //calc==0 means no calculation is to be performed
if (disp_num == "0.") { //if dot (.) button has been pressed
disp_num += ""+i;
} else if (disp_num == 0) { //if 0 is displayed
disp_num = i;
} else { //in all other cases, i.e. if 1, 12 or any other number is displayed
disp_num += "" + i;
}
}
else //if calculation is to be performed, i.e. say last button pressed is +
{
disp_num = i;
calc1 = calc;
calc = 0;
}
}
}
I figured out I can use indexOf function to find if the box already contains a dot (.), but I am not able to use the function properly, please help. It is returning undefined if the box contains a single digit number, in any other case, it is working fine
__________________
Digital Sheets Technology Blog
AMD Phenom II X4 840, 4 GB RAM, MSI HD5670, Corsair CX400 PSU :)
Nokia 5230 :(
Canon IXUS 115 HS :)
Cool Buddy is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Flashing k550i to w610i !! a_k_s_h_a_y Mobiles and Tablets 822 13-10-2010 08:25 AM
Need small help with Flash CS4 and Action Script shashank_re Programming 0 15-03-2010 06:58 AM
Due Kernel I/O error, system refuses to boot randomly gary4gar Open Source 33 04-05-2008 10:22 AM
Filters_Brush_actions_etc etc for Photoshop Krishnan Tutorials 11 27-10-2005 06:04 PM
Couldn't install OfficeXP lahratla Software Q&A 6 05-08-2005 06:44 PM

 
Latest Threads
- by Charan
- by Charan
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 03:20 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2