jt-developer
07-14-2008, 09:41 AM
I've been doing AS2 for years now and my code has always been proceedural rather than OOP, so going from AS2 to OOP AS3 is a massive leap for me. I'm getting my head around using classes, and having separate AS files for each object, including the main class but I still have some problems with some of the more basic attributes that were so useful in AS2 and seem to be a lot more complex in AS3. Could anybody explain these to me....
1.) Say I wanted an object (MovieClip) on the stage to get a vlaue from the main timeline. In AS2 I used to set a variable _root.n = 10; Then from within the MovieClip (which I'll call 'mov1') I could call "trace _root.n" and this would give me the value. I could also add something to that _root variable from either inside mov1 itself (i.e. _root.n+=10) or from the main timeline using some variable in mov1 (i.e. n+= _root.mov1.p). This was the perfect way to share and pass variables. IN AS3 however the rules have changed and I find myself completely lost. For example I have created a root class with a variable n, created a new MovieClip 'mov1' with an attached .as file with a class structure for that Mc and want to access and change the root class's n variable. How would I go about doing that?
2.) I want to create 5 instances of a movieclip, and call them mov1->mov5. In AS2 I simply did a for loop...
for (i=0;i<=5;i++){
_root.attachMovieClip("movtemplate","mov"+i,i++);
}
..Using a similar technique I could then pass details to each of these Mcs at a later date, for example...
for (i=0;i<=5;i++){
_root[mov"+i].n = 10;
}
...with AS3 this sort of thing seems incredibly difficult. I read that you can attach a name variable to each MovieClip that you add to the stage but I dont know whether that is the right way to do it, or how to then send values to a particular MovieClip.
I understand why AS3 can be seen as much easier and better to use, but some things just seem so much more complicated in AS3 than AS2. For example the project I am working on at the moment would take 45 minutes to make in AS2. So far it has taken me 5 days in AS3.
Any help really appreciated.
1.) Say I wanted an object (MovieClip) on the stage to get a vlaue from the main timeline. In AS2 I used to set a variable _root.n = 10; Then from within the MovieClip (which I'll call 'mov1') I could call "trace _root.n" and this would give me the value. I could also add something to that _root variable from either inside mov1 itself (i.e. _root.n+=10) or from the main timeline using some variable in mov1 (i.e. n+= _root.mov1.p). This was the perfect way to share and pass variables. IN AS3 however the rules have changed and I find myself completely lost. For example I have created a root class with a variable n, created a new MovieClip 'mov1' with an attached .as file with a class structure for that Mc and want to access and change the root class's n variable. How would I go about doing that?
2.) I want to create 5 instances of a movieclip, and call them mov1->mov5. In AS2 I simply did a for loop...
for (i=0;i<=5;i++){
_root.attachMovieClip("movtemplate","mov"+i,i++);
}
..Using a similar technique I could then pass details to each of these Mcs at a later date, for example...
for (i=0;i<=5;i++){
_root[mov"+i].n = 10;
}
...with AS3 this sort of thing seems incredibly difficult. I read that you can attach a name variable to each MovieClip that you add to the stage but I dont know whether that is the right way to do it, or how to then send values to a particular MovieClip.
I understand why AS3 can be seen as much easier and better to use, but some things just seem so much more complicated in AS3 than AS2. For example the project I am working on at the moment would take 45 minutes to make in AS2. So far it has taken me 5 days in AS3.
Any help really appreciated.