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

Spacebar

New Here ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

Hi guys, here I am again!
I solved the problem with the timer and the screen appears now.

import flash.utils.Timer;

import flash.events.TimerEvent;

import flash.utils.setTimeout;

import flash.media.SoundChannel;

import flash.utils.*;

import flash.system.ImageDecodingPolicy;

import flash.display.BitmapData;

import flash.events.KeyboardEvent;

var customPanel:CustomPanel = new CustomPanel();

var timer:Timer = new Timer(30,0);

var timer2:Timer = new Timer(Math.random() * 60000,1);

var myTimer:Timer = new Timer(1200000,0);

var secCntr:int = 0;

var minCntr:int = 40;

var hourCntr:int = 23;

var currentTime:String;

var soundRequest:URLRequest = new URLRequest("sounds/Flash Clock.mp3");

var mySound:Sound = new Sound();

var soundChannel1:SoundChannel = new SoundChannel();

mySound.load(soundRequest);

soundChannel1 = mySound.play();

timer.addEventListener(TimerEvent.TIMER, setTime);

timer2.addEventListener(TimerEvent.TIMER, surprise);

stage.addEventListener(KeyboardEvent.KEY_DOWN, pressedKey);

timer.start();

timer2.start();

customPanel.visible = false;

function surprise(e:TimerEvent):void{

          trace("Surprise!");

          this.addChild(new CustomPanel());

}

function pressedKey(event:KeyboardEvent):void{

          if(event.keyCode == 32){keyDetector()}

 

}

function keyDetector():void{

          trace("The spacebar key was pressed")

}

 

 

function setTime(e:TimerEvent){

    secCntr++;

    if(secCntr == 60){

        minCntr++;

        secCntr = 0;

    }

    if(minCntr == 60){

          hourCntr++;

          minCntr = 0;

          }

          if (hourCntr >= 24){

          hourCntr = 0;}

    if(secCntr < 10){

    currentTime = String(hourCntr) + ":" + String(minCntr) + ":0" + String(secCntr);   

    }

    else{

    currentTime = String(hourCntr) + ":" + String(minCntr) + ":" + String(secCntr);

    }

    countdown_txt.text = currentTime;

}

The only is thing that the screen haves to be removes while pressing spacebar. I tried it like this:

function surprise(e:TimerEvent):void{

          trace("Surprise!");

          this.addChild(new CustomPanel());

}

function pressedKey(event:KeyboardEvent):void{

          if(event.keyCode == 32){keyDetector()}

          this.removeChild(customPanel);{

          }

}

function keyDetector():void{

          trace("The spacebar key was pressed")

}

But for some reason this doesn't work. The spacebar does react.

Have somebody a solution for this?

Greets,

Anne-Loes

TOPICS
ActionScript

Views

2.0K

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

LEGEND , Jun 22, 2012 Jun 22, 2012

To make it a child, use:  addChild(customPanel);    right after you create it in the beginning.

Then change your function below to make the customPanel visible (you already made it invisible a line before this function)

function surprise(e:TimerEvent):void {

          trace(Surprise!);

          customPanel.visible = true;

}

Votes

Translate

Translate
LEGEND ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

What about it is not working?  If it's what you show in red, it's because that should have quotes around the string.  Other than that, the removeChild call will function for any key since it is outside the conditional

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 ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

They are quotes. For some reason it doesn't show here.

I get error #1065 Variable TCMText isn't defined

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 ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

Now it's saying it's missing a rightbrace. But I don't see it

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 ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

What you should do is go into your Flash Publish Settings and select the option to  Permit Debugging.  What this often does is adds line numbers to the error message to indicate where the problemed code 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 ,
Jun 22, 2012 Jun 22, 2012

Copy link to clipboard

Copied

It was already set like that. So, it stil doesn't say it. I think it's quite strange, because

it worked before..

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 ,
Jun 22, 2012 Jun 22, 2012

Copy link to clipboard

Copied

You should show the code as you have it now.  While it might not be the problem, it is not correct to have an extra set of brackets in your function below...

