Thursday, February 24, 2011

:void vs. Returning and Receiving Information

var globalVariable:String ="Good Morning";    
var theReturnValue:String;  


function myFunction():void { 
    globalVariable  = " Good Night "; 


myFunction();   
trace(globalVariable);   


//the change of the value changes inside that  function
//and the change is global, there is no need to return that value so the function is :void

function myFunctionThatReturnsSomething():String { 
    return (globalVariable + " Cat head");    
} 
trace(globalVariable); 

trace(myFunctionThatReturnsSomething());  



//the receiving function
//the value that you are passing is called an argument
function myOtherReturnThing(theVar):String { 
    return (globalVariable + "Round2" + theVar); 
}  

theReturnValue = myOtherReturnThing("You are Welcome ");  

trace(theReturnValue); 

///////

OUTPUT:     
 Good Night
 Good Night
 Good Night  Cat head
 Good Night Round2You are Welcome

No comments:

Post a Comment