• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Remember my Number

New Here ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

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 😃

TOPICS
ActionScript

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , May 28, 2012 May 28, 2012

I think you could use a Global Array.

var laps:Array=new Array();  //out of all functions

laps.push(value);    // inside your "HerdOn"

Each time you press a correct key is that mark would add to the array, you would have ordered marks and delete would use:

laps=new Array();

Votes

Translate

Translate
LEGEND ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

To get a key to trigger something you need to make use of a KeyboardEvent listener

stage.addEventListener(KeyboardEvent.KEY_UP, assignValue);

function checkText(event:KeyboardEvent):void {
     yourVar = currentCount;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

getting the key pressing work is not the problem, my problem is: How to get this Number.

The Number is counting up, and anytime I press the key i get the value in a new variable

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

Maybe you should show your code then, because if you do not know how to assign a new variable but can deal with the keyboard end of things, there is a disconnect with what your ability appears to be and what you say it is.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

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});

 

 

 

                              }

                    }

          }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

I think you could use a Global Array.

var laps:Array=new Array();  //out of all functions

laps.push(value);    // inside your "HerdOn"

Each time you press a correct key is that mark would add to the array, you would have ordered marks and delete would use:

laps=new Array();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

Thanks for your help^^ Works fine 😃

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

LATEST

you're welcome 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2012 May 28, 2012

Copy link to clipboard

Copied

Declare your variable outside any functions so that it is available outside of any function if you need it to be, juist like the rest of the vars you declared.  If you need to store different values at different times and want to retain them all, use an array to store them in.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines