How can I access an variable from another function?
I have a function that sets and variable:
private function create () {
var str:String = "hello";
}
private function take() {
var message:String = str;
}
How can I access an variable from another function?
I have a function that sets and variable:
private function create () {
var str:String = "hello";
}
private function take() {
var message:String = str;
}
You didn't specify whether or not the functions are in the same class or in different classes, but your main problem is variable scope. The str variable is defined inside the create function and therefore it's bound in the function's scope. You'll have to declare the variable in a larger scope. If the functions are in the same class, try something along these lines:
private var str:String;
private function create () {
str = "hello";
}
private function take() {
var message:String = str;
}