7 Replies - 2601 Views - Last Post: 30 May 2013 - 08:05 AM

#1 canopyfive  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-May 10

Missile counter not counting...or working in general...

Posted 29 May 2013 - 07:55 AM

This is what I'm working on. I'm trying to make a countdown to keep track of missiles from 9-0, then stopping at zero.

This is what I have so far.

var counter:Number = new Number();

counter = 9;

function fl_MouseClickHandler(event:MouseEvent):void
{
	counter --;
}



Currently I have a button and the text in the same layer. The code is in another layer that's controlling another visual aspect of the game. I've tried the code in both the layer it's currently in and in the layer that houses the number text and the button.

http://www.extremest...r-in-flash-cs5/

This is the tutorial I followed to get this far, obviously I had to add something to make it run without errors. And the tutorial makes a counter up, mine is a counter down.

THANKS!

Is This A Good Question/Topic? 0
  • +

Replies To: Missile counter not counting...or working in general...

#2 eddiehm  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 76
  • Joined: 09-March 10

Re: Missile counter not counting...or working in general...

Posted 29 May 2013 - 08:18 AM

You should have some kind of event listener for the click function.

This will give you a go idea of how event listeners work.
http://www.adobe.com...ndling_as3.html
Was This Post Helpful? 1
  • +
  • -

#3 canopyfive  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-May 10

Re: Missile counter not counting...or working in general...

Posted 29 May 2013 - 12:24 PM

According to the trace, it is counting down. It won't stop at 0 and it won't display on screen. I have no idea how to make a printable countdown on the screen.
Was This Post Helpful? 0
  • +
  • -

#4 eddiehm  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 76
  • Joined: 09-March 10

Re: Missile counter not counting...or working in general...

Posted 29 May 2013 - 12:42 PM

the easiest way to display something on the screen is to add a dynamic text area to your stage, give it an instance name and then tell that dynamic text area to take the value of your counter so something like

myTextarea.text = String(counter);



then to fix your issue of counter going below 0 you will need to add an if statement to your function saying if counter is greater than 0 de-increment counter.
Was This Post Helpful? 1
  • +
  • -

#5 canopyfive  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-May 10

Re: Missile counter not counting...or working in general...

Posted 29 May 2013 - 01:50 PM

Ok. I've started a new project in which I'll ONLY focus on this counter. I am by NO means a programmer but I refuse to be defeated by this. What is in my screen is a simple button. Next to that button, I would like a simple countdown happen from 9 to 0. The countdown should happen one numeral at a time with each button press.

This is the code I currently have written. Remember, I'm not a programmer and were it not required for school, I would probably never have opened Flash/Action Script 3.0

var missileCounter:Number = new Number();

missileCounter.text = String(missileCounter);

missileCounter = 9;  

function fl_MouseClickHandler(event:MouseEvent):void  
{  
	if (missileCounter >= 0)
	{
		missileCounter --;
	}
	else
	{
		missileCounter = 0;
	}
} 



This is the last painful bit of coding I have to work out for this class and I look forward to any insight you may provide.

Thank you.
Was This Post Helpful? 0
  • +
  • -

#6 eddiehm  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 76
  • Joined: 09-March 10

Re: Missile counter not counting...or working in general...

Posted 29 May 2013 - 03:40 PM

Did you end up placing a dynamic text area on you stage? If so what instance name did you give it?
Was This Post Helpful? 0
  • +
  • -

#7 canopyfive  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-May 10

Re: Missile counter not counting...or working in general...

Posted 30 May 2013 - 06:55 AM

I placed text on the field, it's called missileCounter. The text is dynamic and embedded with, I think it's 'numerals 0...9'. I've tried it already starting with the dynamic text saying 9, and with nothing in the text field at all.
Was This Post Helpful? 0
  • +
  • -

#8 canopyfive  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-May 10

Re: Missile counter not counting...or working in general...

Posted 30 May 2013 - 08:05 AM

WE LANDED ON THE MOON! Or, at least, got the code figured out. Thanks for your help. Here's my final working code.

//Missile Counter
fireBtn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

var missile:Number = new Number();

missile = 9;

missileCounter.text = String (missile);  

function fl_MouseClickHandler(event:MouseEvent):void  
{  
	if (missile >= 1)
	{
		missile --;
		missileCounter.text = String(missile);
	}
	else
	{
		missile = 0;
	}
}



Thanks again!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1