Hey, why is it that this works:
number = 10;
button.onRelease = function(){
trace(number)
}
and this doesnt:
var number = 10
button.onRelease = function(){
trace(number)
}Hey, why is it that this works:
number = 10;
button.onRelease = function(){
trace(number)
}
and this doesnt:
var number = 10
button.onRelease = function(){
trace(number)
}button.onRelease = function () { };
var number = 10;
trace (number);
Place the variable inside the function 
var number = 10;
button.onRelease = function()
{
trace(number)
}
Works Fine | Add a semicolon @ the end of 10
strange, i figured it was always the case, i’m sorry, what I meant was:
function definer(){
var number = 10;
trace("the value is really defined");
}
definer();
button.onRelease = function()
{
trace(number); //says undefined
}
And the question is, how can I get the value of number in the onRelease function?
cause number in definer() function is local scope which means number does not exist outside definer();
Putting var before number means you declare a new variable which its scope is inside definer();
You should declare number as global scope, that should works for the case.
Okay, that makes sense, that means that when you delete “var” it becomes a global variable?
Thank you all for your answers 
I really need to get some sleep now, it’s 0:31 here now, so I’ll check this out tomorrow 
You have multiple choices here:
1. you can just declare it first in your script
//declare here, then just use it
var myVar:Number;
.....
function foo(){
myVar = ....
... = myVar;
}
function bar(){
myVar = ....
.... = myVar
}
foo();
bar();
2. you can declare it as _global. by prefixing a variable with _global. you will have access to that var anywhere in your application, provided you already assigned a value to it. Also, _global variables are ALWAYS typeless, you cannot declare var _global.myVar:Number, it will give you an error.
//note that here i don't do any declaring
function foo(){
//use it here first time - you must assign it a value
_global.myVar = ....
//note the *_global* prefix
}
function bar(){
//here just use it in any way...
.... = _global.myVar;
}
foo();
bar();
The correct way is always declaring any variables first in your script, and as much as possible avoid typeless variables – it’s very good practice. Also, using _global is not recommended, because you always must have control over your application, so you won’t use it before it’s declared (or assigned a value).
COPYRIGHT © 2012 ENVATO| TERMS OF USAGE| SUPPORT/HELP| ICONS BY TANGO + WEFUNCTION + FAMFAMFAM
Adobe®, Flash®, Flex®, Fireworks®, Photoshop®, Illustrator®, InDesign® and After Effects® are registered trademarks of Adobe Systems Incorporated.