PDA

View Full Version : Stage placement vs dynamic creation


notsofast
04-25-2002, 06:03 PM
I had a (stupid user) bug recently that got me to wondering how or if objects can be created by placing them on the Stage then moved dynamically with ActionScript. What happens when a keyframe is hit where the objects disagree?

It would be nice to use Stage placement to get the original layout, then have the Actionscript "take over" the objects. To get things to work now, however, I have to dynamically create the objects with attachMovie() or I end up with duplicate objects.

Would it work to just never hit another keyframe for that object? How do the experts do it? (...something I wonder a lot when I see stuff you people have done.)

Jesse
04-26-2002, 02:16 AM
Sorry I'm afraid you've confused me. What is it exactly you wish to do?

notsofast
04-26-2002, 03:19 PM
I want WYSIWYG while I'm constructing in Flash, but I want to be able to move MCs around with code.

Say I'm making a block puzzle where the blocks start out in one arrangement and the user must move them into another arrangement by repeatedly clicking on a block and then clicking on its destination. ActionScript will animate the block to its new location. When done, the puzzle loops back in the timeline and starts over.

So I lay out the initial block arrangement in some starting keyframe on the Stage. They move fine, the motion code is in the block's MC. The problem is when the timeline loops back to start over.

I get duplicated blocks! The timeline puts them back in their starting positions, but the destination blocks moved by ActionScript remain.

As a workaround, I lay out the blocks on the Stage, get their XY locations, then delete them from the Stage and create them in code using attachMovie() and set their _x and _y accordingly. I don't like this solution because I can't edit their locations conveniently.

It also bothers me a little that I have to delete a layer permanently to keep it from showing up in the movie. Layers made invisible should not be exported to the .swf file but should remain in the .fla file, or there should be an additional flag to prevent them from being exported. Sorry, that's off the main topic.

Jesse
04-27-2002, 11:43 AM
I don't quite understand why you're using attachMovie. When you attach the blocks manualy in Flahs, give them instance names, then you can manipulate them using actionscript and record their original positions to set the back in place later.

notsofast
04-29-2002, 04:48 PM
I've traced the behavior to my use of swapDepths(). In this small example (attached) I have one MC, I call swapDepths() to make sure it stays on top of other stuff, and move it. A duplicate of the MC is created.

I can work around it, but I'd like to understand why this happens.

Jesse
05-01-2002, 09:12 AM
That is odd. In my cyclic swap depths script i think I used numbers and it never created duplicates... Hmmm strange indeed.

Jesse
05-01-2002, 09:14 AM
Indeed I did. If you go to the movies section and search for my cyclcic swapdepths you'll find that I used numbers and it works fine in MX and Flash 5... So I honestly cannot think (for the moment) why that's not working.

notsofast
05-01-2002, 03:30 PM
I looked at your cycle_swap2.fla, and yes it works. However, I was able to break it simply by adding a second frame to the main timeline! See the attached cycle_swap2_modified.

Jesse
05-02-2002, 06:35 AM
I think that's a different issue. The way you remade mine it loops back to the beginning and the instances are reinstantiated. On yours they should exist already... Hmm hang on.

Jesse
05-02-2002, 06:43 AM
OK I got it. What you did made me think about it a bit harder. When you swap the MC it's becomming a different clip in Flash's mind so when you loop back to that frame Flash reckons the clip myMC doesn't exist and creates it. It's probably to do with the depths within levels. You know the way each level has X depths? That sort of thing. I fixed it by removing the original MC from the frame you loop back to (and in this case, moving the code to frame 1 b/c it's only a 3 frame movie). See attached.

notsofast
05-02-2002, 04:39 PM
What you are saying is along the lines of how I suspect the underlying Flash state is managed, and it gets back closer to my original question, which was: How do I place things on the Stage manually, then move them dynamically (which includes changing levels)?

I've done some additional experiments to see if just Frame 1 had the peculiar behavior, because I know it has some different object loading behavior. Doesn't appear to be just Frame 1. So it must be what you said, that when you hit the keyframe the second time, and the object has been moved to a new depth, the keyframe creates a new object.

Does this mean that all objects must be returned to their original depths before hitting a keyframe? So, what if two objects have swapped depths? Does the keyframe care if it's the same object, or will just any object at that depth keep it from creating a new one? I don't know of any way to control the initial depth of objects placed on the Stage manually...

This aspect of the keyframe semantics, and the behavior of goto's are my two current challenges to understanding how Flash runs the Timeline. Has anyone written a good description of how the runtime state is updated when the Timeline executes?

Jesse
05-03-2002, 11:41 AM
I think if you returned a clip to its original depth with the same instance name it might not be duplicated when you hit a keyframe with the clip hard coded into the Fla but I can't be sure. I imagine if you swapped two clips around and then hit a keyframe with them on opposite levels it would result in duplicates as this example has. Flash doesn't really care whether there is content on the level/depth combo, it cares if there is an MC with that instance name on that level/depth combo. I've never seen a really wholesome article on depths and levels but this sort of thing is generally good to throw into the arena of the Macromedia Techs as they can provide definite answers... I can only speculate.