View Full Version : What are good design reasons for having different levels in Flash's ActionScript?
echezona
04-30-2002, 07:23 PM
I have been using Flash for a little while now and I still can't figure out any good design reasons for loading SWF's or MovieClips to different levels in a Flash movie.
The only reason why I think one may want to load a movie to a different level is just because they want to design it that way.
For example, in OO design, one can say you put objects in objects for (encapsulation), security reasons etc. When objects in OO design are encapsulated in a certain way, certain objects can't get to other objects. That is, say you have Object Animal which contains Object Cat and Object Dog; you can't stay inside Object Dog and access the properties of Object Cat. In this arrangement, only Object Cat and Object Animal (if the permissions are set right) can access the properties of Object Cat.
But in ActionScript, any object in any level can access any object in another level (PLEASE correct me if I am wrong).
Again, my question in other words is: What are good design reasons for having different levels in Flash's ActionScript?
Thank you much.
jimburton
04-30-2002, 08:19 PM
The main usefulness i've come across is for separating things out in the clipstack - say you have a tank game and you're attaching many instances of bullet, bullet explosions and mine explosions, craters in the ground or whatever, if all these attachMovie or duplicatMovie events are happening on separate layers you can attach thousands and still know that a mine explosion will be behind a bullet, all without doing any fancy swapDepths().
You can achieve the same thing within one level by having a variety of attachLevels variables but that gets complicated: eg
cratersLevel = 50;
minesLevel = 500;
bulletsLevel = 10000;
bulletExplosionsLevel = 50000;
then every time you attach an instance increment the appropriate variable. This is less neat than loading the parent mine, parent crater, etc etc each into it's separate layer and incrementing a topLevel variable in each separate layer as instances are attached. That way you never run out of levels.
I wouldn't bother with levels other than for that sort of thing myself....??
pixelwit
05-01-2002, 08:32 AM
Okay, lets say you made a movie called First.SWF. Inside First.SWF you store a variable on the main timeline called myVar. Somewhere else deep inside First.SWF you reference _root.myVar. Everything is fine. Then one day you decide you need to load First.SWF into another file called Second.SWF. Inside Second.SWF there is a clip called myClip. If you use myClip as a "target clip" and load First.SWF into myClip, the reference to _root.myVar inside First.SWF willl fail because Flash will look for a variable on the main timeline of Second.SWF called myVar which probably won't exist.
On the other hand, if you load First.SWF into a "level" in Second.SWF the reference to _root.myVar inside First.SWF will still work.
Hope it helps,
-PiXELWiT
http://www.pixelwit.com
echezona
05-01-2002, 07:48 PM
>On the other hand, if you load First.SWF into a "level" in >Second.SWF the reference to _root.myVar inside First.SWF will >still work.
Continuing on the idea of loading First.SWF in a level in Second.SWF; are you saying that "_root" isn't still a reference to the main timeline of Second.SWF?
If "_root" isn't a reference to the main timeline of Second.SWF, how would you refer to a var called "Car" in the "_root" of Second.SWF if you are in First.SWF which is located in level1 of Second.SWF?
Thanx
pixelwit
05-01-2002, 07:55 PM
_level0.Car
-PiXELWiT
http://www.pixelwit.com
echezona
05-01-2002, 08:18 PM
If it is level0.Car, isn't level0.Car same as _root.Car? And if it is, then this:
>On the other hand, if you load First.SWF into a "level" in >Second.SWF the reference to _root.myVar inside First.SWF will >still work.
would not work as intended. What do you think?
pixelwit
05-01-2002, 08:29 PM
"_level0" and "_root" are not the same. That is why what I said before is true and does work. Why don't you just try it for yourself and find out?
-PiXELWiT
http://www.pixelwit.com
echezona
05-01-2002, 08:38 PM
Well, I am defintly going to try it -- maybe not soon-soon. Here's the thing: In Tutorial 03 Paths to Objects and Variables by Jesse Stratford, she said level0 is same as _root.
So :confused:
pixelwit
05-01-2002, 08:44 PM
They're only the same if you are addressing a variable from within _level0. "_root" refers to the parent level.
-PiXELWiT
http://www.pixelwit.com
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.