Copy link to clipboard
Copied
Hey everyone, im still trying to understand how exactly i supposed to use flash vars.
so bear with me, i will try my best to explain the situation.
i have a custom class i made, where it stores vars inside:
package {
public class PHPClass extends EventDispatcher {
var stats = {HP:Number, MP: Number, Nickname:String};
public function PHPClass() {
//constructor code
}
}
}
now, to use this class, for some reason, i need to create it,
so here i am at frame number 1 at my code, i do
var PHP:PHPClass = new PHPClass;
now what this allows me to do, when i write "PHP" then adding a dot (.) after that, i see the hint box what vars should i be using.
so far so good?
now, when i switch to frame 2 at my flash game, i no longer can use the hint box anymore but the command is still usable,
so like PHP.stats.HP = 20.0; still working, but i have no hint box to use anymore.
is there any way i can declare a var inside my 2nd frame so it will be using the same var i created at 1st frame?
because something like:
(on 2nd frame)
var NewPHP:PHP; does not work..
i hope i explained the situation clear enough, if no please tell me ill provide an example code.
You can put code in frames but you really shouldn't. There are tons of reasons why you shouldn't and what you are experiencing is just one of them. The correct way: Write your classes inside .as files (class files) and link your project to them so you can use them anywhere in your project.
Anyway .... Create a layer without keyframes that spans the entire timeline, all code (and classes) you put there will be accessible in the other layer's keyframes.
Copy link to clipboard
Copied
You can put code in frames but you really shouldn't. There are tons of reasons why you shouldn't and what you are experiencing is just one of them. The correct way: Write your classes inside .as files (class files) and link your project to them so you can use them anywhere in your project.
Anyway .... Create a layer without keyframes that spans the entire timeline, all code (and classes) you put there will be accessible in the other layer's keyframes.
Copy link to clipboard
Copied
yeah i know, but here is another problem with this that i need an answer also.
how can i access this class from any frame of my code?
each frame, i have to "Create" the class once again using
var PHP:PHPClass = new PHPClass;
but that messes up my saved variables i made inside that class.
any other way to access the class from multiply frames?
Copy link to clipboard
Copied
I told you, create a layer WITHOUT keyframes (must be a layer as long as the entire timeline) and put your code in there, now you can access that code from anywhere in THAT timeline.
Copy link to clipboard
Copied
yes i understood that. i thought there was another way. but thanks.
Copy link to clipboard
Copied
I also told you the other way: create external classes.