0

I tried doing

trace(classname.functionname.variablename);
//or
trace(classname.functionname().variablename);

Didn't work.. any idea, to get from the classname.as the variable, that's inside a function? Btw i tried making the function static, still didn't work Any idea?

1
  • Please provide more code. To access variables outside a class you need to make them public properties. I suspect you want to access variables inside a function body which is not doable since they won't exist until the function is invoked. Commented Apr 6, 2013 at 13:54

2 Answers 2

1

There's no way, as those variables that are defined inside a function only live as long as the function is executed, and disappear once there's a return or end of function body. In order to get whatever value you want from a function, make a class variable outside the function, assign it the value you want within that function, and address it from elsewhere.

class test {
public static var foo:Number;
function bar():void {
    // ... some code
    foo=baz*2.54;
    // ... more code
}
}
class elsewhere {
    ...
    trace(test.foo);
    ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

I thougt it was an easy way.. anyway thanks :) i will make it with the hard way :P
0

the variables created inside a function are only available in the scope of that function. if the variables are class member variables (declared public on a class);

public class x {
 public var varName:String="";
}

you will be able to access them as

classInstanceRef.varName

needless to say you will need to instantiate from that class an instance.

Unless your variable is declared static on the class

public static varName:String="";

and in that case you can access it using

className.varName;

1 Comment

What you mean with ClassInstanceRef

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.