-
Retreivining Class Values in Main Timeline
Hello,
The code works, I'm jsut unable to read the Class variable "myString" on the main timeline.
I thought I could pass the "myString" value from the Class to the Main Timeline?
I created a variable in an external Class .as file.
See coding below.
//------- Code on main timeline .Fla
var testClass:MyClass = new MyClass(myString);
var myString:String;
var vString = myString;
trace("from main timeline=== " +vString);
//-------- Code in the .as File
package {
public class MyClass{
public function MyClass(myString){
//do something
var myString:String = "traced from class === ";
trace(myString);
}
}
}
//-------- Output When Ran (In trace window)
traced from class === //the class value is recognized.
from mail timeline=== null //However, the maintimeline is null
Any help would be appreciated
-
Please use [code] tags to post code.
You need to make the myString variable in MyClass public as opposed to a local variable in the constructor. Then, you need to actually access it. This is not a "Class variable", that term isn't really standard. If you wanted it to be attached to the class itself, you want a static variable. But you probably want it on each instance of the class, which is how it usually works.
Main timeline code
Code:
var testInstance:MyClass = new MyClass();
trace("from main timeline=== "+testInstance.myString);
MyClass.as:
Code:
package {
public class MyClass{
public var myString:String;
public function MyClass(){
myString = "someString";
trace("traced from class=== "+myString);
}
}
}
-
why thank you - 5 ton of flax!
-
getting back into actionscript after a 4 year hiatus, any good actionscript 3 books you can recommend or programming books for that matter?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|