Hey guys,
Maybe simple question but I dont find any solution right now...
I have a number counting up from 0 to 86400.
When I'm pressing a key, I want to get the CURRENT number to be saved into a new variable. This new variable has to be static (not counting).
But the Basic counting have to go on.
Hope you know what I mean and can help me =)
Ok here is my code:
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.utils.Timer;
import com.greensock.*;
import com.greensock.easing.*;
////////////////////////DAYTIME IN SECONDS
var today:Date;
var current:Date;
var time:Date;
var millisecond:int;
var second:int;
var minute:int;
var hour:int;
var day:int;
var month:int;
var secs:int;
var timer:Timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
function timerHandler(event:TimerEvent):void
{
time = new Date();
millisecond = time.getMilliseconds();
second = time.getSeconds();
minute = time.getMinutes();
hour = time.getHours();
day = time.getDate();
month = time.getMonth();
today = new Date(2012,5,28,0,0,0,0);
current = new Date(2012,month+1,day,hour,minute,second,millisecond);
secs = (current.getTime() - today.getTime())/1000;
trace(secs); //"secs" is the current daytime in seconds
stage.addEventListener(KeyboardEvent.KEY_DOWN, HerdOn);
////////////////////////EVENT
function HerdOn(event:KeyboardEvent):void
{
var xPos:Number = -411.10;
var yPos:Number = -8.05;
var pixWidth:int = 0;
if (event.charCode == 49) // key "1"
{
trace ("start");
//So, when I have pressed the key "1", here I want to have a new Variable which gives me a static number
//of "secs"
currentCount
trace ("One is pressed");
bob_mc.x = xPos;
bob_mc.y = yPos;
bob_mc.width = pixWidth;
TweenLite.to(bob_mc, 15.25, {x:xPos, y:yPos, scaleX:2, ease:Linear.easeNone});
}
if (event.charCode == 50) //key "2"
{
trace("stop");
TweenLite.to(bob_mc, 15.25, {paused:true, ease:Linear.easeNone});
}
}
}
I answered your question yeaterday regarding how to get the seconds (you should mark that posting as answered). You should clean up that code so that it is not doing things that you don't need done - which appears to be most of the date functions you run.
Also, you should never nest function within other functions. So you should separate the HerdOn function from being inside the timeHandler function.
If you want another variable, then outside any function declare a new variable, and then assign the secs value to it inside your keyboard handler function.
Ok I understand, maybe this is my big problem, so
How do I call a function or a variable in another function, even the variable is local. I thought it only works with global variables.
For me it's a bit cunfusing, why I put function into function.
Now, when I seperate the function, where I calculate the daytime in seconds, I have to call it again when I press my key, right?
How? (sorry for my inexperience xD)
North America
Europe, Middle East and Africa
Asia Pacific