Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 152
Registered: ‎08-25-2010
My Device: 9530, 9550, 9630
My Carrier: Verizon

Biggest pain adding the time.

Ok, im adding the current time to one of my apps and the problem im getting is its not updating. I have a timer set up as Timer(1000) to represent 1 second. and i have an event that happens every 1 second which is lblSeconds.text = (seconds).toString();

 

to test:

if i add in a lblSeconds.text += 1; it increments correctly. ive been messing with this for quite a while and i know i must be missing something.

 

 

 

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Biggest pain adding the time.

hey ahaz,

 

im not quite understanding the problem. however, you cant do lblSeconds.text += 1 because the lblSeconds.text is a string i beleive. your best bet would be to do something like lblSeconds.text = (Number(lblSeconds.text) + 1).toString(); and see if that works out for you. good luck!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Posts: 152
Registered: ‎08-25-2010
My Device: 9530, 9550, 9630
My Carrier: Verizon

Re: Biggest pain adding the time.

lol, that part was just as a test (forgot to add in the .toString() here in the forum Smiley Tongue ) my problem is i just cant get it to display just a simple clock... it will not update after the first time.

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Biggest pain adding the time.

hey,

 

i wrote up a code sample a little while back on the forums. here is the code:

 

TimeDisplayTest.as:

 

package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.TimerEvent;
import flash.text.TextFieldAutoSize;
import flash.utils.Timer;

import qnx.ui.text.Label;


[SWF(width="1024", height="600", backgroundColor="#E8E8E8", frameRate="30")]
public class TimeDisplayTest extends Sprite
{
private var timeLabel:Label;
private var myTimer:Timer;
private var currentDate:Date;

public function TimeDisplayTest()
{
super();

// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

displayTime();
}

private function displayTime():void
{
/*
* We set up our label, timer and date
* Label will display our time onto the screen
* Timer will be used to "listen" for each second's tick
* based on the tick we call our update function
*/

timeLabel = new Label();
myTimer = new Timer(1000);
currentDate = new Date();

myTimer.start();

timeLabel.setPosition(100,100);
timeLabel.autoSize = TextFieldAutoSize.LEFT;
timeLabel.text = formatTime(currentDate);

myTimer.addEventListener(TimerEvent.TIMER, updateTime);

addChild(timeLabel);

}

private function updateTime(e:TimerEvent):void
{
trace("tick");

/*
* Every second we update the time label with its new time
* we update the currentDate with a new date every call
*/

currentDate = new Date();

timeLabel.text = formatTime(currentDate);
}

private function formatTime(curDate:Date):String
{
var formattedTime:String;

var curHour:int = curDate.getHours();
var curMins:int = curDate.getMinutes();
var curSecs:int = curDate.getSeconds();

/*
* To get the ending AM or PM we do a simple test for the hour
*/

var curEnding:String = ((curHour > 11) ? "PM" : "AM");

/*
* I'm not a fan of military time so I like my numbers less than 13
*/

curHour = ((curHour > 12) ? curHour - 12 : curHour);

/*
* Return the formatted time including adding zeros such as "02" instead of "2"
*/

formattedTime = formatStartingZero(curHour) + ":" + formatStartingZero(curMins) + ":" + formatStartingZero(curSecs) + " " + curEnding;


return formattedTime;
}

private function formatStartingZero(num:int):String
{
/*
* Function to format and return the number based on its value of being less than 10
*/

var formattedNum:String;

formattedNum = ((num < 10) ? "0" + num.toString() : num.toString());

return formattedNum;

}
}
}

 

Maybe it can shed some light on your problem. here is the thread it was posted on:

 

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/display-time/m-p/720453/highlight...

 

good luck!

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman