A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Urgent help required for adding current time to a time duration showing a future time

  1. #1
    Willemuk
    Join Date
    Feb 2010
    Posts
    3

    Lightbulb Urgent help required for adding current time to a time duration showing a future time

    I am doing event driven programming for a subject at college and normally use vb.net but have chosen to try my hand at Flash script instead. I have created a parking meter using drag and drop functions, etc. and it works great but I have hit a snag and am trying to write a script that adds the current time to a chosen duration time that then shows a predicted time in a text box. I have spent weeks trying to sort the script out but just cannot figure it out. I can get it to show the two times together side by side in the text box but cannot add them together. Here is the script I have written the script in red shows the current time format and the script in blue shows the additional time that needs to be added to it to give the future time prediction. the script in green is roughly what I need it to do but obviously it is not the correct way. Any help would be very much appreciated. Thank you.

    onSelfEvent (load) {
    centerX=_width/2;
    centerY=_height/2;
    }
    on (press){
    //calculate angle
    angle = (45);
    knob._rotation += angle;
    trace(_rotation);
    var digital_time: Object = new Date();
    //To get the seconds and minutes in a '00' format, we need the length of that number.
    //If it is '1' then it must be a single digt number
    var new_second: Number = digital_time.getSeconds();
    var new_second1: String = new_second.toString();
    trace("|"+(new_second1));
    if(new_second1.length == 1){
    var seconds_t: String = "0"+ new_second1;
    } else {
    var seconds_t: String = new_second1;
    }
    var new_minute: Number = digital_time.getMinutes();
    var new_minute1: String = new_minute.toString();
    if(new_minute1.length == 1){
    var minutes_t: String = "0"+ new_minute1;
    } else {
    var minutes_t: String = new_minute1;
    }
    ;
    var new_hour: Number = digital_time.getHours()
    var new_time: String = new_hour+":"+minutes_t+":"+seconds_t;

    //show time added from each click
    if (knob._rotation == 45) {
    var new_h: Number = 0;
    var hr_t: String = "0"+ new_h;
    var new_min: Number = 1;
    var min_t: String = "0"+ new_min;
    var new_sec: Number = 0;
    var sec_t: String = "0"+ new_sec;
    var new_t1: String = hr_t+":"+min_t+":"+sec_t;
    Duration.text = new_t1;

    Price.text = "0.70";
    Remaining.text = "0.70";
    // Expires.text = Math(new_time + new_t1);
    }
    else if (knob._rotation == 90) {
    var new_h: Number = 0;
    var hr_t: String = "0"+ new_h;
    var new_min1: Number = 2;
    var min_t1: String = "0"+ new_min1;
    var new_sec: Number = 0;
    var sec_t: String = "0"+ new_sec;
    var new_t2: String = hr_t+":"+min_t1+":"+sec_t;
    Duration.text = new_t2;
    Price.text = "1.40";
    Remaining.text = "1.40";
    }
    else if (knob._rotation == 135) {
    var new_h: Number = 0;
    var hr_t: String = "0"+ new_h;
    var new_min2: Number = 3;
    var min_t2: String = "0"+ new_min2;
    var new_sec: Number = 0;
    var sec_t: String = "0"+ new_sec;
    var new_t3: String = hr_t+":"+min_t2+":"+sec_t;
    Duration.text = new_t3;
    Price.text = "2.10";
    Remaining.text = "2.10";
    }
    else if (knob._rotation == 180) {
    var new_h: Number = 0;
    var hr_t: String = "0"+ new_h;
    var new_min3: Number = 4;
    var min_t3: String = "0"+ new_min3;
    var new_sec: Number = 0;
    var sec_t: String = "0"+ new_sec;
    var new_t4: String = hr_t+":"+min_t3+":"+sec_t;
    Duration.text = new_t4;
    Price.text = "2.80";
    Remaining.text = "2.80";
    //knob._rotation = 0;
    }
    else if (knob._rotation == -135) {
    var new_h: Number = 0;
    var hr_t: String = "0"+ new_h;
    var new_min4: Number = 5;
    var min_t4: String = "0"+ new_min4;
    var new_sec: Number = 0;
    var sec_t: String = "0"+ new_sec;
    var new_t5: String = hr_t+":"+min_t4+":"+sec_t;
    Duration.text = new_t5;
    Price.text = "3.50";
    Remaining.text = "3.50";
    }
    else if (knob._rotation == -90) {
    var new_h: Number = 0;
    var hr_t: String = "0"+ new_h;
    var new_min5: Number = 6;
    var min_t5: String = "0"+ new_min5;
    var new_sec: Number = 0;
    var sec_t: String = "0"+ new_sec;
    var new_t6: String = hr_t+":"+min_t5+":"+sec_t;
    Duration.text = new_t6;
    Price.text = "4.20";
    Remaining.text = "4.20";
    }
    else if (knob._rotation == -45) {
    var new_h: Number = 0;
    var hr_t: String = "0"+ new_h;
    var new_min6: Number = 7;
    var min_t6: String = "0"+ new_min6;
    var new_sec: Number = 0;
    var sec_t: String = "0"+ new_sec;
    var new_t7: String = hr_t+":"+min_t6+":"+sec_t;
    Duration.text = new_t7;
    Price.text = "4.90";
    Remaining.text = "4.90";
    }
    else if (knob._rotation == 0) {
    Duration.text = "00:00:00";
    Price.text = "0.00";
    Remaining.text = "0.00";
    Expires.text = "00:00:00";
    }
    }
    on (release){
    click_x.gotoAndPlay(1);
    stopDrag();
    }

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813

    Well..

    First, if you plan on posting code, you should place it within either "[ PHP ] & [/ PHP ]" (note without the spaces) braces so you reduce the annoying scrolling, help with formatting and color coding which makes the code much easier to read.

    Secondly, I did read through most of your code, but it looks like you are trying to add time to a string, instead of adding it to the date object. Best choice would be to convert the date/time stamp into a true Date format, then using getTime(), add or subtract to get the desired math. Once you get the new information, then you can convert to string to maintain your two digit formatting.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center