function pressedKey(event:KeyboardEvent):void{

          if(event.keyCode == 32){keyDetector()}

          this.removeChild(customPanel);{    // this brace at the end does nothing

          }   // this brace does nothing

}

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 ,
Jun 22, 2012 Jun 22, 2012

Copy link to clipboard

Copied

import flash.utils.Timer;

import flash.events.TimerEvent;

import flash.utils.setTimeout;

import flash.media.SoundChannel;

import flash.utils.*;

import flash.system.ImageDecodingPolicy;

import flash.display.BitmapData;

import flash.events.KeyboardEvent;

var customPanel:CustomPanel = new CustomPanel();

var timer:Timer = new Timer(30,0);

var timer2:Timer = new Timer(Math.random() * 60000,1);

var myTimer:Timer = new Timer(1200000,0);

var secCntr:int = 0;

var minCntr:int = 40;

var hourCntr:int = 23;

var currentTime:String;

var soundRequest:URLRequest = new URLRequest("sounds/Flash Clock.mp3");

var mySound:Sound = new Sound();

var soundChannel1:SoundChannel = new SoundChannel();

mySound.load(soundRequest);

soundChannel1 = mySound.play();

timer.addEventListener(TimerEvent.TIMER, setTime);

timer2.addEventListener(TimerEvent.TIMER, surprise);

stage.addEventListener(KeyboardEvent.KEY_DOWN, pressedKey);

timer.start();

timer2.start();

customPanel.visible = false;

function surprise(e:TimerEvent):void

          {

          trace("Surprise!");

          this.addChild(new CustomPanel());

          }

function pressedKey(event:KeyboardEvent):void{

          if(event.keyCode == 32)

          {

          keyDetector()

          if(contains(customPanel))

          {

          removeChild(customPanel);

          }

  }

}

function keyDetector():void

          {

          trace("The spacebar key was pressed");

          }

function setTime(e:TimerEvent)

{

    secCntr++;

    if(secCntr == 60)

                    {

        minCntr++;

        secCntr = 0;

              }

    if(minCntr == 60)

                    {

        hourCntr++;

        minCntr = 0;

        }

    if (hourCntr >= 24)

                    {

        hourCntr = 0;}

    if(secCntr < 10)

                    {

                    currentTime = String(hourCntr) + ":" + String(minCntr) + ":0" + String(secCntr);   

              }

    else

                    {

                    currentTime = String(hourCntr) + ":" + String(minCntr) + ":" + String(secCntr);

              }

    countdown_txt.text = currentTime;

}

This is the new code. Thank you

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 ,
Jun 22, 2012 Jun 22, 2012

Copy link to clipboard

Copied

It's working now. But the spacebar doesn't react.

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 ,
Jun 22, 2012 Jun 22, 2012

Copy link to clipboard

Copied

You should format your code properly, it is very difficult to read all spread out and oddly indented as you show it.  I had to take you code and reformat it just to see what you have.  After removing any code related to things I do not have, I ran the file and the textfield displayed time counting, and when I press the spacebar I get the trace message: "The spacebar key was pressed" 

So it is working fine for what the code tells it to do.  Since customPanel was never added as a child, it is not going to be removed (you create another new instance, but that other new instance is not customPanel)

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 ,
Jun 22, 2012 Jun 22, 2012

Copy link to clipboard

Copied

Sorry for the confusing code. It's just how I learned to make it.

How can I make customPanel a child? Or isn't that possible?

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 ,
Jun 22, 2012 Jun 22, 2012

Copy link to clipboard

Copied

To make it a child, use:  addChild(customPanel);    right after you create it in the beginning.

Then change your function below to make the customPanel visible (you already made it invisible a line before this function)

function surprise(e:TimerEvent):void {

          trace(Surprise!);

          customPanel.visible = true;

}

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 ,
Jun 22, 2012 Jun 22, 2012

Copy link to clipboard

Copied

Thank you! Now it's really working!

Can I ask you one more question?

I want, if the time ends that it stays at 00:00:00 How can I do this?

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 ,
Jun 22, 2012 Jun 22, 2012

Copy link to clipboard

Copied

LATEST

In your setTime function, check for when the three time elements all equal zero and at that point stop the Timer that calls that 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