Forum Moderators: open

Message Too Old, No Replies

Noob ActionScript Question

Define a Global variable in a function

         

Demaestro

7:14 pm on Aug 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is it possible to define a variable globally within a function and have it be accessible within other functions without passing it as a incoming argument?

function setVari(Event:EVENT):void {
var globalVariable:String = "tester";
}

function useVari(Event:EVENT):void {
trace(globalVariable);
}

Demaestro

7:21 pm on Aug 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ok it is.....

the variable has to be defined outside the function first then it's value can be changed inside one function and that change can be referenced from another function.

*******************

var globalVariable:String = "";

function setVari(Event:EVENT):void {
globalVariable = "hello world";
}

function useVari(Event:EVENT):void {
trace(globalVariable);
}

*******************

Sorry and thanks to anyone who was working this out in their head.

[edited by: Demaestro at 7:22 pm (utc) on Aug. 27, 2007]