PDA

View Full Version : Why is this not working...?


Minipic
10-19-2011, 11:21 PM
I am just doing a simple number generator from a button. Named my button btn1 and the box textDisplay. All I want to do is when I click on my button for the number to show up in the box, in this case the number is just one. The box has also been made into a dynamic.

btn1.onRelease = function(){
textDisplay = +1;
}

You would think that would work, very simple... but it doesnt.

xdeath
10-19-2011, 11:31 PM
ok so if the button is called btn1 and the textfield the number is displayed in is called textDisplay, then try this:

// as2
var num:Number = 1;
btn1.onRelease = function(){
// num+=1; this is how to make the number go higher
// will work without the string function in most cases
textDisplay.text = String(num);
}

//as3
var num:Number = 1;
btn1.addEventListener(MouseEvent.MOUSE_DOWN,presse d);
function pressed(evt:MouseEvent){
// num+=1; this is how to make the number go higher
// you need the string function for this to work
textDisplay.text = String(num);
}


hopefully this has helped.

Minipic
10-19-2011, 11:33 PM
That has helped. I actually got mine to work now too lol. Only thing is I want to click on the button again and for it to add the integers. Know how to do that.

Like if i were to click on the button again it would say 2 because it added the 1 and 1 together.

FusionFactor
10-20-2011, 07:20 PM
ActionScript will automatically convert variable names into numbers. You can add two variables together by writing:


var num1:Number = 1;
var num2:Number = 2;

trace(num1 + num2);

xdeath
10-21-2011, 01:13 AM
That has helped. I actually got mine to work now too lol. Only thing is I want to click on the button again and for it to add the integers. Know how to do that.

Like if i were to click on the button again it would say 2 because it added the 1 and 1 together.
you should read the comments in my code. as i showed you how to increase the number already. i just commented that part out.

so you take out the comments and the writing i added at the end and you'll have that part done as well.

;) glad to here my post helped you.