开发者

In Flash, is it a better practice to have multiple frames, or to alter symbol properties using AS

开发者 https://www.devze.com 2023-03-25 02:03 出处:网络
For example, if you have an active state and a passive state for something, you can jump between the two with gotoAndStop(2), gotoAndStop(1); or you can manipulate whatever property is changing direct

For example, if you have an active state and a passive state for something, you can jump between the two with gotoAndStop(2), gotoAndStop(1); or you can manipulate whatever property is changing directly (e.g. if it's alpha, then symb.alpha=0.5, symb.alpha = 1.0).

I've found myself 开发者_如何转开发jumping between the two, and I don't like it (I like to have a standard, or at least a usual). What's considered a good practice, and why?


If you're using AS2 using frames and gotoandstop is fine, in AS3 you really need to assess whether that will work for you. For me, most often the cons outweigh the pros, and so I use frames sparingly.

The big difference between as2 and as3 is that in as2 the resources are accessible right away. In AS3 the resources cannot be accessed right after.

for example if you have a movieclip named _mc1 on frame 3, in as2 you could do

mymc.gotoandstop(3);
mymc._mc1.visible = false;

in AS3 that would not work, you would get errors, and would need to add an onrender listener and add the code there. Doing this is a nightmare.

That's not to say I don't use frames, for example, when I'm using movieclips as buttons, I don't have any resources that I need to access and so I'm not worried about using frames.

The other thing you should keep in mind is the memory that is being used. If you have objects that have listeners or have expensive creation and removal, having these objects on a timeline that you go back and forward on will use more memory and processing than if you did it using pure code.


I prefer to always do this stuff in code except when I can't. Any animations or other changes made in code are almost always easier to adjust later than doing those same animations on the timeline (especially when you use something like TweenLite). And of course this way the UI can be driven by dynamic data (eg. the rollover effect is unique to each user in the database).

The "can't" situations are complex image changes, like a face that changes expression when the mouse is over it.

It does depend on your studio's workflow however; sometimes the designers insist on using their graphical assets, rather than treating them as mockups to recreate in code, in which case I usually don't bother arguing.


Personally I always prefer to do things purely with code because I feel it gives you more control, and because code is more self-documenting than timeline work. I also find that code is more easily portable.


I almost always use the gotoandstop way of doing things. For me I'm always trying to keep my code length down and this lets me do that.

for example if there is a lot I want to do with the animation that needs to be done on the rollover, it could take 5-10 lines of code depending on the complexity. If I can gut that in favor of doing it on the timeline I find my code stays cleaner.

I'm not sure if there is a best practice for this, it might be more of a personal preference but I would definitely stick to doing it one way throughout a whole project.

0

精彩评论

暂无评论...
验证码 换一张
取 消