Skip to main content
Participant
May 27, 2013
Answered

Needing help, finishing a program

  • May 27, 2013
  • 1 reply
  • 537 views

Hey,

I'm needing somehelp in ActionScript 3. I'm a beginner so just looking for help. I'm attemping to make a program that converts Standard Time to Traditional Time,.I have already set up my variables but don't know how to finish the program. So basically If the user is asked to enter a time like "14:22:10" the lblOutput.text should display "2:22 PM". I will include the code below. Thanks in advance. I have inluded where the code should be written, I just don't know how to convert it.

// This line makes the button, btnConvert wait for a mouse click
// When the button is clicked, the convertTime function is called
btnConvert.addEventListener(MouseEvent.CLICK, convertTime);

// This line makes the textinput wait for a mouse click
// When this component is clicked, the clearLabels function is called
txtinStandard.addEventListener(MouseEvent.CLICK, clearLabels);

// Declare Global Variables
var traditionalTime:String;    // traditional time

// This is the convertTime function
// e:MouseEvent is the click event experienced by the button
// void indicates that the function does not return a value
function convertTime(e:MouseEvent):void
{
// declare the variables
var standardTime:String;    // standard time entered by user
 
standardTime = txtinStandard.text;     // get standard time from user
convertToTraditional(standardTime);    // call the convertToTraditional function

// output an appropriate message in the label
lblOutput.text = standardTime + " is equivalent to " + traditionalTime;
}

// This is function convertToTraditional
// s – is the standard time
// It determines the traditional time based on the value of s
function convertToTraditional(s:String)
{
// write the code here

{
// This is the clearLabels function
// e:MouseEvent is the click event experienced by the textInput
// void indicates that the function does not return a value
function clearLabels(e:MouseEvent):void
{
     lblOutput.text = "";
  txtinStandard.text = "";
}

This topic has been closed for replies.
Correct answer Ned Murphy

What you need to do is split the String value and evaluate the portion of it that determines whether it is AM or PM.

Look into using the String.split() method to have the string broken apart at the colons ( : ).

That will produce an array as a result and you want to look at the 0 index element of that array to determine if it is an AM or PM value.  Then you want to convert it to a value < 13 if it is a PM time.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
May 27, 2013

What you need to do is split the String value and evaluate the portion of it that determines whether it is AM or PM.

Look into using the String.split() method to have the string broken apart at the colons ( : ).

That will produce an array as a result and you want to look at the 0 index element of that array to determine if it is an AM or PM value.  Then you want to convert it to a value < 13 if it is a PM time.

Participant
May 27, 2013

May you please actually show me? I'm a real noob still attempting to understand coding.

Sent from my Android

Ned Murphy
Legend
May 27, 2013

If you do what I say to do (look stuff up and try it) and then show your attempt if it does not work then there is a better chance of getting help.